Error in I2C Communication Between Arduino and Raspberry Pi The code below sends data to Raspberry Pi every 20 millisecond. The code works fine but sometimes python throws an error. Why this is happening? Should I give more time between writeData?
Error:
&gt; Traceback (most recent call last):   File &quot;rpi-I2C.py&quot;, line 33, in
&gt; &lt;module&gt;
&gt; writeData(&quot;360&quot;)   File &quot;rpi-I2C.py&quot;, line 12, in writeData
&gt; bus.write_i2c_block_data(address,0x00,byteValue) OSError: [Errno 121] Remote I/O error

Python code:
import smbus
import time
# for RPI version 1, use bus = smbus.SMBus(0)
bus = smbus.SMBus(1)

# This is the address we setup in the Arduino Program
address = 0x04

#http://www.raspberry-projects.com/pi/programming-in-python/i2c-programming-in-python/using-the-i2c-interface-2
def writeData(value):
    byteValue = StringToBytes(value)    
    bus.write_i2c_block_data(address,0x00,byteValue)
    #first byte is 0=command byte.. just is.
    return -1


def StringToBytes(val):
        retVal = []
        for c in val:
                retVal.append(ord(c))
        return retVal

while True:
    print(&quot;sending test&quot;)
    writeData(&quot;left&quot;)   
    time.sleep(0.02)

    #print('Sending OPEN-00-00');
    writeData(&quot;right&quot;)
    time.sleep(0.02)

    #print('Sending WIN-12-200');
    writeData(&quot;360&quot;)
    time.sleep(0.02)

Arduino code:
#include &lt;Wire.h&gt;
#define SLAVE_ADDRESS 0x04

volatile boolean receiveFlag = false;
char temp[32];
String command;

void setup() {
  Wire.begin(SLAVE_ADDRESS);
  // define callbacks for i2c communication    
  Wire.onReceive(receiveEvent);    
  Serial.begin(115200);    
  Serial.println(&quot;Ready!&quot;);    
}

void loop() {    
  if (receiveFlag == true) {    
    Serial.println(temp);    
    receiveFlag = false;    
  }    
}

void receiveEvent(int howMany) {    
  for (int i = 0; i &lt; howMany; i++) {          
    temp[i] = Wire.read();    
    temp[i + 1] = '\0';  //add null after ea. char    
  }
    
  //RPi first byte is cmd byte so shift everything to the left 1 pos so temp contains our string    
  for (int i = 0; i &lt; howMany; ++i)    
    temp[i] = temp[i + 1];    
    receiveFlag = true;    
  }
A RPI uses 3.3v logic while an arduino uses 5v logic you can use a logic converter but by now it's probly to late and maybe your arduino or RPI is broken (Sorry!)