I spent a bit of time playing with the cloud IDE and flashing some simple programs to the photon. I can't believe how easy it is to get up and running. The fact that you can flash your program onto the photon through the IDE without installing a million drivers and fighting with obscure errors is fantastic.
However, I'm not sure if it was my internet being lame or their servers being a bit laggy, but I sometimes found it would take over 10 seconds to compile my programs and would also time out when trying to flash my photon. I found this behaviour a little frustrating so invested a little time in getting the command line interface working so I could compile and flash programs without needing the cloud IDE. I believe the commands do connect to the particle servers so you still need internet for them to work.
So here we go:
1. Install the CLI
I followed the instructions
here but found the spark-cli was deprecated and so at the end I installed the particle-cli instead.
swap
> sudo npm -g install spark-cli
for
> sudo npm -g install particle-cli
2. Compile your program
There are several ways you can compile your program into a binary file that can be flashed onto the photon. I chose the method of putting all the required files in a directory and running the following:
> cd <dir-with-program-files>
> particle compile p .
Note: the 'p' indicates you are compiling the program to run on a photon.
As an example, this was what my folder looked like:
- photon-app/
|
- myApp.ino
- lib1.h
- lib1.cpp
If your compilation was successful then a binary file will get created inside your directory. (It is named something like 'photon_firmware_1440934375581.bin'.
3. Put the photon in DFU mode
The photon needs to be put in Device Firmware Upgrade mode in order to accept a new program.
Perform the following steps:
- Ensure the photon is powered and the LED is pulsing cyan to indicate normal operation
- Press and hold the 'setup' and 'reset' buttons simultaneously on the photon
- The LED should now be switched off
- Release just the 'reset' button and continue to hold the 'setup' button
- The LED will start flashing magenta and quickly change to yellow
- Once the LED is flashing yellow, release the 'setup' button
The photon is now in DFU mode and we are ready to flash our program onto it.
4. Flash your binary onto the photon
The command to flash a binary onto the photon is
> sudo particle flash --usb <binary-file>
e.g.
> sudo particle flash --usb photon_firmware_1440933735205.bin
Note: this needs to be done with sudo otherwise you get an error that looks like
> Error writing firmware...dfu-util: Cannot open DFU device 2b04:d006
If the flash was successful, the LED on the photon will return to its normal pulsing cyan colour.
I had to install a few bits and pieces to get this stage to work on my Ubuntu 14.04 laptop.
When I first ran the flash command it complained that dfu-util wasn't installed. After installing it with the standard 'sudo apt-get install dfu-util' I got an error along the lines of:
> 'invalid dfuse address: 0x08005000:leave'.
This led me to
a helpful forum post which indicated I needed to install a later version of dfu-util as the official ubuntu repo only had version 0.5 and we need 0.7+.
So I downloaded version 0.8 from
here (dfu-util_0.8.orig.tar.gz) and followed the instructions on the forum post to build it. In order to successfully run ./autogen.sh I needed to install 'autoconf'. And then in order to successfully run ./configure.sh I needed to install 'libusb-1.0.0-dev'.
After finishing up the dfu-util instructions I was able to successfully flash my program onto the photon. The only slightly annoying thing is that I get an error out of dfu-util despite the successful flash. From what I can tell from other people on the internet this is not unexpected.
Here is an example output:
jenny@jenny-940X3G:~/code/sht71-photon$ sudo particle flash --usb photon_firmware_1440934375581.bin [sudo] password for jenny: Found DFU device 2b04:d006checking file photon_firmware_1440934375581.binspawning dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D photon_firmware_1440934375581.bindfu-util 0.8
Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.Copyright 2010-2014 Tormod Volden and Stefan SchmidtThis program is Free Software and has ABSOLUTELY NO WARRANTYPlease report bugs to dfu-util@lists.gnumonks.org
dfu-util: Invalid DFU suffix signaturedfu-util: A valid DFU suffix will be required in a future dfu-util release!!!Opening DFU capable USB device...ID 2b04:d006Run-time device DFU version 011aClaiming USB DFU Interface...Setting Alternate Setting #0 ...Determining device status: state = dfuIDLE, status = 0dfuIDLE, continuingDFU mode device DFU version 011aDevice returned transfer size 4096DfuSe interface name: "Internal Flash "Downloading to address = 0x080a0000, size = 7756Download [=========================] 100% 7756 bytesDownload done.File downloaded successfullydfu-util: Error during download get_status
Error writing firmware...dfu-util: Invalid DFU suffix signaturedfu-util: A valid DFU suffix will be required in a future dfu-util release!!!
dfu-util: Error during download get_status