The Raspberry Pi connects to external devices using GPIO pins. In order for the Pi to make sense of the new input, we will need to use an analog-to-digital converter, or “ADC”, chip to convert the analog input into a readable digital format. The chip serves as a kind of translator, letting us call the potentiometer input in our own custom code.
In this guide, I’m using an Adafruit 1015 ADC chip. The chip arrives with an assortment of pins that need to be soldered into place. Carefully solder the pins to the ADC chip.
In order for the Raspberry Pi to talk to the chip, we need to enable I2C. Connect to the Pi using a terminal and run the following two commands. This will install the I2C tool we need to proceed.
sudo apt-get install -y python-smbus sudo apt-get install -y i2c-tools
Open the Raspberry Pi configuration menu using the following string.
Newer versions of the Pi will have an option called Interfacing Options. Older editions use the Advanced Options selection to reach the I2C settings. Using the appropriate menu screen, enable I2C on the Raspberry Pi.
Now it's time to wire up our freshly soldered ADC chip. Be sure to power off your Raspberry Pi with the following command.
To help showcase the connections we're making, I'm using a breadboard with a Raspberry Pi GPIO breakout board attachment. This makes it much easier to highlight individual connections. This step contains instructions for the ADS1015 chip. If you’re using a different ADC chip, you will need to search for proper wiring steps from the manufacturer.
The following points on the ADC chip are listed with their respective Pi connection points. We only need 4 male to male jumper wires for this step.
The ADC chip I'm using for this guide requires a specific Python library from Adafruit. This step contains installation instructions for ADS1015 and ADS1115 chips. If you're using a different ADC chip, you will need instructions specific to your device. Check with the manufacturer and research online to find the library you need.
Power on the Pi and run the appropriate script for your ADC chip library. If you’re using an ADS1015 or ADS1115, run the following commands.
sudo apt-get update sudo apt-get install build-essential python-dev python-smbus git cd ~ git clone https://github.com/adafruit/Adafruit_Python_ADS1x15.git cd Adafruit_Python_ADS1x15 sudo python setup.py install
Power off the Raspberry Pi using the following command.
The potentiometer I’m using in the example has three prongs. The center prong will be connected to the ADC chip. The outer prongs are for +/- power. Using three female to male jumper wires, connect the potentiometer to the Raspberry Pi. The following table highlights the appropriate connection for the ADS1015 chip.
In order to test our setup, we'll be using the example files provided by Adafruit. Navigate to the examples folder using the following command.
This step includes information for the ADS1115 chip. The Adafruit website contains additional information about modifying the test file for the ADS1015 chip.
Run the following script to initiate the test file.
sudo python simpletest.py
Rotating the potentiometer knob should generate a visible change in the readout from the Pi. Congratulations! Your Pi projects can be customized like never before. Not sure where to start? Check out our awesome Raspberry Pi guides for inspiration!
Nothing can slow down the Raspberry Pi Foundation, as even in 2021, the team managed to serve up a selection of new Raspberry Pi boards, modules, and fun accessories.