Nordic’s nRF24L01+ 2.4GHz RF radios are a great way to communicate wirelessly between Arduino’s. They’re cheap, and powerful. Unfortunately, they can be a little daunting to beginners to get started. Today, I want to make it easy for total beginners to get up and running on nRF24L01+ radios quickly and easily.
Stuff we need
First, we have to go shopping. A great place to start is the iTeadStudio store. Here’s what you need. Obviously, you’ll want to buy two of the radios and protoboards because what good is a radio that can only talk to itself?
Reasonable substitutes for this stuff can also be found at Sparkfun if you like spending a lot more money. Also the radios are at MDfly.com.
My goal today is to create a sensor node which can be used in a wireless sensor network, to capture environmental information and send it back to the base. My main goals are for the nodes to: Be cheap, and last for a year.
How cheap and how low-power can we go? In the end, I got down under $12 for a very capable Arduino-compatible node with a 2.4GHz radio running ~2.6V that should last a year and a half on 2 AA’s, or 5 months on a coin cell.
Ken Boak at the London Hackerspace recently sent over a Nanode to try out. This is a handy combination of Arduino and ENC28J60 Ethernet in one package. My mission is to try it out with Jee Labs’ EtherCard library. This code is by far the most mature, stable, and easiest to use ENC28J60 driver for Arduino.
I’m happy to report that the 7752 revision of EtherCard works perfectly out of the box with NO changes. Even the SPI chip select pin is right, because Jee Labs’ EtherCard hardware uses pin 8, just like Nanode.
This week, I got my hands on a pair of Zigduino units. This is Pierce Nichols’ creation of a Arduino on steroids plus a Zigbee-compatible RF radio, all in one unit. From a hardware perspective, this replaces an Arduino, Xbee Shield and Xbee all at once. On top of that, there are a few more advantages: It’s compatable with further shields, unlike normal Xbee shields which don’t allow you to stack. And best of all, it uses the Atmega128RFA1 chip instead of the Atmega328p found on the Uno. This MCU brings 128KB of flash and 16KB of RAM to the party, plus a bunch of other great features for the power user (onboard AES, among others).
The biggest thing it lacks is a ready software stack. Xbee is easy for even the most non-technical user to bring up, which explains its popularity in the Internet community. So this what I’ve been working on, at least the beginnings of it. The most straightforward way to use Zigduino today is to get Atmel’s IEEE 802.15.4 MAC stack implementation of the IEEE 802.15.4 MAC standard. This is an extensible multi-layer stack that makes available the full power of this SoC. The source is available, it’s well-documented, and it comes with exhaustive examples.
What’s the problem? First, the licensing. While the source is available, it includes no redistribution rights, so it’s not something you can hack on and go share your changes. Second, the build system. For someone comfortable with GCC and Gnu Make, all is well. For folks who take comfort in the simplicity of the Arduino IDE, it’s a problem.
ZMAC is my solution to this problem, available at github.com/maniacbug/ZMAC. First, you download the Atmel MAC distribution yourself, sign up with Atmel, agree to the license, etc. Then you get ZMAC, and run the fileprep script. This will copy and modify the files as needed to organize them so the Arduino library can pick them up. It will even translate some of the examples into a form that will load and compile and run using the Arduino IDE.
Today’s goal is to get my Arduino on the wired Ethernet for cheap. There are basically two options in Arduino-land for Ethernet, Wiznet 5100 or ENC28J60. The Wiznet solution is the easiest and consequently it’s the standard for Arduino Ethernet. It’s also expensive. $45! I bet we can do better.
Electronics Kits Zone sells an ENC28J60-based Ethernet Shield Kit for $19. Stand-alone modules can be found cheaper still such as this $17 module from mdfly.com, but you still have to interface it with the Arduino and convert the voltage down.
Of course, all cheap hardware comes with a price. It requires a TCP/IP stack in software, as opposed to the Wiznet which implements it in hardware. This is not a trivial problem! We expect a full working TCP/IP stack on our PCs, but on a memory-constrained microcontroller, it’s another story entirely. None of the available stacks implement it fully, they all take some shortcuts. Worse, I could never find one that has been ‘tested by fire’ as much as a PC (or Mac or Linux) stack. They seem to still be fairly immature. This translates into a serious pain to use. You have been warned!
I really want to communicate wirelessly between Arduinos for cheap. I love the idea of “The Internet of Things”, with everything I can look, see, touch all connected together. The problem is the cost. Zigbee modules seem to be the standard, but they are just too much to be a reasonable solution for putting everything on the Internet.
The Nordic nRF24L01, built into a small module and sold by mdfly.com for $6.50 is an excellent solution. It’s cheap, fast (2 Mbps), easy, reliable, and low-power. It entirely implements the Data Link Layer in hardware, handling addressing, collisions, and retry, saving us lots of work on the software side. Zigbee has the brand recognition, but this little guy puts it to shame.
Now that we can drive a single 7-Segment LED, and we can use an I/O Expander to drive a Double 7-Segment LED, what’s the obvious next step? A Four-segment model! In the picture above, I’m driving it with an Arduino Pro Mini sitting on a little connector board I made, though anything that can supply power and I2C will work.
||LED Displays 0.56in Hi Eff Red 4Digit Clock Ca
||16B I/O Expander I2C interface
||16pin 100ohms Isolated Low Profile Resistor Network
||Bipolar Small Signal NPN Transistor General Purpose
The way this part is wired, only a single digit can be on at any time. The trick is to set one digit, and then quickly move on to the next digit. Each digit is on for 1/4 of the time, but that’s enough to imprint it on your mind and so you see them all. They call that ‘Multiplexing’. Fancy!
As with my other LED’s, I have chosen a ‘Common Anode’ part for consistency.