I have been working with the NRF24 for a week. I have reviewed the entire RF24 Library documentation (thrh20), although much of it is still not really understood.
I've gone through Nrf24L01-2.4GHz-HowTo and added the capacitors to assist with the current draw.
I have been able to get 2 arduinos exchanging data (a client sending to a server) referencing this: connecting-and-programming-nrf24l01-with-arduino
The next step was to have 2 clients talking to the server. This is where I am being confused by the anomalies I am seeing with the print out of the transferred data. The data from each client comes across, but sometimes (randomly) client 1's data will print out as tmp2 and client 2's data will print out as tmp1.
My code simply reads a temperature (a number between 0-255) at each client and sends it to the server for printout.
Can someone please review my sketches for what may be causing the anomalies? I am new to all of this, and am not an experienced coder.
This is the Server Sketch
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8);
const byte Addr1[6] = "00001";
const byte Addr2[6] = "00002";
byte tmp1;
byte tmp2;
void setup()
{
while (!Serial);
Serial.begin(115200);
radio.begin();
radio.setPALevel(RF24_PA_MIN);
radio.setChannel(108);
radio.setDataRate( RF24_250KBPS );
}
void loop()
{
radio.openReadingPipe(0, Addr1);
radio.startListening();
if (radio.available())
{
radio.read(&tmp1, 1);
radio.stopListening();
}
delay(100);
radio.openReadingPipe(0, Addr2);
radio.startListening();
if (radio.available())
{
radio.read(&tmp2, 1);
radio.stopListening();
}
delay(100);
Serial.print(tmp1); Serial.print(", "); Serial.println(tmp2);
}
This is the Client Sketch.
The only difference in the two client sketches is
const byte Addr[6] = "00001"; for client 1
and
const byte Addr[6] = "00002"; for client 2
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
#include "Adafruit_TMP007.h"
Adafruit_TMP007 tmp007;
RF24 radio(7, 8);
const byte Addr[6] = "00001";
byte tmp;
void setup()
{
tmp007.begin();
radio.begin();
radio.setPALevel(RF24_PA_MIN);
radio.setChannel(108);
radio.setDataRate( RF24_250KBPS );
radio.setRetries(1, 15);
radio.openWritingPipe(Addr);
radio.stopListening();
}
void loop()
{
float objt = tmp007.readObjTempC();
tmp = (objt)*9/5+32;
radio.write(&tmp, 1);
delay(100);
}