I would like to send a double from my Arduino Mega to my Raspberry. Is it possible to do this via I2C? Here is my code:
#include <Wire.h>
#define SLAVE_ADDRESS 0x04
int dataReceived = 0;
void setup() {
Serial.begin(9600);
Wire.begin(SLAVE_ADDRESS);
Wire.onReceive(receiveData);
Wire.onRequest(sendData);
}
void loop() {
delay(100);
}
void receiveData(int byteCount){
while(Wire.available()) {
dataReceived = Wire.read();
Serial.print("Donnee recue : ");
Serial.println(dataReceived);
}
}
void sendData(){
int answer = dataReceived + 100;
Wire.write(answer);
}
The problem in my code is I can't write float answer instead of int answer. Any suggestions?
Thank you very much!
Edit :
Here is my code in Python to get the value of a double :
import smbus import time
bus = smbus.SMBus(0)
address = 0x04
print "double"
bus.write_byte(address, 6)
time.sleep(1)
answer = bus.read_byte(address)
print answer