[Raspberry Pi - Arduino ]Lamp Switch

[Raspberry Pi - Arduino ]Lamp Switch


 

A month ago we planned to manage our Arduino irrigator (aka Irrigatorino) through the NRF24l01+ wireless  module. Our little project has been subjected to a little change, since we decided to make our life easier (buahahah…) and remote control a light over a browser (yes, mobile too). Surprisingly, a lot of people liked the little demo I’ve made with some raw code and asked for a tutorial, so here we are:

Ladies and (more probably) Gentleman, I’m glad to present  you the lamp driven by a browser switch!

Nothing new actually, but still exciting!

Arduino Nano 328 connected with NRF24l01+ module and Lamp

Arduino Nano 328 connected with NRF24l01+ module and Lamp (in the background)

Hardware:

To test the wiring we suggest you to use the ping/pong test you can find  in the RF24 libraries (both, of the raspberry and the arduino).

Raspberry Pi

The connection between the Raspberry Pi and the NRF24l01+ module was a little bit tricky, so you have to double ( or triple) check the wiring before giving up. Here is the wiring scheme, the Raspberry Pi is a revision 2, and the module is the + (plus) version.

Raspberry Pi (rev2) - NRF24l01+ Diagram

Raspberry Pi (rev2) – NRF24l01+ Diagram

Arduino

The setup is easy and similar to a mix of our tutorials about Irrigatorino and NRF24l01+ Tests.
Just keep in mind that you are playing with dangerous voltage, so if you get struck, it’s only your fault. I would suggest, anyway, to check if everything (especially the relay board) is working with a multimeter, before connecting to a real lamp.

Arduino Nano - NRF24l01+ - Lamp Diagram

Arduino Nano – NRF24l01+ – Lamp Diagram

Software

Our plan to communicate between all this stuff is to use a Node.js application to run a binary ‘./switch -f On‘ and ‘./switch -f Off‘  sending a message to the Arduino with the text 1 and 0 .
When the arduino receive it, it then sends back an acknowledgment packet to the raspberry with the same message (yeah, like a parrot). In the meantime, if the message the arduino receive is 1  it will close a relay (turning on a light, like a good parrot), otherwise it will open it (I doubt a parrot could be so clever).

Sketching

The sketch for the Arduino Nano is nothing more than a Getting Started demo of the RF24 library. We just modified it to switch the relay on in case it receive a message with 1 as text, or open it otherwise. Of course you’ll need the RF24 library to make it work.

 

Enabling Raspberry Pi GPIO and Installing Node.js

First we enable the Raspy GPIO:

Method 2 (not tested, but should work):

Let’s install node.js.
If you don’t need the latest version you can install it from the repos:

Otherwise you can follow this instructions (under Ubuntu, Mint… section) to compile the latest version.

The Lamp Switch Application

What we need now is to write an application that will send a message to the arduino using the NRF24l01+ and the Raspi. So the first thing to do is download the RF24 library ported for Raspberry Pi.  I would suggest to use git.

Now let’s install the library:

 

And now we create the switch application,which will be the main binary we will use to send message to the arduino.

Create a new file called switch.cpp in the ~/RF24/librf24-rpi/librf24/examples folder and past this code inside:

And now compile the application:

If everything went well you should be able to turn on (and off) the relay at this point using the ./switch -f on application, hearing the famous ‘click’ from the relay board.

We’ve left the debug printout in the code so you can easy arrange a solution in case of some bugs.

The Node.js Lamp Application

At  this point the only thing left is to build a little node.js server and bind a click  on a client browser to an exec function on the raspberry server.

Since it’s more than just a file, we’ve placed  a link to the repository on github. All the code is commented, so I hope everything is clear. Anyway, since we were a little bit confused on our first node application we’ve decided to write down a little note to help you understand:

- light-app.js   => is the application you need to run with “sudo node light-app.js” (the sudo is NEEDED). This is the server configuration and will launch the client interface too.

- package.json => required modules (with version) you need to run the application

- node_modules (folder) => it’s an auto generated folder which contains the modules

- public folder (folder) => contains light.js, the javascript code loaded on the client and bootstrap folder for styling

- tpl (folder) => contains the page.jade template for the client

To run the application you need to:

 

Authors note (31/3/2014)

