nRF24L01 receive from 2 transmitters?
i have few arduino boards nrf24l01 transceivers on them. have 2 boards sending sensor values , 1 receive them , putting in plx-daq spreadasheet. able either 1 work @ time, have not been able both send data , other 1 pick them both @ same time.
this have 1 of sending (i used library tmrh20)
and respective receive:
then other send
and receive that
this works fine, having trouble getting both of them. guess start off with, possible in first place? tried this:
obviously, changed channel on second sender match. did because figured interfere each other if sending on same channel. anyway, don't 100% how work, appreciated.
this have 1 of sending (i used library tmrh20)
code: [select]
#include <spi.h>
#include "rf24.h"
rf24 myradio (7, 8);
byte addresses[][6] = {"0"};
struct package
{
int id=1;
float moisture;
};
typedef struct package package;
package data;
void setup()
{
serial.begin(9600);
delay(1000);
myradio.begin();
myradio.setchannel(115);
myradio.setpalevel(rf24_pa_max);
myradio.setdatarate( rf24_250kbps ) ;
myradio.openwritingpipe( addresses[0]);
delay(1000);
}
void loop()
{
myradio.write(&data, sizeof(data));
serial.println(analogread(a0));
data.moisture = analogread(a0);
delay(1000);
}
and respective receive:
code: [select]
#include <spi.h>
#include "rf24.h"
rf24 myradio (7, 8);
struct package
{
int id=0;
float moisture;
};
byte addresses[][6] = {"0"};
typedef struct package package;
package data;
int row = 0;
int x = 0;
void setup()
{
serial.begin(9600);
delay(1000);
serial.println("cleardata");
serial.println("label,time,moisture");
serial.println("resettimer");
myradio.begin();
myradio.setchannel(115);
myradio.setpalevel(rf24_pa_max);
myradio.setdatarate( rf24_250kbps ) ;
myradio.openreadingpipe(1, addresses[0]);
myradio.startlistening();
}
void loop()
{
if ( myradio.available())
{
while (myradio.available())
{
myradio.read( &data, sizeof(data) );
}
serial.print("data,time,");
serial.println((-10.32 * (log(data.moisture) / log(2.718)) + 72.66));
row++;
x++;
if (row > 60)
{serial.println("cleardata");
serial.println("row,set,2");
row = 0;}
}
}
then other send
code: [select]
#include <spi.h>
#include "rf24.h"
rf24 myradio (7, 8);
byte addresses[][6] = {"0"};
struct package2
{
int id=1;
float psi;
};
typedef struct package2 package2;
package2 datas;
void setup()
{
serial.begin(9600);
delay(1000);
myradio.begin();
myradio.setchannel(115);
myradio.setpalevel(rf24_pa_max);
myradio.setdatarate( rf24_250kbps ) ;
myradio.openwritingpipe( addresses[0]);
delay(1000);
}
void loop()
{
myradio.write(&datas, sizeof(datas));
serial.println(analogread(a0));
datas.psi = analogread(a0);
delay(1000);
}
and receive that
code: [select]
#include <spi.h>
#include "rf24.h"
rf24 myradio (7, 8);
struct package2
{
int id=0;
float psi;
};
byte addresses[][6] = {"0"};
typedef struct package2 package2;
package2 datas;
int row = 0;
int x = 0;
void setup()
{
serial.begin(9600);
delay(1000);
serial.println("cleardata");
serial.println("label,time,moisture");
serial.println("resettimer");
myradio.begin();
myradio.setchannel(115);
myradio.setpalevel(rf24_pa_max);
myradio.setdatarate( rf24_250kbps ) ;
myradio.openreadingpipe(1, addresses[0]);
myradio.startlistening();
}
void loop()
{
if ( myradio.available())
{
while (myradio.available())
{
myradio.read( &datas, sizeof(datas) );
}
serial.print("data,time,");
serial.println(0.29325513196*datas.psi);
row++;
x++;
if (row > 60)
{serial.println("cleardata");
serial.println("row,set,2");
row = 0;}
}
}
this works fine, having trouble getting both of them. guess start off with, possible in first place? tried this:
code: [select]
#include <spi.h>
#include "rf24.h"
rf24 myradio (7, 8);
struct package
{
int id=0;
float moisture;
};
struct package2
{
int id=0;
float psi;
};
byte addresses[][6] = {"0"};
typedef struct package package;
package data;
int row = 0;
int x = 0;
typedef struct package2 package2;
package2 datas;
void setup()
{
serial.begin(9600);
delay(1000);
serial.println("cleardata");
serial.println("label,time,moisture,air pressure");
serial.println("resettimer");
myradio.begin();
myradio.setchannel(115);
myradio.setpalevel(rf24_pa_max);
myradio.setdatarate( rf24_250kbps ) ;
myradio.openreadingpipe(1, addresses[0]);
myradio.setchannel(95);
myradio.setpalevel(rf24_pa_max);
myradio.setdatarate( rf24_250kbps ) ;
myradio.openreadingpipe(1, addresses[0]);
myradio.startlistening();
}
void loop()
{
if ( myradio.available())
{
while (myradio.available())
{
myradio.setchannel(115);
myradio.read( &data, sizeof(data) );
serial.print("data,time,");
serial.print((-10.32 * (log(data.moisture) / log(2.718)) + 72.66));
serial.print(",");
myradio.setchannel(95);
myradio.read( &datas, sizeof(datas) );
serial.println(0.29325513196*datas.psi);
row++;
x++;}
if (row > 60)
{serial.println("cleardata");
serial.println("row,set,2");
row = 0;}
}
}
obviously, changed channel on second sender match. did because figured interfere each other if sending on same channel. anyway, don't 100% how work, appreciated.
it's been while since did useful nfr2400's, aren't supposed set 'sender' id somewhere?
Arduino Forum > Using Arduino > Project Guidance > nRF24L01 receive from 2 transmitters?
arduino
Comments
Post a Comment