I have the basic i2c slave / master working between a raspberry pi and arduino over I2C.
There is a delay here in the setup, and if I send a request event from master to slave during that delay, I get a buffer with the correct data.
But after that buffer, when I try reading an I2C sensor (accelerometer in this case) and then the requestEvent, I get a buffer with [0, 255, 255, 255, 255, 255, 255, 255] instead of the correct data.
I have stripped down my code to this barebones and it still doesn't work.
Is there something in here I am doing incorrectly?
#include "Wire.h"
extern "C" {
#include "utility/twi.h" // from Wire library, so we can do bus scanning
}
#include "I2Cdev.h"
#include "MPU6050.h"
MPU6050 accelgyro;
int16_t ax, ay, az;
void setup()
{
Serial.begin(9600);
Wire.begin(4);
Wire.onRequest(requestEvent);
accelgyro.initialize();
delay(5000);
}
void loop()
{
accelgyro.getRotation(&ax, &ay, &az);
Serial.println(ax);
delay(1000);
}
void requestEvent() {
Wire.write((const byte *)"asdfasdf", 8);
}