How to Use ADS1115 ADC with Raspberry Pi: Simple Guide
To use the
ADS1115 ADC with a Raspberry Pi, connect it via I2C pins and use a Python library like Adafruit_ADS1x15 to read analog inputs. Initialize the ADC in your code, then read values from the desired channel using simple function calls.Syntax
Here is the basic syntax to read analog values from the ADS1115 using Python on Raspberry Pi:
import board, busio: Import I2C communication modules.from adafruit_ads1x15.ads1115 import ADS1115: Import the ADS1115 class.ads = ADS1115(i2c): Create an ADS1115 object using the I2C bus.chan = AnalogIn(ads, ADS1115.P0): Select the analog input channel (e.g., P0).value = chan.value: Read the raw ADC value.voltage = chan.voltage: Read the voltage converted from the raw value.
python
import board import busio from adafruit_ads1x15.ads1115 import ADS1115 from adafruit_ads1x15.analog_in import AnalogIn # Initialize I2C bus i2c = busio.I2C(board.SCL, board.SDA) # Create ADS1115 instance ads = ADS1115(i2c) # Create single-ended input on channel 0 chan = AnalogIn(ads, ADS1115.P0) # Read raw value and voltage raw_value = chan.value voltage = chan.voltage print(f"Raw ADC Value: {raw_value}") print(f"Voltage: {voltage:.3f} V")
Output
Raw ADC Value: 12345
Voltage: 1.234 V
Example
This example shows how to continuously read and print the voltage from channel 0 of the ADS1115 every second.
python
import time import board import busio from adafruit_ads1x15.ads1115 import ADS1115 from adafruit_ads1x15.analog_in import AnalogIn # Setup I2C and ADS1115 i2c = busio.I2C(board.SCL, board.SDA) ads = ADS1115(i2c) chan = AnalogIn(ads, ADS1115.P0) while True: print(f"Voltage on channel 0: {chan.voltage:.3f} V") time.sleep(1)
Output
Voltage on channel 0: 1.234 V
Voltage on channel 0: 1.230 V
Voltage on channel 0: 1.235 V
...
Common Pitfalls
- Incorrect wiring: Make sure SDA and SCL pins on the Raspberry Pi connect to the ADS1115 SDA and SCL pins.
- I2C not enabled: Enable I2C interface on Raspberry Pi using
raspi-config. - Wrong I2C address: ADS1115 default address is 0x48; check with
i2cdetect -y 1. - Missing libraries: Install
adafruit-circuitpython-ads1x15via pip. - Using wrong channel constants: Use
ADS1115.P0toADS1115.P3for single-ended inputs.
python
import board import busio from adafruit_ads1x15.ads1115 import ADS1115 from adafruit_ads1x15.analog_in import AnalogIn # Wrong: Using wrong channel constant # chan = AnalogIn(ads, 0) # This will cause error # Right: i2c = busio.I2C(board.SCL, board.SDA) ads = ADS1115(i2c) chan = AnalogIn(ads, ADS1115.P0) # Correct channel usage
Quick Reference
| Step | Description |
|---|---|
| Connect ADS1115 SDA to Raspberry Pi SDA (GPIO 2) | I2C data line connection |
| Connect ADS1115 SCL to Raspberry Pi SCL (GPIO 3) | I2C clock line connection |
| Enable I2C on Raspberry Pi | Use sudo raspi-config > Interface Options > I2C |
| Install Python library | pip3 install adafruit-circuitpython-ads1x15 |
| Write Python code | Import libraries, create ADS1115 object, read channels |
| Run script | Get voltage readings from analog sensors |
Key Takeaways
Connect ADS1115 to Raspberry Pi using I2C pins SDA and SCL correctly.
Enable I2C interface on Raspberry Pi before running code.
Use the Adafruit ADS1x15 Python library for easy ADC reading.
Read analog values by creating an AnalogIn object for the desired channel.
Check wiring and I2C address if readings are incorrect or errors occur.