Integrating NRF24 to Raspberry Pi



  • Hi,

    I am trying to integrate NRF24 directly to Raspberry Pi through GPIO pins. A week ago I managed to integrate NRF24 with ESP8266 gateway; but my plan is to set this system to a caravan. So, power consumption (even a few miliwatts) and simplicity is important for me.

    First, I connected NRF24 to Raspberry pi. I use capacitor, and also 5V to 3.3V AMS1117 based voltage regulator. I get power directly from the voltage regulator that powers raspberry pi. So, voltage and power side of my setup is solid.

    I used master branch for My sensors setup.

    My Configure command is:
    ./configure --my-gateway=serial --my-serial-port=/dev/ttyAMA0 --my-serial-baudrate=115200 --my-transport=rf24

    With this setup when I test it, I get an error:

    Nov 07 14:49:08 INFO Starting gateway...
    Nov 07 14:49:08 INFO Protocol version - 2.3.2
    Nov 07 14:49:08 DEBUG Serial port /dev/ttyAMA0 (115200 baud) created
    Nov 07 14:49:08 DEBUG MCO:BGN:INIT GW,CP=RNNGL---,FQ=NA,REL=255,VER=2.3.2
    Nov 07 14:49:08 DEBUG TSF:LRT:OK
    Nov 07 14:49:08 DEBUG TSM:INIT
    Nov 07 14:49:08 DEBUG TSF:WUR:MS=0
    Nov 07 14:49:08 DEBUG TSM:INIT:TSP OK
    Nov 07 14:49:08 DEBUG TSM:INIT:GW MODE
    Nov 07 14:49:08 DEBUG TSM:READY:ID=0,PAR=0,DIS=0
    Nov 07 14:49:08 DEBUG MCO:REG:NOT NEEDED
    Nov 07 14:49:08 DEBUG MCO:BGN:STP
    Nov 07 14:49:08 DEBUG MCO:BGN:INIT OK,TSP=1
    Nov 07 14:49:08 ERROR Failed to get byte count on serial.

    As I understand Raspberry can communicate with NRF24. But I could not figure out what is the problem. Any ideas?



  • @huseyinozsut For serial you need.....

    --my-gateway=serial --my-serial-is-pty --my-serial-port=/dev/ttyMySensorsGateway

    Be warned that some pi models have issues with the serial ports (I had problems with this for months) as the hardware serial controller of early models was re-allocated to the wifi on wifi models and a software serial port was implemented instead. This gave me a lot of issues.



  • Thank you for reply! I couldn't solve the problem. I am using Raspberry 4 4gb by the way. I tried the configuration you provided also. Nothing has changed. I tried different modules. Again, nothing changed. I know that modules are working. I tested them with arduinos.

    After some tests, I also found out that, relay actuator with button node sketch does not work without nrf24 connection. This is a big problem for me. This means, if my Raspberry is closed, I will not be able to control the lights with switches. There is a possibility that I can't modify the sketch to make the switches work without wireless connection (when I switch on, the lights will turn on, even if the wireless is not connected). My programming skills are pretty bad.

    So, I tried to use an arduino with serial gateway sketch uploaded in to it. This way nodes connects to gateway and even if raspberry is closed, switch works!

    I plugged the arduino to Raspberry with USB. And tried several configurations. None of them was successful. If you know the serial gateway configuration, can you tell me? I made several searches here but could not make it work. I tried /dev/ttyUSB0 and several other possible options. What would be the configuration script?



  • @huseyinozsut said in Integrating NRF24 to Raspberry Pi:

    Thank you for reply! I couldn't solve the problem.

    I know, I went throught the same thing!.

    After some tests, I also found out that, relay actuator with button node sketch does not work without nrf24 connection.

    This is surprising, can you post a link to the relay sketch better your actual code here (using code tags)?

    So, I tried to use an arduino with serial gateway sketch uploaded in to it. This way nodes connects to gateway and even if raspberry is closed, switch works!

    Yes, this is also something I did. At least we have independently found the same issue with different hardware, cables, power supply etc. This makes it much more likely that the issue is global in nature.

    I plugged the arduino to Raspberry with USB. And tried several configurations. None of them was successful. If you know the serial gateway configuration, can you tell me? I made several searches here but could not make it work. I tried /dev/ttyUSB0 and several other possible options. What would be the configuration script?

    There is no configuration script for nrf attached to arduino.

    If I were you I would wipe the memory card of the pi and reinstall all fresh.
    Make sure to erase the eeprom on the arduino using the clear eeprom sketch in mysensors library, not the other one that comes with arduino. Also, when you reload the gateway sketch be sure to turn off debug as that sends stuff down the serial port and will corrupt everything ....

    Then get something like this.....

    https://www.aliexpress.com/item/32841439613.html?algo_pvid=83bf1900-7645-4241-aa5f-00f9b728be34&algo_expid=83bf1900-7645-4241-aa5f-00f9b728be34-21&btsid=2100bdd016049153938173468eaad1&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_

    Plug it in and dev/ttyUSB0 should work. It is the path I took and it works.



  • @skywatch Perhaps I'm not understanding the problem of using a serial gateway for radio other an additional component such as a pro-mini?
    Here the Pi3 Controller and Arduino 3v3 Gateway/radio are adjacent and direct wired on serial and power/ground to the pins.
    From vague memory the default configuration on the Pi had to be swapped for wifi, found relatively simply instructed on the internet.



  • @huseyinozsut said in Integrating NRF24 to Raspberry Pi:

    This means, if my Raspberry is closed, I will not be able to control the lights with switches. There is a possibility that I can't modify the sketch to make the switches work without wireless connection (when I switch on, the lights will turn on, even if the wireless is not connected)

    When booting, the node will try to connect to the gateway. If there's no gateway, the node will try forever, except you configure

    #define MY_TRANSPORT_WAIT_READY_MS 1000
    

    in your node. This tells the node to try max 1 sec and then continue to start, even without gateway connection.

    Regarding the raspberry pi issue, why don't you build an ethernet gateway? It would open port 5003 on your raspi and your controller could connect to this port.



  • @skywatch said in Integrating NRF24 to Raspberry Pi:

    @huseyinozsut said in Integrating NRF24 to Raspberry Pi:

    Thank you for reply! I couldn't solve the problem.

    I know, I went throught the same thing!.

    After some tests, I also found out that, relay actuator with button node sketch does not work without nrf24 connection.

    This is surprising, can you post a link to the relay sketch better your actual code here (using code tags)?

    frits explained the solution to the problem. I am a begginner and my technical English is a bit weak, so my research capacity for this project is a bit low. Sorry.

    So, I tried to use an arduino with serial gateway sketch uploaded in to it. This way nodes connects to gateway and even if raspberry is closed, switch works!

    Yes, this is also something I did. At least we have independently found the same issue with different hardware, cables, power supply etc. This makes it much more likely that the issue is global in nature.

    I plugged the arduino to Raspberry with USB. And tried several configurations. None of them was successful. If you know the serial gateway configuration, can you tell me? I made several searches here but could not make it work. I tried /dev/ttyUSB0 and several other possible options. What would be the configuration script?

    There is no configuration script for nrf attached to arduino.

    If I were you I would wipe the memory card of the pi and reinstall all fresh.

    I did this. Nothing changed. By the way I was using rasberry pi os + home assistant supervised, because I use ssd, not sd card. I found out that Version 5 series of HASS OS (beta version) supports SSD boot. So I used that. But again, no luck. It could not pass the boot screen. But 64 bit version worked. As I understand, in 64 bit version there is no GPIO support. So I ditched the plan for directly using NRF24l01 on Raspberry Pi through GPIO out. I will stick to wifi gateway or ethernet gateway. I will test ethernet gateway also, and check whether it consumes less or more power than wireless gateway.

    Make sure to erase the eeprom on the arduino using the clear eeprom sketch in mysensors library, not the other one that comes with arduino. Also, when you reload the gateway sketch be sure to turn off debug as that sends stuff down the serial port and will corrupt everything ....

    Then get something like this.....

    https://www.aliexpress.com/item/32841439613.html?algo_pvid=83bf1900-7645-4241-aa5f-00f9b728be34&algo_expid=83bf1900-7645-4241-aa5f-00f9b728be34-21&btsid=2100bdd016049153938173468eaad1&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_

    Plug it in and dev/ttyUSB0 should work. It is the path I took and it works.

    I will definately try this also. Thank you!



  • @frits Thank you very much for this explanation! This made my day!



  • There is one thing that I am thinking. I don't know wether it is possible or not.

    I know that using password for NRF24 communication is possible. But, the password should be embedded to the sketch of the node also.

    Lets say there is a on off switch on one of the pins of our gateway. When I switch it, it will bypass the password and send the password to all of the nodes, and nodes will save and use that password after that point. Then I will close that switch back, so gateway will stop sending the password to the nodes. By this way, embedding the password into each nodes' sketch will not be needed; but the nodes will be under password protection.

    The aim is simple actually: I will use this system in a few caravans (my uncles' rental caravans), which are more than 500 miles away from me. If a node goes bad, an electrician should be able to change the node without a need for uploading a sketch. This would reduce my workload in the future (especially if you think that I'm doing this for free, hahahahaha!). And will be low to moderately safe (hacking wise). Which is more than enough I guess...

    What do you say? Is it possible?



  • you say "When I switch it, it will bypass the password and send the password to all of the nodes, and nodes will save and use that password after that point."
    So everybody (who knows the design) could send new passwords to your nodes, couldn't they?

    Anyway, I don't think it is possible to modify MY_SIGNING_SIMPLE_PASSWD during runtime, because it is part of the program and not stored in EEPROM, have a look into MySigningAtsha204Soft.cpp:

    #ifdef MY_SIGNING_SIMPLE_PASSWD
    	if (strnlen(MY_SIGNING_SIMPLE_PASSWD, 32) < 8) {
    		SIGN_DEBUG(PSTR("!SGN:BND:PWD<8\n")); //Password is too short to be acceptable
    		_signing_init_ok = false;
    	} else {
    		(void)memset((void *)_signing_hmac_key, 0x00, sizeof(_signing_hmac_key));
    		(void)memcpy((void *)_signing_hmac_key, MY_SIGNING_SIMPLE_PASSWD, strnlen(MY_SIGNING_SIMPLE_PASSWD,
    		             32));
    
    


  • @huseyinozsut I think the nearest you can get to this will probably be FOTA.

    This way you can connect to the controller via internet and upload new firmware to a node with the new password included.

    Note that encryption might be desireable to stop people sniffing the data as it passes over the air.


Log in to reply
 

Suggested Topics

  • 3
  • 2
  • 10
  • 24
  • 1
  • 3

1
Online

11.2k
Users

11.1k
Topics

112.5k
Posts