I'm trying to send the temperature value from the DHT sensor to a raspberry pi through I2C. Which is the best way to do it?. The temp value is a float, and I think I have to convert it to byte and send that with Wire.write() to the raspberry, is that right?. Right now I'm sending bytes from the raspberry (with Python) to the Arduino (C++): Python:
from smbus import SMBus
import time
address = 0x8
bus = SMBus(1)
While True:
bus.write_byte(address, 4)
time.sleep(1)
print(bus.ready_byte(address))
Arduino code:
#include <Wire.h>
#include <DHT.h>
...
void setup() {
dht.begin();
Wire.begin(0x8);
Wire.onReceive(receiveEvent);
}
void receiveEvent () {
float temp = dht1.readTemperature();
delay(1000);
byte tempByte[4] = {temp, 0, 0, 0};
Wire.write(tempByte[0]);
}
So the raspberry is printing 0.
Thanks for any help.