Hi everyone,

I have a Problem with the I2C device. Every time I try to open the device it returns -1.

I can see the device under /dev/i2c_0. This is my code:

 

#include <stdio.h>

#include <stdlib.h>

#include <sys/ioctl.h>

#include <fcntl.h>

#include <linux/i2c.h>

#include <linux/i2c-dev.h>

 

#include <iostream>

 

int main( )

{

            int fd = 0;

 

            std::cout << "I2C communication test begin." << std::endl;

           

            fd = open( "/dev/i2c_0", O_RDWR );

 

            if( fd < 0 )

            {

                        std::cout << "I2C device open: Fail" << std::endl;

                       

                        exit( 1 );

            }          

           

            std::cout << "I2C device open: Pass" << std::endl;

           

            return 0;

}

 

Is there anything I did not consider ?