Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Hardware
  3. Step-by-step procedure to connect the NRF24L01+ to the GPIO pins and use the Raspberry as a Serial Gateway (MySensors 1.x)

Step-by-step procedure to connect the NRF24L01+ to the GPIO pins and use the Raspberry as a Serial Gateway (MySensors 1.x)

Scheduled Pinned Locked Moved Hardware
nrf24raspberry piraspberryraspberry nrf24l01 gpiogateway
168 Posts 47 Posters 175.0k Views 36 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • GertSandersG Offline
    GertSandersG Offline
    GertSanders
    Hardware Contributor
    wrote on last edited by GertSanders
    #39

    You can "fake" a later version (e.g, 1.5) on the Raspberry by changing the version code in the version.h file and recompiling the Gateway software.

    As far as I understand, the gateway will still pass the messages to the controller, even is there is a version mismatch message on the console.

    1 Reply Last reply
    0
    • alexsh1A alexsh1

      @den2k said:

      Hi all,
      I'm following this thread and have upgraded to MySensors v1.5 and get the following error. Version mismatch.

      It looks like the Protocol version is 1.4.

      Does the Raspberry MySensors Gateway support v1.5 or only v1.4? Any ideas on how to fix?

      Up until now, MySensors v1.4 only for nrf24l01+ direct connection.
      Did you upgrade the GW or the sensors or both ?

      D Offline
      D Offline
      den2k
      wrote on last edited by
      #40

      @alexsh1 I know the sensors are on v1.5. As for the Raspberry Gateway, it looks like based on the info here, that is running v1.4.

      1 Reply Last reply
      0
      • hekH hek

        Protocol version hasn't changed since 1.4
        https://github.com/mysensors/Raspberry/blob/master/MyMessage.h#L41

        So you must have some other problem.. As you can see you only get zeroes in the log...

        D Offline
        D Offline
        den2k
        wrote on last edited by
        #41

        @hek I'm running a custom 1Mhz build bootloader on a Pro Mini for the Sensor side. This was paired with the standard Serial Gateway running on another Pro Mini with v1.5 on both gateway and sensor. That setup was working. But I moved over to using the Pi gatway+nRF24+ radio and have this issue. I don't believe the hookup is the problem. I've seen the 0 readings before, and that usually meant node side issue or uninitiated Gateway. I have not changed the Node, so it must be the Pi gateway that is the problem. Any thoughts on what to test?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          den2k
          wrote on last edited by
          #42

          Noob question. Any one have an idea on solving the "Permission denied" error.

          upload-a7ed9c85-5b6b-4198-af00-909e1861374e

          1 Reply Last reply
          0
          • D Offline
            D Offline
            den2k
            wrote on last edited by
            #43

            Solved my own problem. Using the following command did the trick.

            sudo chown -h pi:pi ttyUSB20

            1 Reply Last reply
            0
            • D Offline
              D Offline
              den2k
              wrote on last edited by
              #44

              weird. Permission Denied problem again.

              What is the USER : GROUP that is needed for this to work?

              martinhjelmareM 1 Reply Last reply
              0
              • mfalkviddM Offline
                mfalkviddM Offline
                mfalkvidd
                Mod
                wrote on last edited by
                #45

                @den2k I think your best chance is to post in the Home Assistant category. I don't have any experience with Home Assistant unfortunately.

                1 Reply Last reply
                0
                • J jpbabou

                  Hi
                  something is missing..

                  Is there a problem with the repository
                  Tks a lot for your job!

                  pi@domoticjp ~ $ sudo git clone https://github.com/mysensors/Raspberry.git
                  Cloning into 'Raspberry'...
                  remote: Counting objects: 273, done.
                  remote: Compressing objects: 100% (3/3), done.
                  remote: Total 273 (delta 0), reused 0 (delta 0), pack-reused 270
                  Receiving objects: 100% (273/273), 215.00 KiB | 0 bytes/s, done.
                  Resolving deltas: 100% (114/114), done.
                  Checking connectivity... done.
                  pi@domoticjp ~ $ cd Raspberry/librf24-bcm
                  -bash: cd: Raspberry/librf24-bcm: No such file or directory
                  mfalkviddM Offline
                  mfalkviddM Offline
                  mfalkvidd
                  Mod
                  wrote on last edited by
                  #46

                  @jpbabou said:

                  Hi
                  something is missing..

                  Is there a problem with the repository
                  Tks a lot for your job!

                  pi@domoticjp ~ $ sudo git clone https://github.com/mysensors/Raspberry.git
                  Cloning into 'Raspberry'...
                  remote: Counting objects: 273, done.
                  remote: Compressing objects: 100% (3/3), done.
                  remote: Total 273 (delta 0), reused 0 (delta 0), pack-reused 270
                  Receiving objects: 100% (273/273), 215.00 KiB | 0 bytes/s, done.
                  Resolving deltas: 100% (114/114), done.
                  Checking connectivity... done.
                  pi@domoticjp ~ $ cd Raspberry/librf24-bcm
                  -bash: cd: Raspberry/librf24-bcm: No such file or directory
                  

                  The guide has been updated to reflect the updated in the MySensors Raspberry repository now. Thanks @jpbabou !

                  1 Reply Last reply
                  0
                  • D den2k

                    weird. Permission Denied problem again.

                    What is the USER : GROUP that is needed for this to work?

                    martinhjelmareM Offline
                    martinhjelmareM Offline
                    martinhjelmare
                    Plugin Developer
                    wrote on last edited by martinhjelmare
                    #47

                    @den2k

                    Hi!

                    Have you added the user that runs homeassistant to the dialout group? This group is usually owner of serial ports.

                    Check default group of serial port (change for your port below) after connecting it:

                    pi@martin-pi:~ $ ls -l /dev/ttyUSB0 
                    crw-rw---- 1 root dialout 188, 0 dec 18 03:21 /dev/ttyUSB0
                    

                    Check groups that user pi is in:

                    pi@martin-pi:~ $ groups pi
                    pi : pi adm dialout cdrom sudo audio video plugdev games users input netdev spi i2c gpio
                    

                    If pi runs homeassistant, which should be the case, and is not in dialout, add pi to dialout:

                    sudo adduser pi dialout
                    

                    Changing owner of a port will only work until you disconnect it. Default owner will be restored upon reconnect, if you haven't written a special udev rule.

                    Edit:
                    According to the readme in the mysensors raspberry repo (https://github.com/mysensors/Raspberry), the group of the device is tty. So you should probably use that, and not dialout. But you will know, when you check with ls -l.

                    1 Reply Last reply
                    1
                    • mfalkviddM mfalkvidd

                      Note: This guide is only applicable to MySensors 1.x. For MySensors 2, use this guide.

                      I noticed that a step-by-step procedure to connect the NRF24L01 to the GPIO pins and use the Raspberry as a Serial Gateway was listed in the document for MySensors 1.6.

                      Since I have three gateways configured this way, and I need to set up 3 more for covering different offices around the world, and I had already written the instructions in Swedish for Datormagazin, I thought I'd help out.

                      This is the first draft. Any feedback is welcome.


                      INTRODUCTION
                      The radio module NRF24L01+ is cheap and power efficient, but it is unable to communicate with regular wifi. The bridge between NRF24L01+ nodes and the "computer world" is called a Gateway. You can use other types of gateways, but connecting the NRF24L01+ module directly to the Raspberry Pi is a simple and cheap alternative.

                      Wiring Things Up
                      Connect the NRF20L01+ radio module to the Raspberry Pi like this:
                      raspi_mysensors[1].png

                      Raspberry Pi NRF24L01+ Color
                      6 / GND GND Black
                      1 / 3.3V DC VCC Red
                      22 / GPIO25 CE Orange
                      24 / GPIO 8 CSN/CS Yellow
                      23 / GPIO11 / SPI_CLK SCK Green
                      19 / GPIO10 / SPI_MOSI MOSI Blue
                      21 / GPIO9 / SPI_MISO MISO Violet

                      The IRQ pin on NRF24L01 is not currently used.

                      For a comprehensive view of the Raspberry Pi pins, see http://pinout.xyz/

                      You should also connect a decoupling capacitor to the radio. See this guide.

                      COMPILING THE GATEWAY
                      Login to your Raspberry Pi (using SSH or open a terminal on the graphical console) and run these commands:

                      git clone https://github.com/TMRh20/RF24.git
                      cd RF24
                      make all && sudo make install
                      cd ..
                      
                      git clone https://github.com/mysensors/Raspberry.git
                      cd Raspberry
                      make all && sudo make install
                      

                      If you get the following error:

                      pi@raspberrypi ~/RF24 $ make all && sudo make install
                      g++ -Wall -fPIC -Ofast -mfpu=vfp -mfloat-abi=hard -mtune=arm1176jzf-s -march=armv7-a -D BCM2835_PERI_BASE=0x -c RF24.cpp
                      gcc -Wall -fPIC -Ofast -mfpu=vfp -mfloat-abi=hard -mtune=arm1176jzf-s -march=armv7-a -D BCM2835_PERI_BASE=0x -c bcm2835.c
                      bcm2835.c: In function ‘bcm2835_init’:
                      bcm2835.c:1207:28: error: invalid suffix "x" on integer constant
                      
                      

                      You've probably run into the problem discussed in this thread. People have had luck with different solutions. The simplest is to make the following change to ~/Raspberry/librf24-bcm/Makefile

                      #IOBASE := $(shell cat /proc/iomem | grep bcm2708_vcio | cut -f 1 -d "-")
                      IOBASE := 3F000000
                      

                      VERIFY THE GATEWAY
                      Run sudo /usr/local/sbin/PiGatewaySerial. The output should look like this:

                      pi@raspberrypi ~/Raspberry $ sudo /usr/local/sbin/PiGatewaySerial
                      Starting PiGatewaySerial...
                      Protocol version - 1.4
                      Created PTY '/dev/pts/1'
                      Gateway tty: /dev/ttyMySensorsGateway
                      ================ SPI Configuration ================
                      CSN Pin          = CE0 (PI Hardware Driven)
                      CE Pin           = Custom GPIO25
                      Clock Speed      = 8 Mhz
                      ================ NRF Configuration ================
                      STATUS           = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
                      RX_ADDR_P0-1     = 0xe7e7e7e7e7 0xc2c2c2c2c2
                      RX_ADDR_P2-5     = 0xff 0xc4 0xc5 0xc6
                      TX_ADDR          = 0xe7e7e7e7e7
                      RX_PW_P0-6       = 0x00 0x00 0x20 0x00 0x00 0x00
                      EN_AA            = 0x3b
                      EN_RXADDR        = 0x07
                      RF_CH            = 0x4c
                      RF_SETUP         = 0x23
                      CONFIG           = 0x0e
                      DYNPD/FEATURE    = 0x3f 0x06
                      Data Rate        = 250KBPS
                      Model            = nRF24L01+
                      CRC Length       = 16 bits
                      PA Power         = PA_LOW
                      

                      If the NRF24L01+ isn't correctly wired, the following error will be shown

                      pi@raspberrypi ~ $ sudo /usr/local/sbin/PiGatewaySerial
                      Starting PiGatewaySerial...
                      Protocol version - 1.4
                      Created PTY '/dev/pts/2'
                      Gateway tty: /dev/ttyMySensorsGateway
                      check wires
                      

                      If this happens, double-check your wiring and correct any problems. Press Ctrl+Z and type

                      sudo killall PiGatewaySerial
                      

                      to get rid of the non-functioning Gateway. Then run sudo /usr/local/sbin/PiGatewaySerial again

                      If all is well, exit PiGatewaySerial by pressing Ctrl+C. Then run

                      sudo /etc/init.d/PiGatewaySerial start
                      

                      to start the gateway as a background process. Verify that it started correctly by running

                      sudo cat /dev/ttyMySensorsGateway
                      

                      You should see the message "Gateway startup complete". Exit by typing Ctrl+C.

                      MAKE THE GATEWAY AUTOSTART
                      To make sure the Gateway is started when your Raspberry Pi boots up, run the following command:

                      sudo make enable-gwserial
                      

                      Enable the gateway for use with Domoticz
                      Domoticz (and maybe other home automation systems) has trouble reading from the default path created by PiGatewaySerial. You might need to run the following command:

                      sudo ln -s /dev/ttyMySensorsGateway /dev/ttyUSB20
                      

                      And change /etc/rc.local from this

                      exit 0
                      
                      

                      to this

                      ln -s /dev/ttyMySensorsGateway /dev/ttyUSB20
                      exit 0
                      
                      

                      OTHER NOTES

                      • The 3.3V power on the Raspberry Pi is rated for a maximum of 50mA. A regular NRF24L01+ only needs 15mA, but if you are using a power amplified version you might exceed what the Raspberry Pi can output. In that case, an external power supply might be required. If you use an external power source gnd must be connected to the Raspberry Pi's gnd.

                      • Connecting the NRF24L01+ directly to your Raspberry Pi will prevent you from using the Raspberry Pi's gpio ports for other things, like a Z-wave board.

                      • A user experienced slow data transfer compared to USB-to-Serial(ttl)<-->MySensors Gateway connection, especially on OTA firmware update. If you think this will cause a problem for you, an ethernet gateway might be a better alternative.

                      As always, I stand on the shoulders of giants. Related posts:

                      • http://forum.mysensors.org/topic/1151/tutorial-raspberry-pi-nrf24l01-direct-connection
                      • http://forum.mysensors.org/topic/1974/domoticz-as-controller-and-a-gateway-for-mysensor-nodes-running-on-a-raspberry-pi-2

                      TROUBLESHOOTING
                      If you get this error

                      pi@Domoticz3:~/Raspberry$ sudo /etc/init.d/PiGatewaySerial start
                      [....] Starting PiGatewaySerial (via systemctl): PiGatewaySerial.serviceFailed to start PiGatewaySerial.service: Unit PiGatewaySerial.service failed to load: No such file or directory.
                       failed!
                      

                      or this error

                      pi@raspberrypi ~ $ sudo /usr/local/sbin/PiGatewaySerial
                      sudo: /usr/local/sbin/PiGatewaySerial: command not found
                      

                      you have probably forgotten to run sudo make install. Read the instructions again, and follow them this time :-) User @sineverba reported that a reboot of the Pi after running make install helped.

                      S Offline
                      S Offline
                      Scala
                      wrote on last edited by
                      #48

                      @mfalkvidd Hi there and thanks for a great and super detailed step-by-step tutorial.

                      I've got mine running in no time with your instructions, but after a couple of minutes I've got the following error:

                      2015-12-30 20:51:30.356 Error: MySensors: Unhandled sensor (sub-type=32), please report with log!
                      2015-12-30 20:52:01.390 Error: Serial Port closed!... Error: End of file
                      2015-12-30 20:52:02.315 MySensors: retrying in 30 seconds...
                      2015-12-30 20:52:31.319 MySensors: Using serial port: /dev/ttyUSB20
                      2015-12-30 20:52:31.320 Error: MySensors: Error opening serial port!
                      2015-12-30 20:52:32.321 MySensors: retrying in 30 seconds...
                      2015-12-30 20:53:01.324 MySensors: Using serial port: /dev/ttyUSB20

                      I also attached a partial screen capture showing that it was working before 8-)

                      2015-12-30 21_18_13-Domoticz - Opera.png

                      Any idea on why is this happening and how to solve it?

                      Southern regards and happy new year to all!

                      ronnyandreR 1 Reply Last reply
                      0
                      • mfalkviddM Offline
                        mfalkviddM Offline
                        mfalkvidd
                        Mod
                        wrote on last edited by
                        #49

                        You are using a sensor type that your version of Domoticz doesn't support. What type os sensor is it? Which version of Domoticz are you using? Upgrading Domoticz might solve the problem (if the newer version supports this sub-type).

                        1 Reply Last reply
                        0
                        • Sander TeunissenS Offline
                          Sander TeunissenS Offline
                          Sander Teunissen
                          wrote on last edited by
                          #50

                          When I try to run the init.d script:

                          sudo /etc/init.d/PiGatewaySerial start
                          

                          I get the following error:

                          [....] Starting PiGatewaySerial (via systemctl): PiGatewaySerial.serviceFailed to start PiGatewaySerial.service: Unit PiGatewaySerial.service failed to load: No such file or directory.
                           failed!
                          

                          No such file or directory.... Obviously a missing folder or file, but I am not savvy enough to debug this.... Any help appreciated..

                          mfalkviddM 1 Reply Last reply
                          0
                          • Sander TeunissenS Sander Teunissen

                            When I try to run the init.d script:

                            sudo /etc/init.d/PiGatewaySerial start
                            

                            I get the following error:

                            [....] Starting PiGatewaySerial (via systemctl): PiGatewaySerial.serviceFailed to start PiGatewaySerial.service: Unit PiGatewaySerial.service failed to load: No such file or directory.
                             failed!
                            

                            No such file or directory.... Obviously a missing folder or file, but I am not savvy enough to debug this.... Any help appreciated..

                            mfalkviddM Offline
                            mfalkviddM Offline
                            mfalkvidd
                            Mod
                            wrote on last edited by
                            #51

                            @Sander-Teunissen my guess is that you forgot the sudo make install part of the installation instructions.

                            1 Reply Last reply
                            0
                            • Sander TeunissenS Offline
                              Sander TeunissenS Offline
                              Sander Teunissen
                              wrote on last edited by
                              #52

                              @mfalkvidd Yesterday I stopped trying and shutdown the Pi. This morning I tried the same again and it works !!
                              Pretty sure I haven't done anything else.
                              Thanks anyway.

                              Sander

                              1 Reply Last reply
                              1
                              • MrRikkieM Offline
                                MrRikkieM Offline
                                MrRikkie
                                wrote on last edited by MrRikkie
                                #53

                                Hello, If followed the instruction and everything seemed to work without any problem.
                                However when I enter the command : sudo cat /dev/ttyMySensorsGateway
                                I get the message : cat: /dev/ttyMySensorsGateway: No such file or directory
                                Does anybody have any idea how to solve this ?

                                mfalkviddM ronnyandreR 2 Replies Last reply
                                0
                                • MrRikkieM MrRikkie

                                  Hello, If followed the instruction and everything seemed to work without any problem.
                                  However when I enter the command : sudo cat /dev/ttyMySensorsGateway
                                  I get the message : cat: /dev/ttyMySensorsGateway: No such file or directory
                                  Does anybody have any idea how to solve this ?

                                  mfalkviddM Offline
                                  mfalkviddM Offline
                                  mfalkvidd
                                  Mod
                                  wrote on last edited by
                                  #54

                                  @MrRikkie what output did you get when you ran sudo /etc/init.d/PiGatewaySerial start ?

                                  1 Reply Last reply
                                  0
                                  • MrRikkieM Offline
                                    MrRikkieM Offline
                                    MrRikkie
                                    wrote on last edited by
                                    #55

                                    @mfalkvidd said:

                                    sudo /etc/init.d/PiGatewaySerial start

                                    No output and no error message. Just a new command line.
                                    pi@raspberrypi ~ $ sudo /etc/init.d/PiGatewaySerial start
                                    pi@raspberrypi ~ $

                                    1 Reply Last reply
                                    0
                                    • Sander TeunissenS Offline
                                      Sander TeunissenS Offline
                                      Sander Teunissen
                                      wrote on last edited by
                                      #56

                                      When I

                                      ls -l ttyMySensorsGateway
                                      

                                      I get

                                      lrwxrwxrwx 1 root root 10 Jan  3 20:21 ttyMySensorsGateway -> /dev/pts/0
                                      

                                      It's all root. This results in all kinds of acessability issues. I followed all instructions exactly. Anyone any ideas how to change this ?

                                      Sander.

                                      martinhjelmareM mfalkviddM 2 Replies Last reply
                                      0
                                      • Sander TeunissenS Sander Teunissen

                                        When I

                                        ls -l ttyMySensorsGateway
                                        

                                        I get

                                        lrwxrwxrwx 1 root root 10 Jan  3 20:21 ttyMySensorsGateway -> /dev/pts/0
                                        

                                        It's all root. This results in all kinds of acessability issues. I followed all instructions exactly. Anyone any ideas how to change this ?

                                        Sander.

                                        martinhjelmareM Offline
                                        martinhjelmareM Offline
                                        martinhjelmare
                                        Plugin Developer
                                        wrote on last edited by
                                        #57

                                        @Sander-Teunissen

                                        Try writing a udev rule to set owner of the device (ttyMysensorsGateway) at boot. If you don't need to use the link you could write a rule that names the pts device to the same name every boot, I think. At least for usb devices this works. Haven't tried it in this particular case.

                                        1 Reply Last reply
                                        0
                                        • Sander TeunissenS Sander Teunissen

                                          When I

                                          ls -l ttyMySensorsGateway
                                          

                                          I get

                                          lrwxrwxrwx 1 root root 10 Jan  3 20:21 ttyMySensorsGateway -> /dev/pts/0
                                          

                                          It's all root. This results in all kinds of acessability issues. I followed all instructions exactly. Anyone any ideas how to change this ?

                                          Sander.

                                          mfalkviddM Offline
                                          mfalkviddM Offline
                                          mfalkvidd
                                          Mod
                                          wrote on last edited by
                                          #58

                                          @Sander-Teunissen said:

                                          When I

                                          ls -l ttyMySensorsGateway
                                          

                                          I get

                                          lrwxrwxrwx 1 root root 10 Jan  3 20:21 ttyMySensorsGateway -> /dev/pts/0
                                          

                                          It's all root. This results in all kinds of acessability issues. I followed all instructions exactly. Anyone any ideas how to change this ?

                                          The permissions for a soft link are not used (and if they were, any user would be allowed to do anything since everything is rwx). The permissions for the target is used instead. So it is the result of

                                          ls -l /dev/pts/0
                                          

                                          you need to worry about.

                                          1 Reply Last reply
                                          1
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          16

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular