6 Replies Latest reply on Jun 17, 2014 2:23 PM by AlexT_Intel

    i2c directly under Yocto




      I'm trying to use an Adafruit Oled display directly under Yocto ( compiled with dev tools).


      I know that I plugged the screen correctly cause I was able to run the adafruit sketche sample (with some modifications) through the arduino IDE.


      I guess I'm using the standard method under Yocto:


      modprobe i2c-dev

      chmod 666 /dev/i2c*


      Then in my C file:


      #define addr 0x3D
      void send_command(int i2c, unsigned char command){
              unsigned char buf[10];
              unsigned char control = 0x00;
              buf[0] = control;
              buf[1] = command;
              buf[0] = control;
              if (i2c_smbus_write_byte(i2c,control) == -1) {
                      printf("Failed to write to the i2c control.\n");
              buf[0] = command;
              if (i2c_smbus_write_byte(i2c,command) == -1) {
                      printf("Failed to write to the i2c command.\n");
                      perror("write data fail\n");
      int main(int argc, char* argv[]){
              printf("Begin of program...\n");
              int i2c, reset;
              char *filename = "/dev/i2c-0";
              if ((i2c = open(filename, O_RDWR)) < 0) {
                      /* ERROR HANDLING: you can check errno to see what went wrong */
                      perror("Failed to open the i2c bus");
              if (ioctl(i2c, I2C_SLAVE_FORCE, addr) < 0) {
                      printf("Failed to acquire bus access and/or talk to slave.\n");
              send_command(i2c, 0xae);   
              return 0;


      Now, when I run this code, I end up with:

      Failed to write to the i2c control.

      Failed to write to the i2c command.

      write data fail

      : Remote I/O error

      I also downloaded i2c tools and I can't use i2cset or i2cget:

      galileo# i2cget -y 0 0x3D
      Error: Read failed


      The address (0x3D) seems fine cause it's the same as the one used in the adafruit arduino scketche and the :

      (ioctl(i2c, I2C_SLAVE_FORCE, addr) 

      doesn't fail.


      So have you ever seen this problem ? I hope it doesn't come from the i2c driver...