7

I'm having trouble compiling the python from an example in the library.

https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code/blob/master/Adafruit_ADS1x15/ads1x15_ex_singleended.py

I basically just cloned the entire repo, navigated to the example and then tried to run it as sudo:

sudo python ./ads1x15_ex_singleended.py

Here is the stack trace:

Traceback (most recent call last):
  File "ads1x15_ex_singleended.py", line 35, in <module>
    adc = ADS1x15(ic=ADS1115)
  File "/home/mename/Developer/AutomatedSmokingMachine/Adafruit-Raspberry-Pi-Python-Code/Adafruit_ADS1x15/Adafruit_ADS1x15.py", line 138, in __init__
    self.i2c = Adafruit_I2C(address)
  File "/home/mename/Developer/AutomatedSmokingMachine/Adafruit-Raspberry-Pi-Python-Code/Adafruit_ADS1x15/Adafruit_I2C.py", line 36, in __init__
    busnum if busnum >= 0 else Adafruit_I2C.getPiI2CBusNumber())
IOError: [Errno 2] No such file or directory

3 Answers 3

6

Nevermind. I found the solution in another forum. It turns out that i2c is disabled by default. Follow this guide:

http://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c

# ensure the pi has i2c enabled by adding this to the end of /etc/modules
sudo vim /etc/modules
i2c-bcm2708
i2c-dev

# download and install prerequisites
sudo apt-get update
sudo apt-get install python-smbus
sudo apt-get install i2c-tools

# un-blacklist spi and i2c (disabled by default)
# by commenting out the lines that say
# blacklist spi-bcm2708
# blacklist i2c-bcm2708
sudo vim /etc/modprobe.d/raspi-blacklist.conf

# look for an i2c device on the bus (assuming you have rpi revB)
sudo i2cdetect -y 1
1
2

I just wanted to report that today this result can be achieve very easily using this command from the terminal:

sudo raspi-config

In the next screen choose, in order:

  1. Interfacing Options
  2. I2C

Done that you're good to go.

Happy hacking!

1
  • 1
    I'm amazed it took a year for someone to point this out :-)
    – MikeKulls
    Commented Mar 17, 2019 at 1:21
1

Important to note that in the link that the above answer provided, there is an additional step:

Add the following lines to /boot/config.txt and reboot

dtparam=i2c1=on
dtparam=i2c_arm=on
2
  • Likely the adafruit thing was edited since that answer was posted, after the pi kernel's started using device trees by default.
    – goldilocks
    Commented Jun 1, 2015 at 20:12
  • 1
    That makes sense. It tripped me up before so I thought I would bring attention to it.
    – Greg
    Commented Jun 2, 2015 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.