Difference between revisions of "I2C Configuration"

From Wiki
Jump to: navigation, search
(Created page with "When you run some python code related to I2C device, you may meet the following problem. <pre> IOERROR: [Errno 2] No Such File Or Directory </pre> The cause of "IOERROR" ma...")
(No difference)

Revision as of 07:50, 27 January 2016

When you run some python code related to I2C device, you may meet the following problem.

IOERROR: [Errno 2] No Such File Or Directory

The cause of "IOERROR" maybe that there is something wrong with the I2C device.

First, let's take a look at whether the Raspberry Pi can detect the address of the I2C device.

Install I2C-tools.

sudo apt-get install i2c-tools

Run `i2cdetect` and check the address of the I2C device.

  
sudo i2cdetect -y 1    # 1 for RPi2
sudo i2cdetect -y 0    # 0 for RPi1

The above two lines depends on your Raspberry Pi. For Raspberry Pi 2, run the first line. For Raspberry Pi 1, run the second line.

If nothing occurred, check to see if you wire the I2C device correctly and then run `i2cdetect` again.

If the address still does not occurred, run `raspi-config` Enable i2c:

sudo raspi-config

Select Advenced Options.

Find I2C and enable I2C according to prompt.

After that, select Finish and restart.

Run `i2cdetect` again to check your device address again.

   
sudo i2cdetect -y 1    # 1 for RPi2
sudo i2cdetect -y 0    # 0 for RPi1