In this part of the prototype, we will build a “base station” that will (eventually!) receive sensor data from sensors spread throughout the house and then send the data to a web service.
The base station will be built using an Arduino, Adafruit’s cc3000 breakout board, and an nRF24L01.
Why the nRF24L01?
I’m exploring different wireless technologies that are best suited for in home communications. Picking a technology is all about knowing which trade offs are important. This is true with wireless communications. There are many different wireless options – 802.11, BTLE, Zigbee, nRF24L01, 433 MHZ RF…
Each one is optimal for a few scenarios. It has been my experience (30 years of shipping software products – from millions of copies to 10,000’s) to define a scenario with metrics around the technology in question then match these metrics to the technology that best fits the scenario/metrics. For example, my playing around with writing BTLE apps for iOS cemented for me how ideal BTLE is for a PAN (Personal Area Network). I can see why Apple has an optimized BTLE API and why most wearable devices talk with Smart Phones via BTLE. My years with 802.11 and Ethernet has cemented my thoughts that these more beefy protocols are well suited for the wild and wooly world of Internet traffic.
I am new to in-home networks. I have read a bit about all the options, but the only way I can understand the trade-offs of an RF technology for in-home use is to experiment with it. Lucky for us the Arduino plus RF components makes it easy to do so. I’ll be trying other in-home technologies, but this post is about the nRF24L01. This blog entryprovides good information on the nRF2401 as well as pointers to sketches that use the chip.
Wiring Up the nRF2401
Time to connect the nRF2401 to a breadboard. The nRFL2401 has 8 pins:
I decided the simplest way to connect the nRF2401 to the breadboard was by using a solid ribbon of male to female cables.
I separated out 8 – which made it easy to follow the cable connections based on the information in this post. I used the pin settings for the RF24 Library.
We can tell from the above that the nRF2401 uses SPI to communicate with the Arduino. As is typically the case, the Arduino pins 10,11,12,13 are used for SPI communications.
Here is the chip connected to the female end of the cables.
The test sketch we will use is provided by the nRF2401 Arduino library. Download the zip file and place the files in the place where Arduino libraries need to go to be recognized by the Arduino IDE.
Hook up the Arduino to your Mac/PC and load the GettingStarted.pde example sketch. Run the sketch. If the nRF2401 is hooked up correctly, you’ll see something like this:
STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0 RX_ADDR_P0-1 = 0xe7e7e7e7e7 0xf0f0f0f0d2 RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6 TX_ADDR = 0xe7e7e7e7e7 RX_PW_P0-6 = 0x00 0x20 0x00 0x00 0x00 0x00 EN_AA = 0x3f EN_RXADDR = 0x03 RF_CH = 0x4c RF_SETUP = 0x07 CONFIG = 0x0f DYNPD/FEATURE = 0x00 0x00 Data Rate = 1MBPS Model = nRF24L01+ CRC Length = 16 bits PA Power = PA_HIGH
on your serial debug monitor.
As noted in this blog post, if you see zeroes where values should be, double check how your wires are connected. It is very easy to connect the wrong wires between the Arduino and the nRF2401.
We’ll be adding the nRF2401 to the 802.11 circuit we wired up in this prototype. There is only one “gotcha” to be careful about. Both use SPI, running as slaves to the Arduino master SPI device. As noted in this blog post on wiring multiple SPI components to the Arduino:
SPI bus consists of 3 shared data lines – SCK, MISO and MOSI, plus one “Slave Select” AKA SS line per each device.
What this means is each component that talks to the Arduino using the SPI must have a unique pin for the SS line (note the nRD24L01 refers to the SS line as the CSN or Chip Select line. CSN is a different name for SS).
Most components I have purchased that uses the SPI defaults to pin 10 for the SS line. In some unfortunate cases, either the hardware and/or the software prevents moving the SS line from pin 10. That stinks because if there are two components that refuse to move off pin 10, only one can talk to the Arduino through the SPI.
We are in luck! The great folks at Adafruit made it easy-peasy to change the SS line’s pin. I’ve chosen to use pin 8 for the SS line. To do this is simple. Just change this line within sketches that use Adafruit’s cc3000 and libraryto the SS line’s pin (Adafruit refers to the pin as CS).
#define ADAFRUIT_CC3000_CS 8
We are in even more luck! It is as easy to change which pin to use for the SS line with the RF24 library. I discuss this more in this post.
index.php?p=299And there we have it! A mess of cables! Admittedly, my prototypes are U-G-L-Y!
This wasn’t possible to read so I tried out the Fritzing software to document our prototype. I think I was scared into using Fritzing after attending a short course on kicad. Now – kicad seems like a great tool. But is geared towards the person that knows their way around building PCBs. I aspire to build PCBs, but have not yet. Also, surprisingly (at least to me), the Mac version is hard to install and less stable than the Windows and Linux version.
On the other hand, Fritzing seemed inviting, as their home page notes:
Fritzing is an open-source hardware initiative to support designers, artists, researchers and hobbyists to work creatively with interactive electronics. We are creating a software tool, a community website and services in the spirit of Processing and Arduino, fostering an ecosystem that allows users to document their prototypes, share them with others, teach electronics in a classroom, and layout and manufacture professional pcbs.
Oh happy day!
And – another YIPPEE! moment – Adafruit actively puts their components into Fritzing libraries. This makes it easy-peasy to add the cc3000 to the diagram.
The nRF24L01 chip is used instead of the breakout board. This is because the only nRF24L01 I could find was in one of Sparkfun’s libraries. Hopefully, I matched the pins correctly. I followed the pin assignment documented in the nRF24L201 product specification.
I am hoping you can follow the pin layout in the diagram. If not, please leave a comment and I will write out which wire is connected to what pin. The main elements are the SPI, GND,PWR wiring.
Now the fun begins – does everything work? We tested each RF component separately. What about together? Run the sketch for the nRF24L01 we ran earlier. Then run the cc3000 sketch we ran while building this prototype.
This should work! When I led a team of software developers, there were times when I couldn’t get their code to work. A typical response was “well – it works on MY machine.” My reply was “great, but how do we get your machine to each customer?” For my stuff, it is rare that my prototypes work the first time. If this happens to you, my challenges typically were in the wiring. So double check this. I must have made at least 5 wiring mistakes until I got it right.
If either one of the sketches did not work, double check the wiring. I must have made at least 5 wiring mistakes until I got it right.
So that’s it for this prototype. The next one will set up another nRF24L01 to transmit sensor data to our Base Station.