Hello,
I've the same problem with two arduinos communicating over i2c. I tried to use your solutions but I haven't got any progess with them. I am getting only the last byte and then only 255 too. Can you please help me with it?
Master code:
#include <Wire.h>
int wire_buffer[5]={-1,-1,-1,-1,-1};
void setup(){
Wire.begin();
Serial.begin(115200);
}
void loop(){
uno_r(2);
for(int i;i<5;i++){
Serial.print(wire_buffer[i],DEC);
Serial.print(" ");
}
Serial.println();
delay(100);
}
void uno_r(int howMany){
Wire.requestFrom(2,howMany);
for (int i = 0; i < kolik; i++) {
if (Wire.available() > 0) {
wire_buffer[i]=Wire.read();
}
}
}
Slave code:
#include <Wire.h>
#include <Max3421e.h>
#include <Usb.h>
#include <AndroidAccessory.h>
byte msg[2];
AndroidAccessory acc("Google, Inc.",
"DemoKit",
"DemoKit Arduino Board",
"1.0",
"http://www.android.com",
"0000000012345678");
void setup()
{
Wire.begin(2); // join i2c bus with address #2
Wire.onRequest(requestEvent); // register event
acc.powerOn();
Serial.begin(115200);
}
void loop()
{
if (acc.isConnected()) {
Serial.print("Accessory connected. ");
int len = acc.read(msg, sizeof(msg), 1);
Serial.print("Message value: ");
Serial.print(msg[0],DEC);
Serial.print(" ");
Serial.println(msg[1],DEC);
}
delay(20);
}
void requestEvent()
{
delay(10);
char buff[2]={(byte)msg[0],(byte)msg[1]};
Wire.write(buff);
}
Thank you