Skip to content

Prototyping nRF24L01+ modules on Arduino

I star­ted look­ing at the nRF24L01 chips while plan­ning a con­trol­ler for the sprink­ler in my back yard. They seemed like a pretty good option for low-cost, low-power wire­less Ardu­ino com­mu­nic­a­tion. They’re not per­fect, but when you can buy a 10-pack of mod­ules for twelve bucks on eBay it’s easy to settle for not per­fect. And I got excited at the thought of build­ing a mesh-style net­work of sensors and actu­at­ors using RF24Network. Per­haps a little too excited — my plans have become far more ambi­tious and involve ret­ro­fit­ting nrf mod­ules on to all of the exist­ing Ardu­ino doodads already in my home, and some more new sensor mod­ules out in the garden.

But first things first — order a couple, wire them up, and see if I can make them work.

nRF24L01+ on Arduino Uno

A basic net­work with two nodes is pretty straight­for­ward. I used maniacbug’s get­ting star­ted guide and a dia­gram of the nRFL01 mod­ule to con­nect the mod­ule to my Ardu­ino as fol­lows: 

Sig­nalRadio pinArdu­ino pin
VCC23.3V (NOT 5V)

Note that the default con­nec­tions for CE/CSN are pins 9 and 10, but I ended up using 8 and 9. This is because I was intend­ing to build a base sta­tion with an Eth­er­net mod­ule, which is hard-coded to use pin 10 for it’s SS.

Two nRF24L01 modules wired up to ArduinosI used a couple of small IDC line sock­ets from Jay­car and some rib­bon cable to break­out the pins on the nRF24L01 mod­ules, and a bread­board to man­age the inter­con­nects hook­ing two mod­ules up to two sep­ar­ate Ardu­ino boards. Then installed the RF24 lib­rary. Loaded up the Get­ting­Star­ted example sketch, mod­i­fied the pins in the radio ini­tial­isa­tion call (8 and 9 instead of 9 and 10) and loaded it on each Ardu­ino in turn. This sketch then requires open­ing a seri­al mon­it­or on one of the boards and put­ting it in Trans­mit mode. With luck that’s all that’s needed to get ping pack­ets flow­ing from one board to the oth­er and back again.

Basic protoshield with an nRF24L01 attached

Once I was happy that the basic stuff worked, I used this pin­out to solder a mod­ule on to a short pro­to­typ­ing shield, moun­ted it on an Eth­er­net-enabled Ardu­ino com­pat­ible board, and my wire­less base sta­tion was good to go!

nRF24L01+ on ATTiny84 w/ Arduino

I’ve been exper­i­ment­ing with the very small ATTiny85 chips for a while now, and love them for basic Ardu­ino pro­jects that only need one or two I/O pins. They seem ideal for remote sensor nodes, but the six pins required for the nRF24L01 com­pletely exhaust the ATTiny85’s cap­ab­il­it­ies (although neat hacks exist to drive the chip with only three pins). Its lar­ger sib­ling the ATTiny84 comes in a 14-pin pack­age, though, and has a max­im­um of elev­en pins avail­able. So I ordered a couple of those with a view to build­ing nodes in my net­work with them.

Get­ting this thing work­ing prop­erly had me thor­oughly con­fused for a while. The ATtiny chips do not do hard­ware SPI. The data sheet has SPI pins indic­ated, but as I found out only after sol­der­ing one to a pro­to­board they’re inten­ded for the ICSP inter­face, not to act as an SPI mas­ter. And there’s a few dif­fer­ent meth­ods out there to get around this fact. And to make mat­ters worse dur­ing my test­ing I acci­dent­ally hooked one of my radio mod­ules to the 5V line on my ICSP pro­gram­mer and fried it without noti­cing, which lead to a few days of frus­trated muck­ing around won­der­ing why lib­rar­ies weren’t work­ing…

Even­tu­ally I settled on the ardu­ino-tiny core for my ATtiny, and Steph­en Crane’s SPI lib­rary, a cross-plat­form lib­rary that uses the reg­u­lar SPI bus on chips that sup­port it, and SPI over the USI bus on ATtiny chips. In the end the pro­cess was pretty simple.nRF24L01 module hooked up to ATtiny84

  • Install Steve’s SPI lib­rary, as well as his forks of the RF24 driver and RF24Network lib­rary.
  • Open the RF24Network helloworld_rx sketch. Com­ment out all of the Seri­al calls. Change the radio ini­tial­isa­tion to use pins 8 and 9 for CE and CSN.
  • Burn the ATtiny84 1MHz core to a chip, and upload the sketch. I use High-Low Tech’s guide for work­ing with these chips, and a Tiny AVR Pro­gram­mer from Spark­Fun.
  • Remove the ATtiny from the pro­gram­mer, install it in a bread­board, and con­nect an nRF24L01 mod­ule to it. The ATtiny84 data­sheet comes in handy for this, as well as the ardu­ino-tiny doc­u­ment­a­tion for pin map­pings. In this table, “Chip pin” refers to the pin num­bers on the chip, and “Ardu­ino pin” refers to logic­al Ardu­ino pins. Note that Arduino’s DO and DI are not the same as MOSI and MISO that are labelled on the chip. 
    Sig­nalRadio pinChip pinArdu­ino pin
    INT8(not con­nec­ted)(not con­nec­ted)
  • Add power to VCC and GND. The radio mod­ule is rated to a max­im­um 3.6V. I powered my cir­cuit with 2.4V from a couple of Ni-Cad bat­ter­ies, but the 3.3V out­put from anoth­er Ardu­ino will do in a pinch.

I then took the radio mod­ule shield I’d made pre­vi­ously, and loaded the RF24Network helloworld_tx example sketch. Open the seri­al mon­it­or, and you should see the base mod­ule send­ing pack­ets out, and get­ting a response from the ATtiny.

And that’s the basic stuff. Right now I’m in the pro­cess of build­ing a simple net­work node based around the ATtiny84. It’s mostly ready, but I’m still in the pro­cess of writ­ing use­ful code.

One Comment