--- ---

Analog Communication

19 Nov 2020 - William Salcedo

Raspberry Pis do not have the ability to input analog signals by themselves. Thus, we must use additional hardware to obtain analog data.

We have decided to use an ADC1115 IC, which makes use of I2C to communicate analog readings to the Raspberry Pi. For prototyping purposes we are using the Adafruit version of the IC, which conveniently includes male pin headers. The link to this device could be found here. During later renditions of the PCB, we will use the surface-mounted version of the chip.

Installing the ADS1115 and Enabling I2C

Using the Pi GPIO chart shown below, you should wire the “SCA” and “SDL” pins of the microcontroller and IC together. You should also wire the chip’s GND and VDD to a 5V supply. Pi GPIO

After doing this you need to enable I2C on the Raspberry Pi. If you were able to connect to VNC properly, navigate to Start > Preferences > Raspberry Pi Configuration > Interfaces. You should then enable I2C in that menu.

If you are using the console you should instead type:


sudo raspi-config

Then navigate to Interfacing Options > I2C.

After doing this, run the code below. This will install command-line I2C tools on your Raspberry Pi so we could see if the ADC1115 has connected properly:


sudo apt-get install -y i2c-tools

Now that you have i2c-tools installed, you could run the following code to check if the ADC1115 is detected by the microcontroller:


i2cdetect -y 1

It will print out the 1115’s address in hexadecimal and look something like this:

 
    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: 60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
 
 

Communicating with the ADS1115 Using Python

Now that you have successfully connected the ADC1115 to the Raspberry Pi, you could finally start to use it.

We will use the given Adafruit ADC1x115 library. Install it using the following command in console:


sudo pip install adafruit-ads1x15

Now you could use functions such as read_adc to read certain channels from the device. Here is an example using python:


from Adafruit_ADS1x15 import ADS1x15 as ADS

foo = ADS.ADS1015(0x48)
analogReading = foo.read_adc(0)