Introduction
Learn how to use ADS1115 16-bit ADC With Raspberry Pi. In this tutorial, we will be using the ADS1115 16-bit ADC with the Raspberry Pi to read an analog value from a sensor. ADS1115 is a useful device to read multiple analog sensors with the Raspberry Pi, Arduino, or another microcontroller. We’ll be using the ADS1x15 library to control the ADC.
The GPIO pins on the Raspberry Pi are designed to output a digital signal of either high or low or to read a digital input of either high or low.
However, by using an external analog-to-digital converter (ADC) chip, such as the ADS1115, it is possible to read the values of analog input devices, such as potentiometers, and convert them into digital signals.
ADS1115 ADC allows us to interface analog sensors with digital systems. Many sensors, e.g. temperature and light sensors, produce analog signals. ADC is required to process these signals and convert analog input signals into digital data that can be processed by Raspberry Pi or any microcontroller.
Required Material
- Raspberry Pi 4 (or any model)
- ADS1115 16-bit ADC module
- Breadboard
- Jumper wires
- 10kΩ Potentiometer (or any analog sensor)
ADS1115 ChipÂ
The ADS1115 chip is a high-accuracy, low-power, 16-bit Analog-to-Digital Converter (ADC) chip. It is manufactured by Texas Instruments and it was developed to provide accurate and reliable measurements of analog signals.
SpecificationÂ
- Supply Voltage: 2.0-5.5 VDC
- 16-bit Resolution
- Continuous current consumption: 150uA
- 4 channels in individual mode, 2 channels in comparator mode
- Communication interface: I2C
- The internal stabilized reference voltage (Vref)
- Programmable Comparator
- Programmable Data Rate: 8sps To 860sps
- Internal Oscillator
- Internal PGA (Programmable Gain Amplifier).
- Pin-selectable Addresses
- Four Single-ended Or Two Differential Inputs
- Programmable Comparator
- Operating Temperature Range: –40°C to +125°C
- Single-Cycle Settling
ADS1115 Chip Pinout
Pin Number | Pin Name | Function |
---|---|---|
1 | ADDRESS | I2C slave address select |
2 | ALERT | Comparator output |
3 | GND | Ground |
4 to 7 | AIN0 to AIN3 | Analog input channels 0-3 |
8 | VDD | Power supply |
9 | SDA | Serial data |
10 | SCL | Serial clock input. |
ADS1115 16-bit ADC module
ADS1115 16-bit ADC module is a small electronic device that allows you to convert analog signals to digital signals. ADS1115Â has four analog input channels(A0-A3), which means it can measure up to four different analog signals.
ADS1115 uses the I2C communication protocol to communicate with the Raspberry Pi or other microcontroller. This means that it can be easily attached to your tasks. it has a high resolution of 16 bits, which means it can measure analog signals with very high accuracy.
You may want to see our last post for more detailed information.
- How to Interface ADS1115 16-Bit ADC with Arduino
- Interfacing ADS1115 Analog-to-Digital Converter with Raspberry Pi Pico
- How to Interface ADS1115 16-Bit ADC with ESP8266
- How To Use ADS1115 16-Bit ADC with ESP32
ADS1115 16-bit ADC module Pinout
The ADS1115 16-bit ADC module has 10 pins in total. Here is a brief overview of the pinout:
- VDD: Power supply voltage input (3.0V to 5.5V).
- SCL: Serial clock pin used for I2C communication.
- SDA: Serial data pin used for I2C communication.
- GND: Ground pin.
- ADDR: Address pin used to set the I2C address of the module.
- ALERT: Alert pin that can be used to trigger an interrupt.
- A0: Analog input channel 0.
- A1: Analog input channel 1.
- A2: Analog input channel 2.
- A3: Analog input channel 3.
ADS1115 Module Schematic Diagram
ADS115 Input Mode
The 4 inputs can be operated in 3 different modes.
- Single-Ended Mode
- Comparator Mode
- Differential Mode
ADS1115 I2C Address Selection
You can go through the available addresses by connecting the ADDR pin as noted below. The board already has a pull-down resistor that controls ADDR to GND which defines the default address of 0x48.
DDR Pin Connection | I2C Address |
---|---|
GND | 0x48 (Already) |
VDD | 0x49 |
SDA | 0x4A |
SCL | 0x4B |
Interfacing ADS1115 16-Bit ADC with Raspberry Pi
Connect the ADS1115 to Raspberry Pi using I2C communication. then connect VCC and GND pins to the 3.3V and GND pins of the Raspberry Pi, respectively.
ADS1115 | Raspberry Pi |
---|---|
VDD | 3.3V |
GND | GND |
SCL | SCL (GPIO3) |
SDA | SDA (GPIO2) |
Configuring Raspberry Pi To Use ADS1115
Install ADS1115 python library for Raspberry PiÂ
To install the required library for the ADS1115 module follow these steps:
- Open a terminal window on your Raspberry Pi.
- Run the following command to install the ADS1x15 Python library.
1 |
sudo pip3 install adafruit-circuitpython-ads1x15 |
That’s it! You now have the required library installed.
Enabling I2C communication
Enable I2C on the Raspberry Pi by running the following command in the terminal
1 |
sudo raspi-config |
Then select “Interfacing Options” -> “I2C” -> “Yes” to enable I2C.
Testing I2C communication
Use i2cdetect
command to verify that ADS1115 is detected on the I2C bus. Run the following command in the terminal:
1 |
sudo i2cdetect -y 1 |
The ADS1115 module should show up at address 0x48.
Python code for reading analog values Using ADS1115 & Raspberry Pi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import board import busio import adafruit_ads1x15.ads1115 as ADS from adafruit_ads1x15.analog_in import AnalogIn # Initialize the I2C interface i2c = busio.I2C(board.SCL, board.SDA) # Create an ADS1115 object ads = ADS.ADS1115(i2c) # Define the analog input channel channel = AnalogIn(ads, ADS.P0) # Loop to read the analog input continuously while True: print("Analog Value: ", channel.value, "Voltage: ", channel.voltage) |
Working – ADS1115 16-Bit ADC with Raspberry Pi
This code continuously reads the value and voltage of the analog input channel A0.
Python Code for Read Multiple Analog Values Using ADS1115 & Raspberry Pi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import board import busio import adafruit_ads1x15.ads1115 as ADS from adafruit_ads1x15.analog_in import AnalogIn import time # Initialize the I2C interface i2c = busio.I2C(board.SCL, board.SDA) # Create an ADS1115 object ads = ADS.ADS1115(i2c) # Define the analog input channels channel0 = AnalogIn(ads, ADS.P0) channel1 = AnalogIn(ads, ADS.P1) channel2 = AnalogIn(ads, ADS.P2) channel3 = AnalogIn(ads, ADS.P3) # Loop to read the analog inputs continuously while True: print("Analog Value 0: ", channel0.value, "Voltage 0: ", channel0.voltage) print("Analog Value 1: ", channel1.value, "Voltage 1: ", channel1.voltage) print("Analog Value 2: ", channel2.value, "Voltage 2: ", channel2.voltage) print("Analog Value 3: ", channel3.value, "Voltage 3: ", channel3.voltage) # Delay for 1 second time.sleep(1) |
Result
After running the above code in Raspberry Pi, the module is ready for testing. For this test, we will need a multimeter. The Python shell will display the ADC Value and measured Voltage & analog value.
By following the steps in this article, you can easily get started using ADS1115 with Raspberry Pi to read analog values.