Hi I am attempting to test I2C comms between an pi model 4B and teensy 4.1 (running code uploaded from the arduino IDE via usb). While I can read from the slave with a python script if the arduino code has a Wire.write call in setup(), the event handler for onReceive doesn't trigger which makes me suspect that either data is not being written from the pi side correctly or I am not formatting the arduino side correctly.
I am new to I2C and working with arduino/c so am not sure where I am going wrong but hope if I can sort this out it will help me build from this to the functionality I need. Any help appreciated.
Python script on master pi:
from smbus2 import SMBus, i2c_msg
DEVICE_BUS = 1
DEVICE_ADDR_TEST = 0x8
bus = SMBus(DEVICE_BUS)
write = i2c_msg.write(DEVICE_ADDR_TEST, [40,50])
read = i2c_msg.read(DEVICE_ADDR_TEST, 80)
bus.i2c_rdwr(write, read)
print(read)
code on Arduino IDE:
#include <Wire.h>
void setup() {
Wire.begin(0x8);
Wire.onReceive(receiveEvent); #this doesn't work
Wire.write("foo"); #this does
}
void receiveEvent(int howMany) {
while (Wire.available()) {
Wire.write("foo");
char c = Wire.read();
printf("received: %c", c);
}
}
void loop() {
delay(100);
}