Networking the NRF24L01+

tmp97BDThe tiny NRF24L01 modules you see in the photo to the right (the module handing off the board to the left) make great short distance communication units for Arduino projects – using the RF24 library. The main attraction of these radio units is their cost – under £2 each module from China (Ebay). The downside is they are short range, maybe 80 metres or so in a straight line but dramatically less through walls.  The main board you see is something I put together as a general purpose Arduino-compatible board, soon to be revised.

I’ve done a fair bit of experimenting with these radio modules as they make really cheap radio communications possible – the RF24 library works ok but the first thing to do is change the default 1Mbps data rate to 250Kbps. Still quite fast, considering you only send short packages – but this adds maybe 50% to the range depending on obstacles. I found the variations with a better aerial were only marginally better than these green10-pin modules.

http://maniacbug.github.com/RF24Network/index.html

The real breakthrough is to use these in a network – I have scoured the web and found almost nothing out there to do the job –some academic half-finished projects… but there is one… RF24NETWORK. I had to go into the main library file and change the speed (one location, easy to find) and in the test file do the address assignment in code (the example accepts a single digit from the serial input – if you don’t have anything attached to the input and leave it floating,  you’re asking for trouble as the format is too simple – but then I am just talking about an example – one would assume you’d burn in the address by another method in production.

The fellow has documented everything well but beginners beware – if you see a leading zero, he’s using OCTAL (base 8, ie 0 1 2 3 4 5 6 7 10 11 etc.) numbers which threw me off for a few minutes…

So the idea is you connect units in a tree structure… the root is device ID 0… then at the first level up you have devices 1,2,3,4,5.  The modules can listen to 5 channels at once so that’s how he’s based his network – here’s where the octal comes in  -siblings of device 2 would be 012,022,032,042,052 (they are Octal numbers). Any of those 5 can listen to 5 more etc.  It is possible to put thousands of modules in this network (though I would not recommend it) and I’ve already proven to myself that it works by making 3 units (the photo above is a board I designed some time ago as a general-purpose Arduino board) and spacing them so that the last board could not possibly communicate with the first one by sheer distance.

Works a treat – well worth investigating. Here is a conversation (with debugging turned on) and you’ll see the messages being passed around. Note line 8014. This log is coming from device 0.

Update May 2013: This article was originally written in 2012. Note that I have written a later article here – there are still issues with the networking software as you will see.

tmpE7E0

Advertisements

10 thoughts on “Networking the NRF24L01+

  1. The main disadvantage of a tree system is that the removal (failure) and any node splits the network into two pieces… is there any way to get a non-tree network going?

    • I agree, but this is the best I’ve been able to find. The RF24 library is a great starting place for reliable communications but it does not implement a network. I’ve looked all over and there does not seem to be anything. The RF24 can handle packages of up to 32 bytes – and can listen to up to 5 other devices at the same time… I guess this network library is based on that. You would think by now with the interest in Arduino and those devices that someone would have come up with something – but not as far as I can tell – so this is the best we have so far unless someone cares to prove me wrong.

      • Now I’ve thought about it (and read your recent posts), the solution seems a bit more obvious: if a child looses its parent, can it try and find a new parent?

  2. My GOD… as people often say. Hadn’t thought of that.. but how would it talk to others… it might be possible for it to start going through a list of possible parents and find one – but there’s no way to talk to it as the others might have a full complement of (5) siblings… I do hope anyone reading this know we’re talking about radios 🙂

  3. Pingback: Arduino Home Control Part 1 | Scargill's Tech Weblog

  4. Hello there ,

    first of all congrats with your blog.
    i’ve reading this article but i can’t make it to have a RF24 Network with base(0) , leaf(02) and other leaf(022)
    mb i do something wrong , a simple base(0) leaf(1) works.
    please can i have a example script for these three please ??? so i can see what i do wrong.
    Already post it on arduino.cc but can’t get fast response there

    tnx a lot and greetings from belgium

    helmut

  5. Thanks for a really useful posting – helped me get my multi-node network up and running (eventually!). One query though – you mention changing the default speed to 250kbps but hard as I have tried I always get compile errors. I am using the + devices (I discovered the earlier devices don’t support the lower speed. Clearly I’m doing something stupid here and would really appreciate your insight as to exactly how to do this!

    • Here’s the mod I made..

      In the RF24NETWORK library – in the RF24NETWORK.CPP file in the RF24NETWORK:begin function near the start

      // ps mods
      radio.setDataRate(RF24_250KBPS);
      radio.setPALevel(RF24_PA_MAX);
      // end psmods

  6. Hello Pete,
    could you please tell me how you manged to set up the base node address?

    When I reset my arduino after loading sensornet sketch for the first time, it prompts on the serial port for the node address. I enter 0N, but get the message that this sketch cannot be run on node 00. I have done a search of the forums and see that other people have had the same problem but I cannot see a solution.

    many thanks
    punkie

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