SlideShare a Scribd company logo
Particle Photon
Command Line
Interface
COEN 296 Internet of Things
Winter 2016
Lalu Paul, W1087391
Abhra Koley, W1106352
Contents
1. Photon Command Line Interface
2. Blink an LED in Photon chip
3. Read a light sensor through CLI
4. Export the results using IFTTT
5. Photon interfacing Blynk App
6. Photon interfacing Arduino
1. Photon Command Line Interface
Particle Photon can be programmed from the web IDE at
https://build.particle.io/signup by entering the login credentials. There is
also an offline IDE that can perform similar functions. But a greater
control over the Photon wifi module is achieved through the Command
Line Interface or CLI. The chip can be setup in to a new wifi, flashed and
can be monitored realtime through CLI. Particle CLI is a powerful tool
for interacting with your devices and the Particle Cloud. The CLI uses
node.js and can easily run on Windows, Mac OS X, and Linux. It's also
open source so you can edit and change it, and even send in your changes
as pull requests if you want to share.
a) Prerequisites
i) Node.js is needed to be installed.
ii) Next, install particle-cli from commandline using the
command npm install -g particle-cli.
iii) Install photon drivers to get the chip detected in the
computer system. https://community.particle.io/t/updated-
windows-driver-for-core-and-photon/12249)
b) CLI Commands
i) particle setup wifi- Helpful shortcut for adding another
wifi network to a device connected over USB. Make sure
your device is connected via a USB cable, and is slow
blinking blue listening mode.
ii) particle login- Login and save an access token for
interacting with your account on the Particle Cloud.
iii) particle logout- Logout and optionally revoke the access
token for your CLI session.
iv) particle list- Generates a list of what devices you own,
and displays information about their status, including
what variables and functions are available.
v) particle device add- Adds a new device to your account.
vi) particle device rename- Assigns a new name to a device
you've claimed.
vii) particle device remove- Removes a device from your
account so someone else can claim it.
viii) particle compile- Compiles one or more source file, or
a directory of source files, and downloads a firmware
binary.
ix) particle flash- Sends a firmware binary, a source file, or
a directory of source files, or a known app to your device.
x) particle call- Calls a function on one of your devices,
use particle list to see which devices are online, and what
functions are available.
xi) particle get- Retrieves a variable value from one of your
devices, use particle list to see which devices are online,
and what variables are available.
xii) particle monitor- Pulls the value of a variable at a set
interval, and optionally display a timestamp.
2. Blink an LED in Photon chip
Following code was compiled and flashed in to the photon chip
from CLI.
int led1 = D7;
void setup() {
pinMode(led1, OUTPUT);
}
void loop() {
// To blink the LED, first we'll turn it on...
digitalWrite(led1, HIGH);
// We'll leave it on for 1 second...
delay(1000);
// Then we'll turn it off...
digitalWrite(led1, LOW);
// Wait 1 second...
delay(1000);
// And repeat!
}
3. Read a light sensor through CLI
Following code was compiled and flashed in to the photon chip
from CLI.
int light = 0;
void setup()
{
// variable name max length is 12 characters long
Particle.variable("light", light);
pinMode(A0, INPUT);
}
void loop()
{
// Read the analog value of the sensor (TMP36)
light = analogRead(A0);
//Convert the reading into degree celcius
}
Now in the CLI, use particle monitor
particle monitor- Pulls the value of a variable at a set interval,
and optionally display a timestamp.
4. Export the results using IFTTT
a) First, create a recipe
b) Click ‘this’
c)
d)
e)
f)
g)
h)
i)
j)
k)
l)
m)
n)
o)
p)
q)
5. Photon Interfacing Blynk App
Blynk is a Platform with iOS and Android apps to control Arduino,
Raspberry Pi and the likes over the Internet. It's a digital dashboard
where you can build a graphic interface for your project by simply
dragging and dropping widgets.It's really simple to set everything up and
you'll start tinkering in less than 5 mins.
Blynk library for photon is available in github and all the header
files in the blynk library needs to be sourced while flashing the
following source code in to the photon chip from CLI.
//#define BLYNK_DEBUG // Uncomment this to see debug prints
#define BLYNK_PRINT Serial
#include "blynk/blynk.h"
Used in the code below
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "e19a5229861e48ef8ae12cafc184e5ac";
// Attach a Button widget (mode: Switch) to the Digital pin 7 - and
control the built-in blue led.
// Attach a Graph widget to Analog pin 1
// Attach a Gauge widget to Analog pin 2
// No coding is required for direct pin operations!
void setup()
{
Serial.begin(9600);
delay(5000); // Allow board to settle
Blynk.begin(auth);
}
// Attach a Button widget (mode: Push) to the Virtual pin 1 - and
send sweet tweets!
BLYNK_WRITE(V1) {
if (param.asInt() == 1) { // On button down...
// Tweeting!
// Note:
// We allow 1 tweet per minute for now.
// Twitter doesn't allow identical subsequent messages.
Blynk.tweet("My Particle project is tweeting using
@blynk_app and it’s awesome!n @Particle #IoT #blynk");
// Pushing notification to the app!
// Note:
// We allow 1 notification per minute for now.
Blynk.notify("You pressed the button and I know it ;)");
}
}
// Attach a Slider widget to the Virtual pin 2 - and control the built-
in RGB led!
BLYNK_WRITE(V2) {
if (param.asInt() > 0) {
RGB.control(true);
byte rgb[3];
HsvToRgb(param.asDouble()/255, 1, 1, rgb);
RGB.color(rgb[0], rgb[1], rgb[2]);
} else {
RGB.control(false);
}
}
void loop()
{
Blynk.run();
if (ModeBtnPressed()) {
Blynk.notify("Mode button was pressed");
}
}
// *** Utility functions
bool ModeBtnPressed() {
if(millis() > 5000) {
if(BUTTON_GetDebouncedTime(BUTTON1) >= 50) {
BUTTON_ResetDebouncedState(BUTTON1);
return 1;
}
}
return 0;
}
void HsvToRgb(double h, double s, double v, byte rgb[]) {
double r, g, b;
int i = int(h * 6);
double f = h * 6 - i;
double p = v * (1 - s);
double q = v * (1 - f * s);
double t = v * (1 - (1 - f) * s);
switch(i % 6){
case 0: r = v, g = t, b = p; break;
case 1: r = q, g = v, b = p; break;
case 2: r = p, g = v, b = t; break;
case 3: r = p, g = q, b = v; break;
case 4: r = t, g = p, b = v; break;
case 5: r = v, g = p, b = q; break;
}
rgb[0] = r * 255;
rgb[1] = g * 255;
rgb[2] = b * 255;
}
Graph from light sensor
7. Photon interfacing Arduino
Connection was made as follows and I2C protocol was used to
communicate between Photon and Arduino
Blynk library for photon is available in github and all the header
files in the blynk library needs to be sourced while flashing the
following source code in to the photon chip from CLI.
// This #include statement was automatically added by the Particle
IDE.
#include "blynk/blynk.h"
#define BLYNK_PRINT Serial
#include "blynk/blynk.h"
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
Arduino Pin A5 – Photon Pin D0
Arduino Pin A4 – Photon Pin D1
char auth[] = "e19a5229861e48ef8ae12cafc184e5ac";
// Attach a Button widget (mode: Switch) to the Digital pin 7 - and
control the built-in blue led.
// Attach a Graph widget to Analog pin 1
// Attach a Gauge widget to Analog pin 2
// No coding is required for direct pin operations!
bool x = 0;
bool prev_state=HIGH;
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600);
delay(5000); // Allow board to settle
Blynk.begin(auth);
}
// Attach a Button widget (mode: Push) to the Virtual pin 1 - and
send sweet tweets!
BLYNK_WRITE(V1) {
if (param.asInt() == 1) { // On button down...
// Tweeting!
// Note:
// We allow 1 tweet per minute for now.
// Twitter doesn't allow identical subsequent messages.
Blynk.tweet("My Particle project is tweeting using
@blynk_app and it’s awesome!n @Particle #IoT #blynk");
// Pushing notification to the app!
// Note:
// We allow 1 notification per minute for now.
Blynk.notify("You pressed the button and I know it ;)");
}
}
// Attach a Slider widget to the Virtual pin 2 - and control the built-in
RGB led!
BLYNK_WRITE(V2) {
if (param.asInt() > 0) {
RGB.control(true);
byte rgb[3];
HsvToRgb(param.asDouble()/255, 1, 1, rgb);
RGB.color(rgb[0], rgb[1], rgb[2]);
} else {
RGB.control(false);
}
}
void loop()
{
Blynk.run();
if (ModeBtnPressed()) {
Blynk.notify("Mode button was pressed");
}
bool state = digitalRead(D7);
if (state != prev_state) {
action(state);
prev_state = state;
}
}
// *** Utility functions
bool ModeBtnPressed() {
if(millis() > 5000) {
if(BUTTON_GetDebouncedTime(BUTTON1) >= 50) {
BUTTON_ResetDebouncedState(BUTTON1);
return 1;
}
}
return 0;
}
void HsvToRgb(double h, double s, double v, byte rgb[]) {
double r, g, b;
int i = int(h * 6);
double f = h * 6 - i;
double p = v * (1 - s);
double q = v * (1 - f * s);
double t = v * (1 - (1 - f) * s);
switch(i % 6){
case 0: r = v, g = t, b = p; break;
case 1: r = q, g = v, b = p; break;
case 2: r = p, g = v, b = t; break;
case 3: r = p, g = q, b = v; break;
case 4: r = t, g = p, b = v; break;
case 5: r = v, g = p, b = q; break;
}
rgb[0] = r * 255;
rgb[1] = g * 255;
rgb[2] = b * 255;
}
void action(bool a) {
Wire.beginTransmission(8); // transmit to device #8
Wire.write(a); // sends one byte
Wire.endTransmission(); // stop transmitting
}
The following code was flashed into the Arduino Uno from the
Arduino IDE.
#include <Wire.h>
void setup() {
pinMode(13, OUTPUT);
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop() {
// there are no statements in this block
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
if (Wire.available()) { // loop through all but the last
bool c = Wire.read(); // receive byte as a character
digitalWrite(13, c);
}
}
Led on Arduino was turned on from the blynk app through photon-
arduino communication in I2C protocol.
Conclusion
Explored the command line interface programming of Particle Photon
Wifi Chip. Read a light sensor and obtained a graphical representation in
Blynk app. Exported the sensor data to google drive using IFTTT and
obtained a graphical representation. Communicated with an Arduino
Uno board from Blynk app through photon Chip.

More Related Content

Similar to Survey_Paper

PyQt.pptx
PyQt.pptxPyQt.pptx
Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1
benDesigning
 
Road to RIoT 2017 Medan
Road to RIoT 2017 MedanRoad to RIoT 2017 Medan
Road to RIoT 2017 Medan
Albert Suwandhi
 
pcDuino Presentation at SparkFun
pcDuino Presentation at SparkFunpcDuino Presentation at SparkFun
pcDuino Presentation at SparkFun
Jingfeng Liu
 
REP.01 PROJ-FX01 Smart Home RP-v2
REP.01 PROJ-FX01 Smart Home RP-v2REP.01 PROJ-FX01 Smart Home RP-v2
REP.01 PROJ-FX01 Smart Home RP-v2
Ricardo Pereira
 
15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx
15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx
15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx
felicidaddinwoodie
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter Notebooks
Eueung Mulyana
 
TP_Webots_7mai2021.pdf
TP_Webots_7mai2021.pdfTP_Webots_7mai2021.pdf
TP_Webots_7mai2021.pdf
kiiway01
 
generate IP CORES
generate IP CORESgenerate IP CORES
generate IP CORES
guest296013
 
222066369 clad-study-guide
222066369 clad-study-guide222066369 clad-study-guide
222066369 clad-study-guide
homeworkping9
 
Io t basic-exercises
Io t basic-exercisesIo t basic-exercises
Io t basic-exercises
Fermin Galan
 
Creating a Smart Alarm System with Raspberry Pi and Google Cloud Pub/Sub
Creating a Smart Alarm System with Raspberry Pi and Google Cloud Pub/SubCreating a Smart Alarm System with Raspberry Pi and Google Cloud Pub/Sub
Creating a Smart Alarm System with Raspberry Pi and Google Cloud Pub/Sub
XinYingLim12
 
Micro c lab2(led patterns)
Micro c lab2(led patterns)Micro c lab2(led patterns)
Micro c lab2(led patterns)
Mashood
 
Artificial Neural Networks on a Tic Tac Toe console application
Artificial Neural Networks on a Tic Tac Toe console applicationArtificial Neural Networks on a Tic Tac Toe console application
Artificial Neural Networks on a Tic Tac Toe console application
Eduardo Gulias Davis
 
Tutorial_Python1.pdf
Tutorial_Python1.pdfTutorial_Python1.pdf
Tutorial_Python1.pdf
MuzamilFaiz
 
Node red for Raspberry Pi
Node red for Raspberry PiNode red for Raspberry Pi
Node red for Raspberry Pi
Anshu Pandey
 
掀起 Swift 的面紗
掀起 Swift 的面紗掀起 Swift 的面紗
掀起 Swift 的面紗
Pofat Tseng
 
Robotics.DS_Store__MACOSXRobotics._.DS_StoreRobotics.docx
Robotics.DS_Store__MACOSXRobotics._.DS_StoreRobotics.docxRobotics.DS_Store__MACOSXRobotics._.DS_StoreRobotics.docx
Robotics.DS_Store__MACOSXRobotics._.DS_StoreRobotics.docx
SUBHI7
 
Esp32 bluetooth networking_user_guide_en
Esp32 bluetooth networking_user_guide_enEsp32 bluetooth networking_user_guide_en
Esp32 bluetooth networking_user_guide_en
Shubham Jaiswal
 
超級全能危樓改造王 - 增建、改建、打掉重建你的軟體架構?
超級全能危樓改造王 - 增建、改建、打掉重建你的軟體架構?超級全能危樓改造王 - 增建、改建、打掉重建你的軟體架構?
超級全能危樓改造王 - 增建、改建、打掉重建你的軟體架構?
Pin-Ying Tu
 

Similar to Survey_Paper (20)

PyQt.pptx
PyQt.pptxPyQt.pptx
PyQt.pptx
 
Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1
 
Road to RIoT 2017 Medan
Road to RIoT 2017 MedanRoad to RIoT 2017 Medan
Road to RIoT 2017 Medan
 
pcDuino Presentation at SparkFun
pcDuino Presentation at SparkFunpcDuino Presentation at SparkFun
pcDuino Presentation at SparkFun
 
REP.01 PROJ-FX01 Smart Home RP-v2
REP.01 PROJ-FX01 Smart Home RP-v2REP.01 PROJ-FX01 Smart Home RP-v2
REP.01 PROJ-FX01 Smart Home RP-v2
 
15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx
15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx
15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter Notebooks
 
TP_Webots_7mai2021.pdf
TP_Webots_7mai2021.pdfTP_Webots_7mai2021.pdf
TP_Webots_7mai2021.pdf
 
generate IP CORES
generate IP CORESgenerate IP CORES
generate IP CORES
 
222066369 clad-study-guide
222066369 clad-study-guide222066369 clad-study-guide
222066369 clad-study-guide
 
Io t basic-exercises
Io t basic-exercisesIo t basic-exercises
Io t basic-exercises
 
Creating a Smart Alarm System with Raspberry Pi and Google Cloud Pub/Sub
Creating a Smart Alarm System with Raspberry Pi and Google Cloud Pub/SubCreating a Smart Alarm System with Raspberry Pi and Google Cloud Pub/Sub
Creating a Smart Alarm System with Raspberry Pi and Google Cloud Pub/Sub
 
Micro c lab2(led patterns)
Micro c lab2(led patterns)Micro c lab2(led patterns)
Micro c lab2(led patterns)
 
Artificial Neural Networks on a Tic Tac Toe console application
Artificial Neural Networks on a Tic Tac Toe console applicationArtificial Neural Networks on a Tic Tac Toe console application
Artificial Neural Networks on a Tic Tac Toe console application
 
Tutorial_Python1.pdf
Tutorial_Python1.pdfTutorial_Python1.pdf
Tutorial_Python1.pdf
 
Node red for Raspberry Pi
Node red for Raspberry PiNode red for Raspberry Pi
Node red for Raspberry Pi
 
掀起 Swift 的面紗
掀起 Swift 的面紗掀起 Swift 的面紗
掀起 Swift 的面紗
 
Robotics.DS_Store__MACOSXRobotics._.DS_StoreRobotics.docx
Robotics.DS_Store__MACOSXRobotics._.DS_StoreRobotics.docxRobotics.DS_Store__MACOSXRobotics._.DS_StoreRobotics.docx
Robotics.DS_Store__MACOSXRobotics._.DS_StoreRobotics.docx
 
Esp32 bluetooth networking_user_guide_en
Esp32 bluetooth networking_user_guide_enEsp32 bluetooth networking_user_guide_en
Esp32 bluetooth networking_user_guide_en
 
超級全能危樓改造王 - 增建、改建、打掉重建你的軟體架構?
超級全能危樓改造王 - 增建、改建、打掉重建你的軟體架構?超級全能危樓改造王 - 增建、改建、打掉重建你的軟體架構?
超級全能危樓改造王 - 增建、改建、打掉重建你的軟體架構?
 

Survey_Paper

  • 1. Particle Photon Command Line Interface COEN 296 Internet of Things Winter 2016 Lalu Paul, W1087391 Abhra Koley, W1106352
  • 2. Contents 1. Photon Command Line Interface 2. Blink an LED in Photon chip 3. Read a light sensor through CLI 4. Export the results using IFTTT 5. Photon interfacing Blynk App 6. Photon interfacing Arduino
  • 3. 1. Photon Command Line Interface Particle Photon can be programmed from the web IDE at https://build.particle.io/signup by entering the login credentials. There is also an offline IDE that can perform similar functions. But a greater control over the Photon wifi module is achieved through the Command Line Interface or CLI. The chip can be setup in to a new wifi, flashed and can be monitored realtime through CLI. Particle CLI is a powerful tool for interacting with your devices and the Particle Cloud. The CLI uses node.js and can easily run on Windows, Mac OS X, and Linux. It's also open source so you can edit and change it, and even send in your changes as pull requests if you want to share. a) Prerequisites i) Node.js is needed to be installed. ii) Next, install particle-cli from commandline using the command npm install -g particle-cli. iii) Install photon drivers to get the chip detected in the computer system. https://community.particle.io/t/updated- windows-driver-for-core-and-photon/12249) b) CLI Commands i) particle setup wifi- Helpful shortcut for adding another wifi network to a device connected over USB. Make sure your device is connected via a USB cable, and is slow blinking blue listening mode.
  • 4. ii) particle login- Login and save an access token for interacting with your account on the Particle Cloud. iii) particle logout- Logout and optionally revoke the access token for your CLI session. iv) particle list- Generates a list of what devices you own, and displays information about their status, including what variables and functions are available. v) particle device add- Adds a new device to your account. vi) particle device rename- Assigns a new name to a device you've claimed. vii) particle device remove- Removes a device from your account so someone else can claim it.
  • 5. viii) particle compile- Compiles one or more source file, or a directory of source files, and downloads a firmware binary. ix) particle flash- Sends a firmware binary, a source file, or a directory of source files, or a known app to your device. x) particle call- Calls a function on one of your devices, use particle list to see which devices are online, and what functions are available. xi) particle get- Retrieves a variable value from one of your devices, use particle list to see which devices are online, and what variables are available. xii) particle monitor- Pulls the value of a variable at a set interval, and optionally display a timestamp.
  • 6. 2. Blink an LED in Photon chip Following code was compiled and flashed in to the photon chip from CLI. int led1 = D7; void setup() { pinMode(led1, OUTPUT); } void loop() { // To blink the LED, first we'll turn it on... digitalWrite(led1, HIGH); // We'll leave it on for 1 second... delay(1000);
  • 7. // Then we'll turn it off... digitalWrite(led1, LOW); // Wait 1 second... delay(1000); // And repeat! } 3. Read a light sensor through CLI Following code was compiled and flashed in to the photon chip from CLI. int light = 0;
  • 8. void setup() { // variable name max length is 12 characters long Particle.variable("light", light); pinMode(A0, INPUT); } void loop() { // Read the analog value of the sensor (TMP36) light = analogRead(A0); //Convert the reading into degree celcius } Now in the CLI, use particle monitor particle monitor- Pulls the value of a variable at a set interval, and optionally display a timestamp.
  • 9. 4. Export the results using IFTTT a) First, create a recipe b) Click ‘this’ c)
  • 11. g) h)
  • 13. l) m)
  • 14. n) o)
  • 15. p) q)
  • 16. 5. Photon Interfacing Blynk App Blynk is a Platform with iOS and Android apps to control Arduino, Raspberry Pi and the likes over the Internet. It's a digital dashboard where you can build a graphic interface for your project by simply dragging and dropping widgets.It's really simple to set everything up and you'll start tinkering in less than 5 mins. Blynk library for photon is available in github and all the header files in the blynk library needs to be sourced while flashing the following source code in to the photon chip from CLI. //#define BLYNK_DEBUG // Uncomment this to see debug prints #define BLYNK_PRINT Serial #include "blynk/blynk.h" Used in the code below
  • 17. // You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon). char auth[] = "e19a5229861e48ef8ae12cafc184e5ac"; // Attach a Button widget (mode: Switch) to the Digital pin 7 - and control the built-in blue led. // Attach a Graph widget to Analog pin 1 // Attach a Gauge widget to Analog pin 2 // No coding is required for direct pin operations! void setup() { Serial.begin(9600); delay(5000); // Allow board to settle Blynk.begin(auth); } // Attach a Button widget (mode: Push) to the Virtual pin 1 - and send sweet tweets! BLYNK_WRITE(V1) { if (param.asInt() == 1) { // On button down... // Tweeting! // Note:
  • 18. // We allow 1 tweet per minute for now. // Twitter doesn't allow identical subsequent messages. Blynk.tweet("My Particle project is tweeting using @blynk_app and it’s awesome!n @Particle #IoT #blynk"); // Pushing notification to the app! // Note: // We allow 1 notification per minute for now. Blynk.notify("You pressed the button and I know it ;)"); } } // Attach a Slider widget to the Virtual pin 2 - and control the built- in RGB led! BLYNK_WRITE(V2) { if (param.asInt() > 0) { RGB.control(true); byte rgb[3]; HsvToRgb(param.asDouble()/255, 1, 1, rgb); RGB.color(rgb[0], rgb[1], rgb[2]); } else { RGB.control(false); }
  • 19. } void loop() { Blynk.run(); if (ModeBtnPressed()) { Blynk.notify("Mode button was pressed"); } } // *** Utility functions bool ModeBtnPressed() { if(millis() > 5000) { if(BUTTON_GetDebouncedTime(BUTTON1) >= 50) { BUTTON_ResetDebouncedState(BUTTON1); return 1; } } return 0; } void HsvToRgb(double h, double s, double v, byte rgb[]) {
  • 20. double r, g, b; int i = int(h * 6); double f = h * 6 - i; double p = v * (1 - s); double q = v * (1 - f * s); double t = v * (1 - (1 - f) * s); switch(i % 6){ case 0: r = v, g = t, b = p; break; case 1: r = q, g = v, b = p; break; case 2: r = p, g = v, b = t; break; case 3: r = p, g = q, b = v; break; case 4: r = t, g = p, b = v; break; case 5: r = v, g = p, b = q; break; } rgb[0] = r * 255; rgb[1] = g * 255; rgb[2] = b * 255; }
  • 22. 7. Photon interfacing Arduino Connection was made as follows and I2C protocol was used to communicate between Photon and Arduino Blynk library for photon is available in github and all the header files in the blynk library needs to be sourced while flashing the following source code in to the photon chip from CLI. // This #include statement was automatically added by the Particle IDE. #include "blynk/blynk.h" #define BLYNK_PRINT Serial #include "blynk/blynk.h" // You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon). Arduino Pin A5 – Photon Pin D0 Arduino Pin A4 – Photon Pin D1
  • 23. char auth[] = "e19a5229861e48ef8ae12cafc184e5ac"; // Attach a Button widget (mode: Switch) to the Digital pin 7 - and control the built-in blue led. // Attach a Graph widget to Analog pin 1 // Attach a Gauge widget to Analog pin 2 // No coding is required for direct pin operations! bool x = 0; bool prev_state=HIGH; void setup() { Wire.begin(); // join i2c bus (address optional for master) Serial.begin(9600); delay(5000); // Allow board to settle Blynk.begin(auth); } // Attach a Button widget (mode: Push) to the Virtual pin 1 - and send sweet tweets! BLYNK_WRITE(V1) { if (param.asInt() == 1) { // On button down... // Tweeting! // Note: // We allow 1 tweet per minute for now. // Twitter doesn't allow identical subsequent messages. Blynk.tweet("My Particle project is tweeting using @blynk_app and it’s awesome!n @Particle #IoT #blynk"); // Pushing notification to the app! // Note: // We allow 1 notification per minute for now. Blynk.notify("You pressed the button and I know it ;)"); } } // Attach a Slider widget to the Virtual pin 2 - and control the built-in RGB led! BLYNK_WRITE(V2) { if (param.asInt() > 0) {
  • 24. RGB.control(true); byte rgb[3]; HsvToRgb(param.asDouble()/255, 1, 1, rgb); RGB.color(rgb[0], rgb[1], rgb[2]); } else { RGB.control(false); } } void loop() { Blynk.run(); if (ModeBtnPressed()) { Blynk.notify("Mode button was pressed"); } bool state = digitalRead(D7); if (state != prev_state) { action(state); prev_state = state; } } // *** Utility functions bool ModeBtnPressed() { if(millis() > 5000) { if(BUTTON_GetDebouncedTime(BUTTON1) >= 50) { BUTTON_ResetDebouncedState(BUTTON1); return 1; } } return 0; } void HsvToRgb(double h, double s, double v, byte rgb[]) { double r, g, b;
  • 25. int i = int(h * 6); double f = h * 6 - i; double p = v * (1 - s); double q = v * (1 - f * s); double t = v * (1 - (1 - f) * s); switch(i % 6){ case 0: r = v, g = t, b = p; break; case 1: r = q, g = v, b = p; break; case 2: r = p, g = v, b = t; break; case 3: r = p, g = q, b = v; break; case 4: r = t, g = p, b = v; break; case 5: r = v, g = p, b = q; break; } rgb[0] = r * 255; rgb[1] = g * 255; rgb[2] = b * 255; } void action(bool a) { Wire.beginTransmission(8); // transmit to device #8 Wire.write(a); // sends one byte Wire.endTransmission(); // stop transmitting } The following code was flashed into the Arduino Uno from the Arduino IDE. #include <Wire.h> void setup() { pinMode(13, OUTPUT); Wire.begin(8); // join i2c bus with address #8 Wire.onReceive(receiveEvent); // register event Serial.begin(9600); // start serial for output } void loop() { // there are no statements in this block
  • 26. } // function that executes whenever data is received from master // this function is registered as an event, see setup() void receiveEvent(int howMany) { if (Wire.available()) { // loop through all but the last bool c = Wire.read(); // receive byte as a character digitalWrite(13, c); } } Led on Arduino was turned on from the blynk app through photon- arduino communication in I2C protocol.
  • 27. Conclusion Explored the command line interface programming of Particle Photon Wifi Chip. Read a light sensor and obtained a graphical representation in Blynk app. Exported the sensor data to google drive using IFTTT and obtained a graphical representation. Communicated with an Arduino Uno board from Blynk app through photon Chip.