We love the way you support each other in the comments! It’s really a satisfaction for us.
We can’t be always here to answer your questions or doubts, and all your contributions are a really great value you add to this website.
Thank you all!

Comments

54 Comments

Post a comment
  1. Björn #
    April 18, 2014

    Hi, I’m pretty new on the linux environment and not sure what I’m doing. I’ve tried to use the guide but I’m getting the following error when trying to compile the switch program:

    pi@greenhouse ~/RF24/librf24-rpi/librf24/examples $ sudo g++ -Wall -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -L../librf24/ -lrf24 switch.cpp -o switch
    /tmp/ccm241WK.o: In function setup()':
    switch.cpp:(.text+0x14): undefined reference to
    RF24::begin()’
    switch.cpp:(.text+0×24): undefined reference to RF24::setRetries(unsigned char, unsigned char)'
    switch.cpp:(.text+0x30): undefined reference to
    RF24::setChannel(unsigned char)’
    switch.cpp:(.text+0x3c): undefined reference to RF24::setPALevel(rf24_pa_dbm_e)'
    switch.cpp:(.text+0x48): undefined reference to
    RF24::setPALevel(rf24_pa_dbm_e)’
    switch.cpp:(.text+0×58): undefined reference to RF24::openWritingPipe(unsigned long long)'
    switch.cpp:(.text+0x6c): undefined reference to
    RF24::openReadingPipe(unsigned char, unsigned long long)’
    switch.cpp:(.text+0×74): undefined reference to RF24::startListening()'
    switch.cpp:(.text+0x80): undefined reference to
    RF24::printDetails()’
    /tmp/ccm241WK.o: In function switchLight(int)':
    switch.cpp:(.text+0xa8): undefined reference to
    RF24::stopListening()’
    switch.cpp:(.text+0xc8): undefined reference to RF24::write(void const*, unsigned char)'
    switch.cpp:(.text+0xe0): undefined reference to
    RF24::startListening()’
    switch.cpp:(.text+0xe4): undefined reference to __millis'
    switch.cpp:(.text+0xf4): undefined reference to
    RF24::available()’
    switch.cpp:(.text+0×134): undefined reference to RF24::read(void*, unsigned char)'
    switch.cpp:(.text+0x138): undefined reference to
    __millis’
    switch.cpp:(.text+0×154): undefined reference to __msleep'
    switch.cpp:(.text+0x158): undefined reference to
    __millis’
    /tmp/ccm241WK.o: In function _GLOBAL__sub_I_radio':
    switch.cpp:(.text.startup+0x1c4): undefined reference to
    RF24::RF24(std::basic_string<char, std::char_traits, std::allocator >, unsigned int, unsigned char)’
    collect2: ld returned 1 exit status

    Any ideas what I’ve missed? Using 2014-01-07-wheezy.raspian

  2. Mohit #
    April 18, 2014

    Hey Guys,

    I’m building a system where my Pi (central unit) needs to connect to multiple Arduinos wirelessly.

    So I have one Pi and 3 Arduinos set up.

    Each Arduino has a variable called ID to help identify it.

    If my Pi want to talk to Arduino with ID = 1, it will send a message with the format : 1XXXX
    If it wants to talk to Arduino with ID =1, the message sent out will be : 2XXXX

    Even though all units are kept in the same room for now, I’m noticing major packet drops.

    One of my observations is this : when the Pi transmits, all the Arduinos receive, but if the ID does not match, they do nothing, only the Arduino with the correct ID will give an Acknowledgement back, but it turns out the Pi does not receive the Acknowledgement.

    What I can’t figure out is, whether my modules are faulty, or are they not designed to work this way ..??

    Thanks !

  3. sid #
    April 18, 2014

    Hi Edoardo,

    I have implemented this for a home automation system.
    This works but the problem is it works intermittently.

    At times it works really smooth.
    The next moment it stops working.
    After some investigation I found that the NRF24l01 on arduino receives the request works on it and sense the response back to NRF24l01 on raspberry. But the raspberry is not able to receive it resulting in packet drops.

    It enters the following part of cpp code

    while ( ! radio.available() && ! timeout ) {
    __msleep(100);
    if (__millis() – started_waiting_at > 1000 )
    timeout = true;
    }

    As radio.available never becomes true this thing times out.
    I increased the delay to 100 from 10 to give NRF24l01 on rpi time to find data sent from arduino, but that didn’t help.

    What surprises me is even the switch is not toggled by arduino.
    Range can’t be an issue as arduino and rpi are in same room.

    Can you please tell me what is the problem here.
    Is it the NRF24l01? Is it faulty?
    Or do i need to add anything in the code?

  4. Oscar #
    April 15, 2014

    Hi. Thanks a lot for sharing your jobs. I’ve done your project, in order to test miself!!. But now I have to implement my own solution. I want to control some blinds, each one with an arduino one, with a raspberry pi. But my problem is that I’m gonna use some wall blind switch. So I would need to transmit with the arduino to the raspberry when the switch its been activated, in order to memorize the new blind position on the raspberry. My first solution to do that it’s to have two different programs on the raspberry: One always running, just to listen when some arduino sends info to the raspberry with his new position. And another one program to control the blinds movement from remote.
    Do you think that’s a good solution?? Maybe I could have some collission problems when both programs will be running?
    Thanks a lot for you help

    • April 15, 2014

      Hi Oscar,
      hopefully I’ve understood the problem, please correct me if I’m wrong.
      Since you are sending a message to the arduino, I suppose that the message is different when opening and closing the blinds.
      Said that, the arduino actually replies with the same message you’ve sent (ack package) when he receive the message correctly.
      Now, your raspberry know that your blind is being opened and can hold and manage this information. The same happen when you are closing the blinds. What you might to achieve is to have a “callback” when the blinds are effectively closed. Without creating two programs, you could use the same, given the fact the opening/closing the blinds will be eventually a locking command during all the time of the operations. Which means that when you are opening the blinds you can’t turn the lights on, for instance. This solution simply tell the raspberry to ping the arduinoBlinds every 5 seconds after you’ve pressed the action and send a message, like “What are you doing?” and he answers: 00) Closed .10)I was open and I’m closing .01) I was closed and I’m opening. 11) I’m open. When the raspberry receive the last command it will stop to ping.

      Let’ make an example.
      Raspberry knows that arduBlinds is 00 (Because of a ping or a previous known state saved, for instance, on a db). So Raspberry tells him “11″. Then Raspberry start to pings arduBlinds with “What are you doing?”. At first the arduBlinds will say “01″ for the time it is opening the blinds and then, when finished, it will say “11″. At this point Raspberry stop to ping.

      I don’t have libraries with me, but I suppose you have to switch mode from listening to sending.

      Let me know.

      • Oscar #
        April 15, 2014

        Thanks for your time, unfortunately I don’t explain myselfarruinó. nk I can write all the process between arduino and the raspberry. My problem is when I use the wall switch, not via the raspberry. Every blind has it’s own switch, connected to the arduino to avoid conflict between switch and online orders. So, if I act the switch, the arduino can send a message to the raspberry with the new blind position. But then I need to Have the raspberry always listening for a message from the arduino ? . and another program to operate the blinds ‘online’??. Thanks a lot again

  5. Mohit #
    April 10, 2014

    I’m connecting the transceiver to an Arduino Mega and it stops working … I connect it to the Uno and it works … any ideas ?

    • Mohit #
      April 10, 2014

      Ooops … turns out SPI connections on MEGA are different …

  6. Evan #
    March 31, 2014

    Hi,

    I’ve gotten to the point where I need to compile where I need to compile the application, but I get errors:

    pi@raspberrypi ~/RF24/librf24-rpi/librf24/examples $ sudo g++ -Wall -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -L../librf24/ -lrf24 switch.cpp -o switch
    switch.cpp:2:1: error: stray ‘\302’ in program
    switch.cpp:2:1: error: stray ‘\240’ in program
    switch.cpp:15:45: warning: extra tokens at end of #include directive [enabled by default]
    switch.cpp:15:46: fatal error: ~/RF24/librf24-rpi/librf24/RF24.h: No such file or directory
    compilation terminated.

    Any ideas? the “RF24.h” file is in the directory it says it is not.

    Thanks!

    • Mohit Athwani #
      March 31, 2014

      Hey Evan,

      Stray \302, \240 could be some issue with copy pasting code (not sure though)

      About the extra toke, get rid of the semi-colon “;” at the end of line 15 of your code …

      I put my code in the examples folder in the RF24 directory and it worked fine …

  7. March 30, 2014

    Hi! I know this is somewhat off topic but I was wondering if you knew where I could find
    a captcha plugin for my comment form? I’m using the
    same blog platform as yours and I’m having trouble finding
    one? Thanks a lot!

  8. March 16, 2014

    Awesome tutorial ! But sadly I cannot get it to work :(

    I’ve checked, double checked and triple checked the connections.

    Out put on my Arduino Uno is :


    Light Switch Arduino

    STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
    RX_ADDR_P0-1 = 0xf0f0f0f0e1 0xf0f0f0f0d2
    RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
    TX_ADDR = 0xf0f0f0f0e1
    RX_PW_P0-6 = 0x20 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

    And out put on my Pi is :

    Preparing interface
    SPI device = /dev/spidev0.0
    SPI speed = 8000000
    CE GPIO = 25
    STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
    RX_ADDR_P0-1 = 0xf0f0f0f0e1 0xf0f0f0f0d2
    RX_ADDR_P2-5 = 0xe2 0xe3 0xe4 0xe5
    TX_ADDR = 0xf0f0f0f0e1
    RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20
    EN_AA = 0x00
    EN_RXADDR = 0x3f
    RF_CH = 0x4c
    RF_SETUP = 0x07
    CONFIG = 0x0f
    DYNPD/FEATURE = 0x00 0x04
    Data Rate = 1MBPS
    Model = nRF24L01+
    CRC Length = 16 bits
    PA Power = PA_MAX

    Turn it ooooon!
    Now sending 1...ok...Failed, response timed out.
    Now sending 1...ok...Failed, response timed out.
    Now sending 1...ok...Failed, response timed out.
    Now sending 1...ok...Failed, response timed out.
    Now sending 1...ok...Failed, response timed out.

    Can’t figure out what’s going on …

    • March 17, 2014

      [UPDATE]
      Woke up today morning and tried it again, and guess what the 2 devices communicated.

      So I kept on playing with the on/off commands and noticed that communication is never 100% … can anybody comment on the success rate ?

      • March 22, 2014

        Hi Mohit!
        We are happy that you finally managed to make them communicate! We did have the same problems, which turned out it was just a matter of clean implementation and wiring.
        About the succes rate, we’ve found that turning on the light in the same room as the Raspy was almost instantaneous. Maybe you have some device which is generating some intereferences with your modules. Remember that the frequency is 2.4 Ghz, which is the same as wifi and microwave oven (and some other devices). Try to change channel frequency and, if you are brave enough, have a look at some antenna mods you find around for 2.4ghz (remember I’ve seen this module with an antenna mod too).
        Let us now how it goes!

  9. Ishu #
    March 14, 2014

    So, I have competed a complete working automation solution using same hardware … any advice as to how i should publish it. should i licence it or something .. I’m new to the field.

    • March 16, 2014

      Hey Ishu ,

      since you got it working, maybe you can help me out with my problem above ?

      Thanks,

      Mohit

  10. Mar #
    March 12, 2014

    Hi,
    thanks for this great project. I succeed with it. But I have one strange behaviour. I succeed to send the on (1) and off (2) to arduino from Raspberry Pi. But when the Raspberry Pi get back the response it never receive the same information. I would expect that when Raspberry Pi send “1″ to arduino then arduino send back again “1″. But I never get this back on Raspberry Pi. I always get some different strange number (0, 1678878, 245584 etc…) but never 1. I also tryed to send same static number from the Arduino to Pi but I never receive the correct number on Pi. Do you have any idea where could be the problem?

    Thanks.

  11. Hduque #
    March 2, 2014

    Hi

    I am no able to get it work yet. May be could be for this (like luke previous comment):

    pi@raspberrypi ~ $ sudo ldconfig -v | grep librf
    ldconfig: Path /lib/arm-linux-gnueabihf' given more than once
    ldconfig: Path
    /usr/lib/arm-linux-gnueabihf’ given more than once
    librf24.so.1 -> librf24.so.1.0

    Can you help me please? am i missing something?

    thanks in advance

    • March 2, 2014

      ldconfig is telling you he has already found other /lib/arm-linux-gnueabihf and /usr/lib/arm-linux-gnueabihf libraries link.
      Have you tried to move on the next step?

      • Hduque #
        March 2, 2014

        Hi

        Thanks for your quick response.

        Yes, i have moved to the next steps. I have test “sudo ./switch -f on” and i get “Failed, response timed out”.

        I have double check the connections, but it is ok. Maybe my problem is in the Arduino side (i have use Arduino uno). Right now, the Arduino sketch is showing a message when is compiled, it says “printf_begin was not declared in this scope”.

        I have run the scanner to, and it shows something like this:

        “000000000000000011111111111111112222222222222222333333333333333344444444444444445555555555555555666666666666666677777777
        0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef01234567
        000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000″

        I am really sure that i am doing something wrong, but i can`t figure what.

        If you can give me some tips i’ll really appreciate and i wil try to get it work.

        Thanks again.

        • March 3, 2014

          Have a double check at the wires first. We’ve exchanged pins so many times! We have a UNO around, so if you want we can have look. I don’t see the point why it should not work anyway. Keep in mind that we are planning a huge step up on this project in the next months. Plus, we have to work too :D So we’ll not have so much time to support all the requests of help we receive. Said that, since we would have really appreciated an help from someone who finally made it, we’ll reply as soon as we can, trying to keep everything updated.
          Have a nice day!

          • Hduque #
            March 3, 2014

            Ok.

            I will check again the wires and the pins, and i let you know how it goes.

            Thanks again for your replies.

          • Hduque #
            March 4, 2014

            Hi Guys

            Finally it’s working. Apparently the problem presented by the RF24 library was corrupt. I downloaded again and upload the sketch to the Arduino again, and it worked.

            About the printf_begin problem, what i did, was open the printf.h file in the arduino IDE, and the sketch at the same time. Upload the sketch and the message disappear.

            Thanks a lot for yur help.

  12. Ishu #
    March 2, 2014

    great project guys,
    i have tried it myself and am wondering if it possible to run “./switch -f on” through php execute function.
    Thank you in advance.
    keep up the good work.

    • March 2, 2014

      I think you can use it with exec(). Not sure though if you can run it with sudo.
      Have a nice day!

    • Mar #
      March 12, 2014

      Hi Ishu, I succeed to run the switch through PHP script using the exec() function and also .sh file in between the switch and PHP script. Part on which I spend the most of the time was correct rights of all the files and also the fact that I succeed only in case that www-data account has been set to work without password. PHP script then run the .sh file with one parameter which can be then passed to switch -f . When switch example is slightly modified then it can sand many kinds of commands to arduino. If more info neede let me know and I can add some more tips.

      Then I would also like to thanks for this great project.

  13. JuanMi #
    February 28, 2014

    Hi there!

    Thank you guys for this fine article! It helped me a lot! I am involved in a project concerning Arduino and RPi communication and I suceeded connecting both.

    The starting point was your example code which I modified to my needs. It worked at (just) the second try! :).

    Again, thank you for sharing,

    JuanMi

  14. Tom #
    February 27, 2014

    Hi. Great project, thx! I have done everything and now i can switch one relay from Pi :) I’m trying to add some line to turn on second relay on board but need some help. Could You guys give me some tips? How should Arduino Sketch and switch.cpp looks like? Thank You :)

    • February 28, 2014

      Holaaaa Tom!
      You need to pass a different message to arduino for each relay you want to switch.
      Let’s say “1″ is “turn on the R1 (relay 1)” and “3″ is “turn on the R2 (relay 2)”.
      Remember you need a message to turn them off too. So, you’ll define “0″ as a message to turn off R1, and “2″ to turn off R2.
      With this pattern you’ll have all couples, with a pair and an odd number. The pair switch off, the odd switch on.
      Like this:
      R1 | R2 | R3
      —————————
      0 – 1 | 2 – 3 | 3 – 4
      off-on | off-on | off-on

      We are working on something similar, but more “modular” on our side. More in the next week!

  15. luke #
    February 18, 2014

    hi *,

    maybe someone can help me. i dont get it. i suppose, that may this is the reason:

    pi@raspbmc ~$ sudo ldconfig -v | grep librf
    ldconfig: Path /lib/arm-linux-gnueabihf' given more than once
    ldconfig: Path
    /usr/lib/arm-linux-gnueabihf’ given more than once
    librf24.so.1 -> librf24.so.1.0

    i also checked “sudo modinfo i2c-dev”, witch results in “module i2c-dev not found”.

    any ideas?
    thnx & regards

  16. Camillo #
    February 10, 2014

    Hi, great tutorial and project!
    I am wondering if it is possible (and how!!!) to power the arduino part on a battery or coin cell and make it live for about an year or so.
    Thank you!
    Camillo

  17. kevingmgb #
    February 1, 2014

    Hey,

    I think this is a great project. I am working on a project that would send text from tweets from the pi to an arduino with an lcd screen using the nrf24l01. Every example I find out there for the pi is sending numeric information. I saw the serialchat example in the arduino and I am having a tough time replicating something similar to send a string across the radio. Anyway you could point me in the right direction?

    Thanks!

    • February 11, 2014

      I think you should try send strings directly. Unfortunately don’t have the time to try it.

  18. kg77 #
    January 26, 2014

    Hi,
    I’m begginer in this technology…
    Is the revision 2 of Raspberry Pi really importent? RPiV1 and V2 functions of used GPIO pins are the same.
    I’ve RPiV1. Everything (preparation, and compilation are OK) but unfortunaltelly I’ve problem after run:
    ./switch -f on
    Preparing interface
    Segmentation fault

    Do you think that it is because of Raspberry revision?

    Regards
    Chris

    • January 26, 2014

      Hi! I’m on my phone, but at first shot I think you are missing a sudo before the command. Using gpio requires sudoers privileges. Have a nice day.

      • kg77 #
        January 26, 2014

        Exactly. Now it’s OK. Thx :)

  19. January 9, 2014

    Its a wonderful project and has a huge potential, I am from India, I am working on the same kind of project. Your project is a great help to us, My question is can we use nRF24LE so that data sent can be encrypted and to avoid arduino nano. Thank you once again for the resources.

    • Lorenzo Farnararo #
      January 9, 2014

      I digged around and I found some material to work on. First of all I wuold use AES simmetric key to do the job. Here some reference to a library written for NRF24LE1.
      I don’t understand why the WiFi module alone… if you want to explain us you project or link something we would be grateful!

      • January 9, 2014

        I don’t understand why the WiFi module alone… if you want to explain us you project or link something we would be grateful!

        Indeed, I don’t understand neither :D . That module (the NRF24LE1) doesn’t seems to have a micro-processor you could use as an arduino’s one. Plus,I think that if you would use it for encryption it would be better to keep it separated from other calculus, which right now belongs to arduino.

        If we’ve misunderstood please correct us, since we are looking for an “encrypted” solution too.
        Have a nice day.

  20. November 10, 2013

    Hi, really cool project you have there!..

    ref:
    http://arduino-for-beginners.blogspot.com/2013/02/setup-nordic-nrf24l01-rf-modules-to.html?goback=%2Egde_1268377_member_217339050#%21

    I’ve been working with the same project for the past 2 months and got the rpi and the arduino uno talking to each other via the RF24 unit(s). I also managed to get some PHP + MySql codes working to turn the relay OFF @ ON respectively.

    But the only thing that halted my project is the RF24 security, which if i’m not mistaken, transfers the data forth and back in plain form. I thought that it would be ‘dangerous’ if someone could just send a forged packet and my arduino would blindly accept it. So I’ve been googling around for a library that could be used both in RPI & Arduino Uno to encrypt the packets with no luck.

    So does the RF24 unit has any security implementation inside that i can use?.

    Thanks again for sharing this.

    • Lorenzo Farnararo #
      November 10, 2013

      Hi Mr.F. I don’t think the little RF24 has the dedicated hardware which can provide encryption. You’ll have to do develop it software-side both on the Raspberry Pi (not a problem) and the arduino (can be a problem).
      Like you, I mind very much about security, but for this little test I didn’t bother too much actually. Do you have so much “nerd” neighbours???

      If you would like to build something interesting, I strongly suggest you a symmetrical key (like AES). I’ve looked around the internet and I’ve found some arduino’s libraries [on the Raspberry Pi you have Debian ;) ]:
      - http://forum.arduino.cc/index.php/topic,88890.0.html
      - https://github.com/DavyLandman/AESLib
      - http://www.expertcore.org/viewtopic.php?f=18&t=3772
      Give it a try, but keep in mind that encryption is such an heavy task for an arduino.
      Cheers

  21. October 26, 2013

    Hi. Is it possible to control several nodes with only one “hub” (Raspi)?

    • October 26, 2013

      Sure, you’ll need to set different wifi addresses. You can pass these addresses to the RF24 library.

      On the arduino you identify them on the sketch with this code:
      // Radio pipe addresses for the 2 nodes to communicate.
      const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

      on the raspberry application (.cpp) with:

      const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

      • Jose #
        October 28, 2013

        Great, thank you! And, is it possible to create a bi-directional link? I want to send commands from Raspi to Arduino and receive sensor data back.

        • October 28, 2013

          Actually it is a bidirectional communication. Indeed, we’ve made arduino reply with the same message he received, to check if communication worked, but you can make him respond whatever you need.
          On line 92 of Arduino sketch you can change
          radio.write( &message, sizeof(unsigned long) );

          to deliver anything you want.
          Have nice coding!

          • November 4, 2013

            Ciao!

            Ho acquistato questi moduli due mesi fa, poi li ho abbandonati per carenza di tempo e poca documentazione per ciò che mi serviva.

            Il mio progetto di impianto domotico è completo e volevo estenderlo in altre camere evitando di infilare cavi inutili in tutta casa, se ti interessa puoi cercare DomoHome su YouTube tanto per farti un’idea..
            Detto questo.. non ho ancora dato un’occhiata al source in js, ma probabilmente non farà altro che chiamare l’applicazione compilata in C a runtime, mi sbaglio?

            Il mio problema più grande è che il mio progetto è scritto interamente in python su Raspberry, e ci ho impiegato moltissimo tempo per scriverlo da zero, quindi doverlo riscrivere in C non saprei da dove partire.

            Ho tutto l’occorrente a disposizione, mi servirebbe giusto un consiglio sulla giusta pista da adottare..

          • November 4, 2013

            ENG
            Hi Angelo,
            we’ve seen your awesome project on youtube. The road we’ve taken is definitely more “wireless” :D
            Js instructions are interpreted by a binary file pre compiled written in C++. This binary interface itself with RF24 libraries written in C (If I remember well) which probably (almost surely) have a python sub layer.
            To be able to use those libraries you should unmount them or look for the pre porting version. From there, I think the rest is pretty easy.
            Next time could be better to write in english, so all the world can take advantage from your doubts and projects.
            Thank you again for you participation!

            ITA
            Ciao Angelo,
            abbiamo visto il tuo fantastico progetto su youtube. La strada che stiamo percorrendo noi e’ decisamente piu’ “wireless” :D
            Le istruzioni js vengono interpretate da un binario pre compilato scritto in C++. Questo binario si interfaccia con delle librerie per RF24 in C (se non sbaglio) che probabilmente (quasi sicuramente) hanno un sub layer in python.
            Per sfruttare queste librerie dovresti smontarle o cercare il pre porting. Da li’ penso che la strada sia abbastanza in discesa.
            La prossima volta sarebbe meglio tu scrivessi in inglese, in modo che tutto il mondo possa trarre vantaggio dai tuoi dubbi e dai tuoi progetti.
            Grazie ancora per la partecipazione!

          • November 4, 2013

            I found a wrapper written in python a month ago but it didn’t work due to different configurations. I’ve learnt that you need to set different params in order to let them communicate.

            Is there a way to talk to you directly and share some information to let this project work for a lot of people like me who codes in python?

          • November 9, 2013

            Sure, althought I have to tell you that I do not have so much free time (like you see). My email is edo “at” lenotta.com

          • November 16, 2013

            In these days I found the time to write down a wrapper to send data from Raspberry through nRF24L01. It’s simply to use, it accepts three parameters.. the sender address, the receiver address and the message coded in long long unsigned int.

            Thanks to this wrapper the only thing you have to do is to configure the receiver, in my case an Arduino Uno, in order to understand your messages.

  22. October 6, 2013

    Cool project! I’ve been working on something like this for my desktop computer. By any chance, do you know what the current draw of the Raspberry Pi is when it’s idle waiting for a command?

Leave a Reply

Basic HTML is allowed. Your email address will not be published.

Subscribe to this comment feed via RSS