Playing with a Photon

phot-with-bat1Figure 1:  A Photon-powered project has been added to my collection.

Posted 09/22/2016:

I’d been toying with the idea of using the Arduino in a couple projects, where the more powerful boards could be seen as over-kill.  Price was not the only reason that I wanted to add MCU/WiFi SoC board based devices to my mix of (mostly) Pi and Odroid boards.  It was not even the most important one.  The most pressing need, relative to a small number of projects I have in mind, is for a device that has low power consumption.  I’m thinking about battery operated sensors in remote locations.  So, I thought about the Arduino lineup, and the cost of adding WiFi or Cellular or some other “increased distance” communication board.  Then, I stumbled upon the Photon by the people at Particle.io.

It fits the bill for my power consumption requirements, with a running power draw of 80 mA with WiFi turned on, 30 mA with it turned off, and as little as 175 micro-amps in deep sleep (or so I have read). One amazing thing about the device is the price: only $19 per board.  I couldn’t make the cost numbers add up to such $smallish dollars as that on *any* other platform that I’d been considering, and which included built-in WiFi or similar facility.  So, I obtained one of the little creatures from Mouser, and started to play …

Figure one shows the idea in a physical mock up.  Actually, the parts are real, they just haven’t been soldered together yet.  So, we have a battery bank of three Imedion NiMH “AA” cells, a 5.0 VDC booster that takes the (3.0 VDC – 4.2 VDC) range that is supplied by the pack, a Photon (of course), and an ADC board (or other) for sensor measurements.  Did I mention that the Photon, in addition to WiFi, does I2C, I2S, SPI, ADC, DAC, and general GPIO? For $19 bucks?

Oh yeah – and the plastic enclosure is left over from the Orange-box-pi project, where I had used the lid (of the plastic junction box) as an LCD frame. A small piece of plexi-glass will suffice as the replacement for the lid.  As the new device seemed too good to be true, I went about the business of putting the newly arrived Photon to work, doing a simple test.  The test would be the setup and execution of a local “web server”, associated with the local WiFi access point – in a “time and temperature” sort of mode.  Actually, the output line would just be a fictitious line of text (no sensor connection just yet).

netsurf-showing-photon-response1-4Figure 2:  A spoiler, showing the program download (to the device). Click to enlarge.

While the Photon is just an STM MCU married to a Broadcom WiFi chip and 1 MB Flash memory, it has bigger and better characteristics than some of the other options I’d been considering.  For starters, it has 128k of RAM memory for the programs.  Also – it runs at 120 MHz, which is substantially faster than some of those other options.

The bigger memory and faster speed characteristics make it play well in a real-time operating system environment, which it has.  It uses FreeRTOS as a sort of “hypervisor” – managing separate threads of execution for the WiFi stack, the system software, and the user application software. User programs are easily made multi-threaded.

Looking for documentation about where to start is not always straight-forward. The Particle.io site has a ton of information about the various high level development environments, and how to set them up, but I wanted to go with the bare minimum, using a text editor and gcc, and nothing else. I found the best info that taking that approach on the sparkfun.com site, as one of their tutorials:

sparkfun.com/tutorials/photon-development-guide

Particle.io has an online builder web app, where a person can do everything online.   They have another development environment that can be run locally, and which uses a special package (called particle-dev) that can be added to the Atom code editor (atom.io).  I did set up Atom, and added the particle packages, and saw that it worked (mostly). The particle-dev atom packages want to use an “online” compilation method, while also keeping a local repo for the source.  There is another atom package, called offline-compiler, that will both compile and flash the Photon locally, with no internet connection.  All these things were candy for me, but I wanted first to acquaint myself with the steak and potatoes methods. I went back to the terminal text editor for the balance of the photon-powered web server test.

For this project I selected Devuan Linux as the platform.  Mainly, this decision had to do with the fact that my Nvidia card was misbehaving on the Debian and Ubuntu distros I normally use.  On Devuan, it was cranky, but I could work around the issues. Probably driver related issues caused this, or systemd?  Anyway, here is a short list of the stuff I installed in order to eat meat and potatoes:

