Difference between revisions of "I2C Configuration"
(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...") |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 43: | Line 43: | ||
sudo i2cdetect -y 1 # 1 for RPi2 | sudo i2cdetect -y 1 # 1 for RPi2 | ||
sudo i2cdetect -y 0 # 0 for RPi1 | sudo i2cdetect -y 0 # 0 for RPi1 | ||
+ | </pre> | ||
+ | |||
+ | Finally remember to install `'''smbus'''` for I2C | ||
+ | |||
+ | <pre> | ||
+ | sudo apt-get install python-smbus | ||
</pre> | </pre> |
Latest revision as of 06:15, 26 June 2018
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
Finally remember to install `smbus` for I2C
sudo apt-get install python-smbus