multiple nrf24 sending data to one master

Posted on
  • Could one espruino with a nrf24 be used to receive sensor data from many other espruinos with nrf24…? Or is this a 1:1 setup always?

  • Yes - that's absolutely fine... You can reconfigure the TX address of the 'receiver' on demand, so you can actually send to multiple NRF24s from one as well.

  • Hi,
    I try to setup multiple connection, set the pipe2 address on master as

     >nrf.setRXAddr([0,0,0,0,3],2)
    =undefined 
    

    but it answers

     >nrf.getAddr(0x0C)
    =[0,0,0,0,0]
    

    and

    >nrf.setRXAddr([3,0,0,0,0],2)
    =undefined
    >nrf.getAddr(0x0C)
    =[3,3,3,3,3]
    

    why it set 3,3,3,3,3 instead of 0,0,0,0,3 ?
    ewerithing is ok with pipe 1 at the same time...

     >nrf.setRXAddr([0,0,0,0,2],1)
    =undefined
    >nrf.getAddr(0x0B)
    =[0,0,0,0,2]
    

    what can be wrong?

  • Hi Andrey,

    The nrf24 uses all 5 bytes of address for only the first 2 addresses. After that, it uses just the first byte and then the last 4 bytes of address #1. getAddr is just reporting the same first byte over and over.

    So:

    nrf.setRXAddr([6,7,8,9,0],1)
    nrf.setRXAddr([1,2,3,4,5],2)
    

    Means that address 2 is actually 1,7,8,9,0. I guess I should update the driver to produce warnings and the correct addresses.

    Hope that helps!

  • Thanks, Gordon,
    but I'm affraid on my f3discovery board it isn't.

    =undefined
    >nrf.getAddr(0x0A)
    =[0,0,0,0,1]
    >nrf.getAddr(0x0B)
    =[0,0,0,0,2]
    >nrf.setRXAddr([5,0,0,0,0],2)
    =undefined
    >nrf.getAddr(0x0C)
    =[5,5,5,5,5]
    
  • That's the point though. While it may report 5,5,5,5,5, the address it uses will actually be 5,0,0,0,2. Check the NRF24 datasheets for more info on it.

  • In case anyone wants it, here is my code for multiple TX with one RX:

    RX:

    SPI1.setup({sck:A5, miso:A6, mosi:A7});
    
    var nrf = require("NRF24L01P").connect( SPI1, B0, B1 );
    
    var recvData, lastData, lastUpdated;
    
    function onInit() {
      recvData = [];
      lastData = [];
      lastUpdated = [];
      lastUploaded = getTime();
      
      nrf.init([0,0,0,0,1]/* rx addr 1*/, [0,0,0,0,2] /* tx addr */);
      nrf.setDataRate(250000);
      // set receive addresses
      nrf.setRXAddr([1,0,0,0,1], 2);
      nrf.setRXAddr([2,0,0,0,1], 3);
      nrf.setRXAddr([3,0,0,0,1], 4);
      nrf.setRXAddr([4,0,0,0,1], 5);
    
       setInterval(checkNRF, 50);
    }
    
    function checkNRF() {
      var pipe;
      while ((pipe=nrf.getDataPipe())!==undefined) {
        nrf.getData().map(function(ch) {
          if (recvData[pipe]===undefined) recvData[pipe]="";
          if (ch===0 && recvData[pipe]!=="") {
            var d = JSON.parse(recvData[pipe]);
            if (d) {
              lastData[pipe] = d;
              lastUpdated[pipe] = getTime();
            }
            recvData[pipe] = "";
          } else if (ch!==0) {
            recvData[pipe] += String.fromCharCode(ch);
          }
        });
      }
    }
    

    TX 1:

    SPI1.setup({sck:A5, miso:A6, mosi:A7});
    var nrf = require("NRF24L01P").connect( SPI1, B0, B1 );
    function onInit() {
      nrf.init([0,0,0,0,2]/* rx addr */, [0,0,0,0,1]/*tx must match receiver's RX*/);
      nrf.setDataRate(250000);
    }
    function sendData() {
      var data = { temp : E.getTemperature().toFixed(2), bat : E.getAnalogVRef().toFixed(2) };
      nrf.setEnabled(true);
      nrf.sendString(JSON.stringify(data));
      nrf.setEnabled(false);
    }
    onInit();
    setInterval(sendData, 20000);
    setDeepSleep(1);
    

    TX2:

    SPI1.setup({sck:A5, miso:A6, mosi:A7});
    var nrf = require("NRF24L01P").connect( SPI1, B0, B1 );
    function onInit() {
      nrf.init([0,0,0,0,2]/* rx addr */, [1,0,0,0,1]/*tx must match receiver's RX*/);
      nrf.setDataRate(250000);
    }
    function sendData() {
      var data = { temp : E.getTemperature().toFixed(2), bat : E.getAnalogVRef().toFixed(2) };
      nrf.setEnabled(true);
      nrf.sendString(JSON.stringify(data));
      nrf.setEnabled(false);
    }
    onInit();
    setInterval(sendData, 20000);
    setDeepSleep(1);
    

    and so on... All that changes is the TX address.

  • Thank you very much, Gordon, that's quite useful samle. Now i need to synchronise several periodical processes on 4 espruinos. Those processes realised on setInterval's. Could you recomend the rigth way to start the circle on all of them simultaneously, with maximum accuracy, which is principle can be realized with those wireless devices?

  • To re-synchronise an interval, I'd just clear it with clearInterval and re-start it. I was considering making a library to sync the Espruinos. My idea was:

    • Have one central Espruino that is always receiving (it never sleeps)
      • Each transmitter transmits every 60s (or whatever), receives for 1ms, and then sleeps (unless it receives something in which case it keeps listening).
    • Then it's easy for the 'central' Espruino to just wait until it receives something, and then to send any command it gets out to the receiver.
  • I am really new to this. Still not quite understand the address setup for multiple transmitters. Actually I am setting up to have 3 transmitters sending individual data to one receiver. I have similar problem.
    It seems readings from three transmitters are same. When I tried to change reading from , all readings from all sensors changed.
    TX1:
    const uint64_t pipes[3] = {0xB3B4B5B6F1,0xB3B4B5B6CD,0xB3B4B5B6A3}­;
    radio.openWritingPipe(pipes[1]);
    read and send data p1, t1, s1
    radio.write(p1, sizeof(p1));
    radio.write(t1, sizeof(t1));
    radio.write(s1, sizeof(s1));

    TX2:
    const uint64_t pipes[3] = {0xB3B4B5B6F1,0xB3B4B5B6CD,0xB3B4B5B6A3}­;
    read and send data p2, t2, s2
    radio.openWritingPipe(pipes[2]);
    read and send data p2, t2, s2
    radio.write(p2, sizeof(p2));
    radio.write(t2, sizeof(t2));
    radio.write(s2, sizeof(s2));

    Receiver:
    const uint64_t pipes[3] = {0xB3B4B5B6F1,0xB3B4B5B6CD,0xB3B4B5B6A3}­;

    radio.openReadingPipe(1,pipes[1]);
    radio.openReadingPipe(2,pipes[2]);
    Do I need to upload entire code?
    Thank you!

  • @user66100 are you using an Espruino board at all? It looks a lot like you're using an Arduino as you're writing C code - if that's the case you'd need to post on the Arduino forum...

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

multiple nrf24 sending data to one master

Posted by Avatar for hansamann @hansamann

Actions