Hi everybody,
i have a Raspi as Master and Arduino Mega as Slave which are connected via I2C. I am trying to continuously read the data of my sensors connected to analog Pins A0-A3 on my Mega.
The Programm on my raspi runs for a few seconds (sometimes longer than that) returning the values and then crashes.
Here ist my Python script that is running on the raspi:
import smbus
import time
bus = smbus.SMBus(1)
SLAVE_ADDRESS = 0x08
def requestreading():
block = bus.read_i2c_block_data((SLAVE_ADDRESS), 0, 8)
print(block)
while True:
requestreading()
time.sleep(0.1)
it gives out the error message:
"Traceback (most recent call last):
requestreading()
block = bus.read_i2c_block_data((SLAVE_ADDRESS, 0, 8)
OSError: [Errno 121] Remote I/O error
My Arduino Code looks like this:
#include <Wire.h>
int SLAVE_ADDRESS = 0x08;
int analogPin1 = A0;
int analogPin2 = A1;
int analogPin3 = A2;
int analogPin4 = A3;
void setup(){
Wire.begin(SLAVE_ADDRESS);
Wire.onRequest(sendAnalogReading);
}
void loop(){
}
void sendAnalogReading(){
uint16_t reading1 = analogRead(analogPin1);
uint16_t reading2 = analogRead(analogPin2);
uint16_t reading3 = analogRead(analogPin3);
uint16_t reading4 = analogRead(analogPin4);
Wire.write((char *) &reading1, 2);
Wire.write((char *) &reading2, 2);
Wire.write((char *) &reading3, 2);
Wire.write((char *) &reading4, 2);
}
i guess the problem is the continuous loop?? is this a timing issue?
Many thanks