title: How to read data from Arduino with Raspberry Pi with I2C
body: <p>I am trying to read data from an Arduino UNO to Raspberry Pi with the python smbus module. The only documentation I could find on the smbus module was <a href="http://wiki.erazor-zone.de/wiki%3alinux%3apython%3asmbus%3adoc?do=show">here</a>. I am not sure what the cmd means in the module. I can use the write to send data to the Arduino. I have written two simple programs one for read and one for write</p>
  
  <p>The one for write</p>
  
  <pre><code>import smbus
  b = smbus.SMBus(0)
  while (0==0):
      var = input("Value to Write:")
      b.write_byte_data(0x10,0x00,int(var))
  </code></pre>
  
  <p>The one for read</p>
  
  <pre><code>import smbus
  bus = smbus.SMBus(0)
  var = bus.read_byte_data(0x10,0x00)
  print(var)
  </code></pre>
  
  <p>The Arduino code is</p>
  
  <pre><code>#include &lt;SoftwareSerial.h&gt;
  #include &lt;LiquidCrystal.h&gt;
  #include &lt;Wire.h&gt;
  LiquidCrystal lcd(8,9,4,5,6,7);
  
  int a = 7;
  
  void setup() 
  { 
    Serial.begin(9600);
    lcd.begin(16,2);
    // define slave address (0x2A = 42)
    #define SLAVE_ADDRESS 0x10
  
    // initialize i2c as slave
    Wire.begin(SLAVE_ADDRESS);
  
    // define callbacks for i2c communication
    Wire.onReceive(receiveData);
    Wire.onRequest(sendData); 
  }
  void loop(){
  }
  
  // callback for received data
  void receiveData(int byteCount) 
  {
   Serial.println(byteCount);
    for (int i=0;i &lt;= byteCount;i++){
    char c = Wire.read();
    Serial.println(c);
   }
  }
  
  // callback for sending data
  void sendData()
  { 
    Wire.write(67);
    lcd.println("Send Data");
  }
  </code></pre>
  
  <p>When I run the read program it returns "33" every time. The Arduino returns that the the sendData function is called.</p>
  
  <p>I am using a <a href="https://www.adafruit.com/products/757">Data Level Shifter</a> and the description says it might be a little sluggish.</p>
  
  <p>Has anyone gotten this to work?</p>