gcc-arm-none-eabi_4.8.4-1+11-1_amd64.deb
binutils-arm-none-eabi_2.25-5+5+b1_amd64.deb
libnewlib-arm-none-eabi_2.1.0+git20140818.1a8323b-2_all.deb
libstdc++-arm-none-eabi-newlib_4.8.3-9+4_all.deb

binutils_2.25-5_amd64.deb
build-essential_11.7_amd64.deb
autoconf_2.69-8_all.deb
dh-autoreconf_10_all.deb
automake_1%3a1.14.1-4+deb8u1_all.deb
autopoint_0.19.3-2_all.deb
autotools-dev_20140911.1_all.deb
libnewlib-dev_2.1.0+git20140818.1a8323b-2_all.deb

gcc_4%3a4.9.2-2_amd64.deb
libgcc-4.9-dev_4.9.2-10_amd64.deb
libstdc++-4.9-dev_4.9.2-10_amd64.deb
dpkg-dev_1.17.27_all.deb
fakeroot_1.20.2-1_amd64.deb
g++-4.9_4.9.2-10_amd64.deb
make_4.0-8.1_amd64.deb
libc-dev-bin_2.19-18+deb8u6_amd64.deb
libc6-dev_2.19-18+deb8u6_amd64.deb
gcc-4.9_4.9.2-10_amd64.deb
linux-libc-dev_3.16.36-1+deb8u1_amd64.deb

npm_1.4.21+ds-2_all.deb
libusb-1.0-0-dev_2%3a1.0.19-1_amd64.deb
libubsan0_4.9.2-10_amd64.deb
git_1%3a2.1.4-2.1+deb8u2_amd64.deb
debhelper_9.20150101+deb8u2_all.deb
git-man_1%3a2.1.4-2.1+deb8u2_all.deb

The short list, above, is not exhaustive, but has some of the development related packages I installed on Devuan to work with Photon. Some other software had to be compiled, either because the package-repo version  was too old, or didn’t exist:

  • git clone git://git.code.sf.net/p/dfu-util/dfu-util.git
  • cd dfu-util
  • sudo apt-get build-dep dfu-util
  • sudo apt-get install dh-autoreconf
  • ./autogen.sh
  • ./configure
  • make
  • sudo make install

I had to get the latest tarball from nodejs.org, since the package-repo for Devuan had an older version:

  • tar -xvf node-v4.5.0.tar
  • cd node-v4.5.0
  • ./configure
  • make
  • sudo make install

With the new nodejs, I could install a couple node related dependencies:

  • npm install -g particle-cli
  • npm install -g particle-api-js

Nodejs is needed for the particle command line client (particle-cli).  This program allows one to (among other things), configure the WiFi settings on the Photon:

$particle serial wifi

The command line (above), prompts the user for the SSID, the password, and the security level configuration details of the Photon (which at this point is only connected via USB).  One simply connects the board to a PC, using the supplied USB cable, puts the Photon into the proper mode by pressing switches on the board (see particle docs for this) – and WiFi setup is pretty smooth.  At least it was for me.  I was able to ping the board immediately after the setup finished, and the board reset itself.

The next thing I did was to get the firmware:

Then I added some found-snippet tcpserver application code (more on that later), changed to the modules directory in the firmware source tree, put the Photon into DFU mode (more on that later) and issued:

make clean all PLATFORM=photon APP=tcpserver program-dfu

The build system built the system firmware (in two parts), as well as my application binary (the tcpserver), and then downloaded all three pieces to the Photon.  Subsequently, I could use my Netsurf browser to visit the Photon’s little web page (shown in figure 2).  Success!

Read More

Note: the author does not have a recent, applicable background in circuit building, or battery related issues, so this is presented as the work of a hobbyist, and is not meant for duplication by others. Readers should look elsewhere for design advice and info.

Note: the Photon referenced in this post is manufactured by the folks at particle.io, and this site and author are not related in any way. PHOTON is a trademark of Particle Industries, Inc.  The Arduino is manufactured by the people at Arduino.org, and they are not affiliated with this site or author in any way.

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s