Hi @kaydend
OK, the following code works for me! First the transmitter sending one incrementing byte to address 8 and blinking the D7 LED to show that it is sending:
uint8_t val = 0;
void setup() {
Wire.begin();
pinMode(D7,OUTPUT);
}
void loop() {
delay(1000);
digitalWrite(D7,HIGH);
Wire.beginTransmission(8);
Wire.write(&val,1);
Wire.endTransmission();
val++;
delay(20);
digitalWrite(D7,LOW);
}
Now the receive side using onReceive:
uint8_t data[8];
int idx;
void receiveEvent(int numOfBytes) {
idx = 0;
while (Wire.available()) {
data[idx++] = (uint8_t)Wire.read();
}
}
void setup() {
Serial.begin(9600);
Wire.begin(8);
Wire.onReceive(receiveEvent);
pinMode(D7,OUTPUT);
}
void loop() {
if (idx != 0) {
digitalWrite(D7,HIGH);
Serial.print("RX (");
Serial.print(idx);
Serial.print("): ");
for(int i=0;i<idx;i++) {
Serial.println(data[i],HEX);
}
idx = 0;
digitalWrite(D7,LOW);
}
}
I let this run for several minutes with no problems. Here’s a copy of the serial output.
RX (1): F9
RX (1): FA
RX (1): FB
RX (1): FC
RX (1): FD
RX (1): FE
RX (1): FF
RX (1): 0
RX (1): 1
RX (1): 2
RX (1): 3
RX (1): 4
RX (1): 5
RX (1): 6
RX (1): 7