私は私のArduinoメガから私のラズベリーに二倍を送りたいと思います。これはI2C経由で可能ですか?ここに私のコードです:Arduino MegaからI2C経由でラズベリーにダブルを受け取るにはどうしたらいいですか?
#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);
}
私のコードの問題は、私はint答えの代わりにフロートの答えを書くことができないです。 提案がありますか?
ありがとうございました!
編集:
ここでは、二重の値を取得するにはPythonで私のコードです:
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
私は試してみますが、私はちょうど121を取得します。私はパイソンで私のラズベリーとの価値を得るために私のコードを書いた –
申し訳ありませんが、本当にあなたを助けることはできません。私はPythonに慣れていないし、PythonのI2Cについてもそうだ。 –