The particle photon is an inexpensive wifi-enabled micro-controller that comes with a well-developed & secure cloud service for remote programming, device control and data collection. The names are a bit silly but these little micro-controller pack a lot of punch and program just like an Arduino. The newest versions of the photon (particle electron, particle boron, particle xenon) make it super easy to move everything to a cellular network for field deployment (within 2G, 3G or LTE range) or implement a mesh network of microcontrollers.
UART
= universal asynchronous receiver/transmitterI2C
= inter integrated circuitSPI
= serial peripheral interfacePMW
= pulse width modulationNote: technically you only need the CLI and can do everything from command line with a regular text editor but the IDE has some very useful features that makes your life easier.
Connect to your photon and set up the wireless. Note that all course photons have been white-listed with OIT in advance so you can use them on the regular UCB Wirless
network without a network password. Also note that you can only claim/setup a photon if it is not already claimed (i.e. associated with another account) for security reasons, and if it is in listening mode (blinking dark blue).
particle login
particle
executable is not available in your terminal, it may not be in your path - you can either call it directly from its location (on MacOS e.g. /usr/local/bin/particle
) or follow the advanced installation instructionsparticle setup
(follow steps, if there are problems connecting to photon by wireless, try again)particle list
in your terminal with function names digitalread
, digitalwrite
, analogread
, analogwrite
(these are installed from the default program running on the particle photon called tinker)particle call NAME digitalwrite D7,HIGH
replacing NAME
with the name you gave your deviceparticle call NAME digitalwrite D7,LOW
particle project create .. --name REPO
from the command line, where REPO is the name of your repo foldersrc/???.ino
file, add the following code:in the setup function:
pinMode(D7, OUTPUT);
in the loop function:
digitalWrite(D7, HIGH);
delay(1000);
digitalWrite(D7, LOW);
delay(1000);
particle compile photon
from the terminalphoton_xxxxx.bin
file that is represent your program, otherwise you’ll get a list of errors that should help trouble-shoot your codeparticle flash NAME photon_xxxxx.bin
from the terminal with the NAME of your device and the name of the .bin
file.bin
fileparticle flash NAME
, i.e. flash without specifying a .bin
file.bin
files floating around because the wrong ones may get flashed unintentionallyWhile your photon can run on its own away from your computer and you can flash code via the internet, it can be extremely helpful to have it also send some regular debugging information via the USB cable to your computer during program development. This of course only works if it is actually connected to your computer via USB.
in the setup function:
Serial.begin(9600);
pinMode(D7, OUTPUT);
Serial.println("INFO: setup complete");
in the loop function:
Serial.println("ON at " + Time.timeStr());
digitalWrite(D7, HIGH);
delay(1000);
Serial.println("OFF at " + Time.timeStr());
digitalWrite(D7, LOW);
delay(1000);
particle serial monitor
from the terminalNote: you will notice that the serial monitor gets disconnected whenever you flash new code to your device, if you find it annoying to reconnect manually, you can run the following from the terminal: while true; do particle serial monitor; done
(hit ctrl+C twice quickly to exit, this may not work on Windows)
outside functions, add:
const int cds_pin = A0;
int cds_reading;
in the setup function, add:
pinMode(cds_pin, INPUT);
in the loop function, add:
cds_reading = analogRead(cds_pin);
Serial.print("Analog reading = ");
Serial.println(cds_reading);
outside functions, add:
const int led_pin = D0;
in the setup function, add:
pinMode(led_pin, OUTPUT);
digitalWrite(led_pin, HIGH);
in the loop function, add:
int led_brightness = map(cds_reading, 0, 4095, 0, 255);
analogWrite(led_pin, led_brightness);
delay
outside functions, add:
const uint interval = 1000;
unsigned long last_time;
in the setup function, add:
last_time = millis();
replace the loop function:
if ( millis() - last_time > interval) {
Serial.print(Time.timeStr() + ": Analog reading = ");
Serial.println(cds_reading);
last_time = millis();
}
cds_reading = analogRead(cds_pin);
int led_brightness = map(cds_reading, 0, 4095, 0, 255);
analogWrite(led_pin, led_brightness);
in the setup function, add:
Particle.variable("cds", cds_reading);
once flashed, use the Particle
–> Show cloud variables
in the cloud IDE (may take a minute to update) OR call particle list
to see your device variables in the terminal, and then particle variable get NAME cds
to retrieve the latest value (with NAME your device name)
1a:2b:34:5c:6d:78
Dear OIT, I am working with wireless micro-controllers for my project on XXXXX and would like to add a new device. Could you add the following MAC address for the new wifi-enabled micro controller (a particle photon with ARM Cortex M3 micro-controller and a Broadcom Wi-Fi chip) to the UCB Wireless network? My CU Boulder identikey is xxxxxxx.
1a:2b:34:5c:6d:78
Error codes: the devices modes page has an extremely useful list of color error codes: https://docs.particle.io/guide/getting-started/modes/photon/
Flashed code that causes trouble: put photon into safe mode (i.e. connected to particle cloud but not running program) so you can flash it again. To get into safe mode: Hold down BOTH buttons, release only the RESET button, while holding down the SETUP button, wait for the LED to start blinking magenta, release the SETUP button.
Doesn’t take any commands / trouble claiming the photon: make sure to start from scratch, photon might have gotten corrupted and need to be factory reset, just hold both the setup and reset button pressed until it starts going through series of LED colors and ends on white, then let go. Reinstall vis USB or phone Partcle app.
Wrong server keys: sometimes internet connectivity issues are because of wrong server keys, to update get into DFU mode (see below) and then run particle keys server
on the command line
dfu-util
via mac ports or homebrew by running sudo port install dfu-util
or sudo brew install dfu-util
run particle update
from command line