Dear team, I need your help, I have been trying for several weeks to connect several sensors (3 DS18B20 + 1 DHT22) to a master in such a way that the master receives the synchronized information from the sensors. Please if someone can structure the programming code, I was reading some cases in the programming forum and I don't get results.
Have you proven that your NRF devices are all working and able to communicate? Master to each slave, individually?
Please explain synchronized information? Does this indicate you can sequentially read them or must you read then concurrently. It takes 750 ms to get a 12 bit reading from the sensor. You can start them at the same time but you can only read them one at a time.
Thanks for the question, I should read them simultaneously approximately the results should be displayed every 5 minutes
Yes, I have verified it. Individually they can communicate.
Ok, that is out of the way. What leads you to believe you can read from the NRF devices "simultaneously"?
I expressed myself wrong, sorry. I was referring to the fact that approximately every 5 minutes the measurements of all the sensors are updated, I understand that the information is arriving one after another in less time.
//Program NODE01
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire ourWire(2); //Se establece el pin 2 como bus OneWire
DallasTemperature sensors(&ourWire); //Se declara una variable u objeto para nuestro sensor
RF24 radio(10, 9); // nRF24L01 (CE,CSN)
RF24Network network(radio); // Include the radio in the network
const uint16_t this_node = 01; // Address of our node in Octal format ( 04,031, etc)
const uint16_t master00 = 00; // Address of the other node in Octal format
const unsigned long interval = 10; //ms // How often to send data to the other unit
unsigned long last_sent; // When did we last send?
void setup() {
SPI.begin();
Serial.begin(9600);
sensors.begin(); //Se inicia el sensor
radio.begin();
network.begin(90, this_node); //(channel, node address)
radio.setDataRate(RF24_2MBPS);
}
void loop() {
network.update();
sensors.requestTemperatures(); //Se envía el comando para leer la temperatura
//===== Sending =====//
unsigned long now = millis();
if (now - last_sent >= interval) { // If it's time to send a data, send it!
last_sent = now;
float temp1= sensors.getTempCByIndex(0); //Se obtiene la temperatura en ºC
RF24NetworkHeader header(master00); // (Address where the data is going)
bool ok = network.write(header, &temp1, sizeof(temp1)); // Send the data
Serial.print("Temp1= ");
Serial.print(temp1);
Serial.println(" C");
}
}
//PROGRAM NODE02
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire ourWire(2); //Se establece el pin 2 como bus OneWire
DallasTemperature sensors(&ourWire); //Se declara una variable u objeto para nuestro sensor
RF24 radio(10, 9); // nRF24L01 (CE,CSN)
RF24Network network(radio); // Include the radio in the network
const uint16_t this_node = 02; // Address of our node in Octal format ( 04,031, etc)
const uint16_t master00 = 00; // Address of the other node in Octal format
const unsigned long interval = 10; //ms // How often to send data to the other unit
unsigned long last_sent; // When did we last send?
void setup() {
SPI.begin();
Serial.begin(9600);
sensors.begin(); //Se inicia el sensor
radio.begin();
network.begin(90, this_node); //(channel, node address)
radio.setDataRate(RF24_2MBPS);
}
void loop() {
network.update();
sensors.requestTemperatures(); //Se envía el comando para leer la temperatura
//===== Sending =====//
unsigned long now = millis();
if (now - last_sent >= interval) { // If it's time to send a data, send it!
last_sent = now;
float temp2= sensors.getTempCByIndex(0); //Se obtiene la temperatura en ºC
RF24NetworkHeader header(master00); // (Address where the data is going)
bool ok = network.write(header, &temp2, sizeof(temp2)); // Send the data
Serial.print("Temp2= ");
Serial.print(temp2);
Serial.println(" C");
}
}
//PROGRAM BASE00
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
RF24 radio(10, 9); // nRF24L01 (CE,CSN)
RF24Network network(radio); // Include the radio in the network
const uint16_t this_node = 00; // Address of this node in Octal format ( 04,031, etc)
//const uint16_t node01 = 01; // Address of the other node in Octal format
//const uint16_t node012 = 012;
//const uint16_t node022 = 022;
const uint16_t node01 = 01;
const uint16_t node02 = 02;
float temp1;
float temp2;
void setup() {
SPI.begin();
Serial.begin(9600);
radio.begin();
network.begin(90, this_node); //(channel, node address)
radio.setDataRate(RF24_2MBPS);
}
void loop() {
network.update();
//===== Receiving =====//
while ( network.available() ) { // Is there any incoming data?
RF24NetworkHeader header;
unsigned long incomingData;
network.read(header, &temp1, sizeof(temp1)); // Read the incoming data
if (header.from_node == 01) { // If data comes from Node 01
Serial.print("Temp1= ");
Serial.print(temp1);
Serial.println(" C");
}
network.read(header, &temp2, sizeof(temp2)); // Read the incoming data
if (header.from_node == 02) { // If data comes from Node 02
Serial.print("Temp2= ");
Serial.print(temp2);
Serial.println(" C");
}
}
}
I can't connect all the sensors to the receiver, but independently. Can someone help me please.
Do You fiind a solution? Same problema i have , and i use the same library.
Thanks
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.