Hi Guys,
I have a problem with my program. With an Arduino Nano [TX] I have to send the results of 2 temperature sensors to an Arduino Mega [RX] with LCD display via an nRF24L01.
The problem is that the data from [TX] is not sent, at least that says the program where I have built a function for it.
The fact is that [RX] does not receive any results.
And just that you know, i speak german, but i think this shoulden't be a problem.
I would be happy if someone could help me.
Arduino Nano [TX]:
#include <OneWire.h> //Benötigten Bibliotheken
#include <DallasTemperature.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
float temp1, temp2;
OneWire ds_1(4); //Verbindung zu Pin 4
OneWire ds_2(5); //Verbindung zu Pin 5
DallasTemperature sensor_1(&ds_1); //Sensor 1 = Pin 4 = Innen
DallasTemperature sensor_2(&ds_2); //Sensor 2 = Pin 5 = Außen
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "MF0SP";
void setup(void) //Setup: läuft 1 mal
{
Serial.begin(9600);
Serial.println("---Programm startet---"); //Visuelle Ausgabe, dass das Programm startet
sensor_1.begin(); //Sensor 1 wird initialisiert
sensor_2.begin(); //Sensor 2 wird initialisiert
radio.begin();
radio.setPALevel(RF24_PA_LOW); //LOW weil kein großer Abstand
radio.setDataRate( RF24_250KBPS );
radio.openWritingPipe(address[1]);
radio.openReadingPipe(1,address[0]);
radio.stopListening();
Serial.println("Setup beendet");
Serial.println("Loop wird gestartet");
Serial.println(""); //Setup beendet: Absatz für Monitor
delay(1000);
}
void loop(void) //Loop: wiederholt sich immer wieder
{
radio.stopListening();
sensor_1.requestTemperatures(); //Sensor 1 wird nach Temperatur gefragt
sensor_2.requestTemperatures(); //Sensor 2 wird nach Temperatur gefragt
temp1=sensor_1.getTempCByIndex(0); //Temperatur wird in °Celsius gewandelt
Serial.print("Innen: ");
Serial.print(temp1); //Ausgabe
Serial.println(" °Celsius");
temp2=sensor_2.getTempCByIndex(0); //Temperatur wird in °Celsius gewandelt
Serial.print("Außen: ");
Serial.print(temp2); //Ausgabe
Serial.println(" °Celsius");
//Transmit data
bool ok_1;
ok_1 = radio.write(&temp1, sizeof(temp1));
if (ok_1) { Serial.println("Innen gesendet"); }
else { Serial.println("Innen nicht gesendet"); }
bool ok_2;
ok_2 = radio.write(&temp2, sizeof(temp2));
if (ok_2) { Serial.println("Aussen gesendet"); }
else { Serial.println("Aussen nicht gesendet"); }
Serial.println();
delay(1000); //2 Sekunden warten, bevor sich loop wiederholt
}
Arduino Mega [RX]:
#include <OneWire.h> //Benötigten Bibliotheken
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
#include <RF24.h>
#include <SPI.h>
#include <nRF24L01.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
float temp1, temp2;
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "MF0SP";
void setup(void)
{
Serial.begin(9600);
radio.begin();
radio.setPALevel(RF24_PA_LOW); //LOW weil kein großer Abstand
radio.setDataRate( RF24_250KBPS );
radio.openWritingPipe(address[0]);
radio.openReadingPipe(1,address[1]);
radio.startListening();
lcd.begin(16, 2);
lcd.print("Connecting.....");
delay(1000);
}
void loop(void)
{
radio.startListening();
lcd.clear();
radio.available();
//Temperatur = EmpfangenerWert / 100.0
radio.read(&temp1, sizeof(temp1));
lcd.setCursor(0, 0);
lcd.print("Innen:");
lcd.setCursor(9, 0);
lcd.print(temp1);
lcd.print(" C");
Serial.print("Innen: ");
Serial.println(temp1);
radio.read(&temp2, sizeof(temp2));
lcd.setCursor(0, 1);
lcd.print("Aussen:");
lcd.setCursor(9, 1);
lcd.print(temp2);
lcd.print(" C");
Serial.print("Aussen: ");
Serial.println(temp2);
Serial.println();
delay(1000);
}
[Edit] You can find the final code at reply #8