Can I send float structure via nRF24L01 module?
I send this:
struct DaneTemp {
float tempL;
float tempR;
float temp;
} daneTemp;
but my reciver reads value 0.00 when I read value of temp variable.
Should I somehow convert it to bytes?
Can I send float structure via nRF24L01 module?
I send this:
struct DaneTemp {
float tempL;
float tempR;
float temp;
} daneTemp;
but my reciver reads value 0.00 when I read value of temp variable.
Should I somehow convert it to bytes?
Yes you can as long as the total number of bytes does not exceed 32
Which Arduino board are you using ?
Please post both sketches, using code tags when you do
I send data from Arduino Uno to Arduino Nano Every.
Transmiter:
# include <Wire.h>
# include <OneWire.h>
# include <DallasTemperature.h>
# include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include "RF24.h"
#include "nRF24L01.h"
#define RFCE 9
#define RFCSN 10
RF24 radio(RFCE, RFCSN); //nRF24L01
const byte AddressTempIn[6] = "Temp1n";
const byte AddressTempOut[6] = "Temp1o";
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
struct DaneTemp {
float tempL;
float tempR;
float temp;
} daneTemp;
LiquidCrystal_I2C lcd(0x27, 16, 4);
void setup()
{
Serial.begin(9600);
sensors.begin();
radio.begin();
radio.setPALevel(RF24_PA_HIGH);
radio.setDataRate(RF24_1MBPS);
radio.setChannel(1);
radio.setAutoAck(1);
radio.setRetries(2, 15);
radio.setCRCLength(RF24_CRC_8);
radio.openWritingPipe(AddressTempOut);
radio.openReadingPipe(1, AddressTempIn);
delay(500);
}
void loop() {
radio.stopListening();
sensors.requestTemperatures();
daneTemp.tempL = sensors.getTempCByIndex(0);
daneTemp.tempR = sensors.getTempCByIndex(1);
daneTemp.temp = (daneTemp.tempL + daneTemp.tempR) / 2;
Serial.println(daneTemp.temp);
radio.openWritingPipe(AddressTempOut);
delay(10);
radio.write(&daneTemp, sizeof(DaneTemp));
delay(100);
}
Receiver:
#include <Servo.h>
#include "nRF24L01.h"
#include "RF24.h"
#include <SPI.h>
#define RFCE 9
#define RFCSN 10
RF24 radio(RFCE, RFCSN); //nRF24L01
const byte AddressTempIn[6] = "Tem1o";
const byte AddressTempOut[6] = "Tem1n";
struct DaneTemp {
float tempL;
float tempR;
float temp;
} daneTemp;
Servo serwoL;
void setup() {
Serial.begin(9600);
radio.begin();
radio.setPALevel(RF24_PA_HIGH);
radio.setDataRate(RF24_1MBPS);
radio.setChannel(1);
radio.setAutoAck(1);
radio.setRetries(12, 15);
radio.setCRCLength(RF24_CRC_8);
radio.openWritingPipe(AddressTempOut);
radio.openReadingPipe(1, AddressTempIn);
radio.startListening();
delay(500);
Serial.write("Started\n");
serwoL.attach(5);
serwoL.write(0);
delay(1000);
}
void loop() {
radio.startListening();
if (radio.available()) {
Serial.println("OK");
radio.read(&daneTemp, sizeof(DaneTemp));
if (daneTemp.temp < 18) {
Serial.println("ok_1");
serwoL.write(0);
delay(500);
}
if (daneTemp.temp > 22.5) {
Serial.println("ok_11");
serwoL.write(10);
delay(500);
}
}
}
I don't see anything connected to printing to an LCD..???
Please post the code that actually demonstrates this.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.