Monday, December 31, 2012

Arduino Esplora interfaced to an Xbee Radio

Third in a series, I expand on my previous post documenting the Arduino Esplora expansion header and using the hardware and software serial capabilities of the Arduino on the Esplora platform.
For this post, I use a small perfboard and some header to make a plug-in platform for the Xbee project.  To aid prototyping, I use a small breadboard available from most electronic outlets.  You can use the same concept to prototype any circuit you like with the Esplora using the expansion pins I document here.
A perfboard with headers used to anchor it as a base

On the breadboard, I mount an Xbee adapter board (similar to Sparkfun board, also use headers).  As the Xbee operates at 3.3 volts and the Esplora is a 5 volt system at the expansion header, I use a voltage regulator (one from Adafruit was handy but you can make your own 5v to 3v3 circuit, see Igoe Making things Talk, pages 200-201).  Per Igoe, the Xbee data lines are 5 volt tolerant so I interface them directly.

Esplora connections: Pin 10 ground (black), Pin 9 +5 volts (red), Pin 8 Transmit (orange), Pin 7 Receive (green).  +5 goes to the regulator input and the regulator output goes to Xbee pin 1 VCC.  Connect ground to the regulator and XBee grounds.  Note: The receive line pin 7 from Esplora goes to Xbee transmit pin 2, transmit line from Esplora header 8 connects to Xbee receive pin 3.  That's basically it on wiring, not fancy when you know what you are connecting to.
Mounted breadboard with regulator, Xbee carrier and Xbee.  Wiring from the Esplora right header to the breadboard.

For software, I take the lead from my previous post on pin mapping.  The Esplora hardware serial line follows Leonardo conventions.  The Serial function talks to the USB.  The Serial1 function talks to the "D0/D1" hardware serial line we know from programming older Arduinos like the Uno.  These are on Esplora header pins 7 and 8.  Software serial is possible too although the receive pin must be another data line that supports the softwareserial library's interrupt function.  Here I stick with the hardware serial and it is simpler.

I took the Arduino software IDE example sketch "EsploraRemote" and added just the tiniest tweeks to change use of the serial port (USB) to the hardware serial line Serial1.  The code is available as EsploraXbeeRemote at https://github.com/TheKitty/EsploraSerial .  The code is simple but cool - it takes input to either change the buzzer or LED on the Esplora or return Esplora input values.

On radios, I use two Xbee Series 1 radios.  The MY addresses are set to 1 on #1, 2 on #2.  Destinations are set to the other (2 for #1, 1 for #2.  They are also set for serial communications 9600, 8, N, 1.  For Xbee basics, see Making Things Talk or the digi examples website.

Esplora with Xbee and another Xbee talking to it wirelessly
For the transmitter, I use the Foca board I used yesterday - you can use equivalent boards from Adafruit and Sparkfun - they turn a USB port into serial to talk to the Xbee or to talk TTL serial.  You can use any Xbee transmit/receive project to speak to the Esplora - the example just uses a serial terminal to talk to the Xbee which wirelessly sends and receives characters to the Esplora via the other Xbee.  I use the PuTTY serial terminal on Windows - it is available on Mac & Linux or use your favorite serial program.  I set communications to the same as the example program and my Xbees at 9600 baud.  I enabled local echo on the terminal to see what I was typing.

Upload the ExampleXbeeRemote sketch from my Github repository.  Upload the sketch to the Esplora.  Now the USB will only power the unit and we will not use USB to talk to it.  In PuTTY, you type any of the commands listed in the example code headet, for example T440 (which turns the Esplora buzzer on at a frequency of 440Hz).  If it is all connected right and the Bees are set right the annoying buzz will start (use T0 to turn it off).  The Rxxx, Gxxx, and Bxxx commands set the color of the onboard RGB LED.  Very cool.
Screen shot with PuTTY terminal left and Arduino IDE right
With this you can wirelessly communicate with your Esplora, one step closer to making a truly wireless controller (the last step being battery power).  If you use other radios, post your links to your project as a standard serial line will "speak" to nearly any radio link.  Enjoy.

PS Yes the Esplora schematic has a small 3 .3 volt regulator for limited use by one sensor, I did not try to hack into it as it is not readily available and most likely very low current - the 5 volt system has many milliamps for use so a regulator from 5 volt to 3.3 volt (especially an efficient one) is a good solution.  The one I use is a more expensive Adafruit buck converter, overkill at $15 but I had it.  A 78xx or similar regulator and a couple of capacitors like in Making Things Talk works just as well at a lower cost but higher parts count.