Nordic FOB and nRF24L01+

Nordic FOB and nRF24L01+

Sparkfun sells a nifty little gadget to control your project remotely using nRF24L01+ radios. It’s a small key fob with 5 buttons, which transmits codes when you press each button. Today we’re going to explore how to receive those signals using the RF24 library. This is all thanks to Kirk Mower who sent me these units for Christmas. Thanks, Kirk! :)

Parts

Qty Vendor# Description Price
1 WRL-08602 Nordic FOB $24.95
1 WRL-00691 Transceiver nRF24L01+ Module with Chip Antenna $19.95

Connections

Sparkfun nRF24L01+ module connections

Connecting the Sparkfun transceiver unit to an Arduino using a breadboard is easier than with the typical modules. Does that make it worth $20 over $4? You’ll have to decide that. To connect it, we can follow the guidance on my previous post, Getting Started with nRF24L01+ on Arduino. Wiring it this way means we can use all the RF24 examples, which are set up to use these pins by default.

Radio Arduino
GND GND
VCC 3V3
CE 9
CSN 10
SCK 13
MOSI 11
MISO 12

Sketch

This is now an example for the RF24 library, nordic_fob.pde.

Setting up the radio is simply a matter of matching the radio parameters on the receiver with those of the transmitter. We can refer to the device firmware for the transmitter settings.

  radio.begin();
radio.setChannel(2);
radio.setPayloadSize(4);
radio.setAutoAck(false);
radio.setCRCLength(RF24_CRC_8);
radio.openReadingPipe(1,0xE7E7E7E7E7LL);

The payload sent by the transmitter is 4 bytes long. The first is one byte containing the current state of the buttons. The low 5 bits correspond with each button, and the bit is 1 when the button is up and 0 when pressed. Bytes 2 & 3 are a 16-bit sequence number I call the ‘id’. Every time the unit sends a packet, the sequence number is increased by 1. The 4th byte is not used. So this is what our payload looks like:

struct payload_t
{
uint8_t buttons;
uint16_t id;
uint8_t empty;
};

The main loop simply listens for packets, and dumps out the results, translating the button bits into words so it’s easier to read.

void loop(void)
{
//
// Receive each packet, dump it out
//

// if there is data ready
if ( radio.available() )
{
// Get the packet from the radio
payload_t payload;
radio.read( &payload, sizeof(payload) );

// Print the ID of this message.  Note that the message
// is sent 'big-endian', so we have to flip it.
printf("#%05u Buttons ",flip_endian(payload.id));

// Print the name of each button
int i = num_buttons;
while (i--)
{
if ( ! ( payload.buttons & _BV(i) ) )
{
printf("%s ",button_names[i]);
}
}

// If no buttons, print None
if ( payload.buttons == _BV(num_buttons) - 1 )
printf("None");

printf("\r\n");
}
}

About these ads

13 Comments

Filed under Arduino, RF Radio

13 responses to “Nordic FOB and nRF24L01+

  1. Great. So what pins/wires did you use to solder the RF unit onto those male pins for the BreadBoard?

  2. Those are right-angle pin strip headers. Mouser part #517-500-01-36.

  3. Finally got to trying it out – I get an infinite loop when running the example Nordic_FOB.pde (well as .ino in Arduino 1.0). From the Serial Monitor: http://pastebin.com/raw.php?i=v5dgHzEi

    #65535 Buttons
    #65535 Buttons
    …and on – button clicks don’t seem to get picked up at all.
    Do I need to change the address of the radio in Nordic_FOB.pde to one of those parameters at top? Thanks.

    • > RX_ADDR_P0-1 = 0xffffffffff 0xffffffffff
      All these FF’s are telling us that the software cannot communicate with the radio attached to the Arduino. This usually means one of the wires is not connected properly.

  4. OK – I may have fried the radio by having mistakenly plugged it into 5V previously….

  5. John

    I made some changes for noobs like me who do not understand the arrays and const functions. See http://pastebin.com/fXhkXmDa

  6. Don

    Hi,
    After no success with other libraries, yours worked very easily! Thanks so much.
    I am using the Nordic FOB and it read key presses and outputs to the serial monitor, however I get:
    RAVÓ`†´^J±’îÆJL¸’îÆÊL,îÆÊL¬QæÄÊõp';f’”^~¬Q/9
    1-¤ 5êä¤qDC@C”’j˜¨˜A`–’zž2b ÑGˆeð²Èx‚
    þ-¤[\ùàK,1Á‹@
    zÑ8©a.@Ãd,9Cp8BQjb–j˜¨˜A`–’zž2b ÑGˆeð²Èx‚
    þÃøþÂè þâÄàBÉ`ôbÄQðCØ@ðbÌÕÿBÁ ðãØ@ðBÉøñâèáÂéàñ

    That last line is a series of key presses.
    Any hints on how to turn that into plain English?
    Thanks so much!
    Don

  7. Thanks, worked perfectly first time! Now I just need an idiots guide to re-programming the FOB so I can switch to a different channel…

  8. John Howard

    Do these fobs have an identifier so that it’s data can be recognized or ignored (such as is done with a garagedoor opener)?

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