ADS1x15 Error: "Error accessing 0x48: Check your I2C address"
mwyatt2 opened this issue · 2 comments
I keep receiving the following error:
pi@raspberrypi ~/ADS1115 $ python ads1x15_ex_singleended.py
Error accessing 0x48: Check your I2C address
Error accessing 0x48: Check your I2C address
Traceback (most recent call last):
File "ads1x15_ex_singleended.py", line 38, in
volts = adc.readADCSingleEnded(0, gain, sps) / 1000
File "/home/pi/ADS1115/Adafruit_ADS1x15.py", line 223, in readADCSingleEnded
val = (result[0] << 8) | (result[1])
TypeError: 'int' object has no attribute 'getitem'
I read the comment in ADS1x15.py that states:
133 # Depending on if you have an old or a new Raspberry Pi, you
134 # may need to change the I2C bus. Older Pis use SMBus 0,
135 # whereas new Pis use SMBus 1. If you see an error like:
136 # 'Error accessing 0x48: Check your I2C address '
137 # change the SMBus number in the initializer below!
Although, I do not know what exactly what I am required to change.
I know it would be very difficult to diagnose my issue with only the information that I have provided, but I would greatly appreciate any help in troubleshooting this issue.
Thanks in advance for any help you may provide!
The error looks like the I2C device can't be found, possibly because the bus or wiring aren't right. One thing to check, take a look at the I2C on Pi guide to make sure all the I2C modules, etc. are enabled: https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c Also run both these commands with the device connected to inspect the I2C buses:
sudo i2cdetect -y 0
sudo i2cdetect -y 1
One of them should show a device with address 0x48, the default address of the ADS1115. If you don't see either of them with a 48 value then double check the wiring, power, ground, etc. are good. You'll need to make sure i2cdetect sees the device before the python code will work.
Then depending on the command that worked, the bus number to use is the value 0 or 1 in the working command. For example if i2cdetect -y 1 shows the 48 device then you want to use I2C bus 1. To change the bus you can modify the constructor right below those comments to look like:
self.i2c = Adafruit_I2C(address, busnum=1)
Swap the value 1 in the busnum parameter to 0 if you see your device on bus 0 with i2cdetect. Give that a shot and let me know if you still see issues.
Cleaning up old issues and I'll close this one for now. If you still run into issues, feel free to post on forums.adafruit.com where more folks can help troubleshoot.