Difference between revisions of "I2C Configuration"

From Wiki
Jump to: navigation, search
Line 45: Line 45:
 
</pre>
 
</pre>
  
Install smbus for I2C
+
Finally remember to install smbus for I2C
  
 
<pre>  
 
<pre>  
 
sudo apt-get install python-smbus
 
sudo apt-get install python-smbus
 
</pre>
 
</pre>

Revision as of 06:13, 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