0% found this document useful (0 votes)
49 views

Experiment 7 MSK Raspberry Oscilloscope

This document provides instructions to connect an ADS1115 16-bit ADC to a Raspberry Pi and write a Python code to use the ADC as an oscilloscope. It involves enabling I2C on the Pi, installing required libraries like Adafruit_ADS1x15, matplotlib and drawnow. The Python code reads analog values from channel 0 of the ADC in a loop, stores it and plots it live using matplotlib to visualize the waveform.

Uploaded by

Manoj Kavedia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Experiment 7 MSK Raspberry Oscilloscope

This document provides instructions to connect an ADS1115 16-bit ADC to a Raspberry Pi and write a Python code to use the ADC as an oscilloscope. It involves enabling I2C on the Pi, installing required libraries like Adafruit_ADS1x15, matplotlib and drawnow. The Python code reads analog values from channel 0 of the ADC in a loop, stores it and plots it live using matplotlib to visualize the waveform.

Uploaded by

Manoj Kavedia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

ADS115 ADC interface

with RPi
Er. Manoj S. Kavedia
www.kaizenfuturetech.com
www.kavediasir.yolasite.com
9324258878 / 8329988738
Raspberry Pi PinOut
Connection
ADS1115 and Raspberry Pi Connections:
VDD – 3.3v
GND – GND
SDA – Pin3 - SDA
SCL –Pin5 - SCL

ADS1115 16-Bit ADC - 4 Channel with Programmable Gain Amplifier


The chip can be configured as
 4 single-ended input channels, or
 two differential channels
Pi CRO
Installation Steps
Step 1: Enable Raspberry Pi I2C interface
To enable the I2C, from the terminal, run;

$ sudo raspi-config

• When the configuration panels open,


• select interface options,
• select I2C and
• click enable.

Step 2: Update the Raspberry pi


$ sudo apt-get update
$ sudo apt-get upgrade
Enable I2C interface
Installation
Step 3: Install the Adafruit ADS1115 library for ADC
Ensure you are in the Raspberry Pi home directory

$ cd ~

install the build-essentials

$ sudo apt-get install build-essential python-dev python-smbus git

Next, clone the Adafruit git folder for the library

$ git clone https://github.com/adafruit/Adafruit_Python_ADS1x15.git

Change into the cloned file’s directory and run the setup file

$ cd Adafruit_Python_ADS1x1z sudo python setup.py install


Installation
After installation, your screen should look like the image below.
Installation
Step 4: Test the library and 12C communication.
Ensure the ADC can communicate with the raspberry pi over I2C.

While still in the Adafruit_Python_ADS1x15 folder, change directory to the


examples directory by running;

cd examples
Run the sampletest.py example which displays the value of the four channels
on the ADC in a tabular form.

python simpletest.py
Installation Steps
If the I2C module is enabled and connections good, you should see the data as
shown in the image below

If an error occurs, check to ensure the ADC is well connected to the PI and I2C
communication is enabled on the Pi.
Installation Steps
Step 5: Install Matplotlib
To visualize the data, install the matplotlib module which is used to plot all
kind of graphs in python. This can be done by running;’

sudo apt-get install python-matplotlib


Installation Steps
You should see an outcome like the image below.
Installation Steps
Step6: Install the Drawnow python module

Lastly, we need to install the drawnow python module. This module helps us
provide live updates to the data plot.
We will be installing drawnow via the python package installer; pip, so we
need to ensure it is installed. This can be done by running;

sudo apt-get install python-pip

We can then use pip to install the drawnow package by running:

sudo pip install drawnow


Installation Steps
You should get an outcome like the image below after running it.

With all the dependencies installed, we are now ready to write the code.
Python Code
Python Code for Raspberry Pi Oscilloscope:
import time
import matplotlib.pyplot as plt
#import numpy
from drawnow import *

# Import the ADS1x15 module.


import Adafruit_ADS1x15

# Create an ADS1115 ADC (16-bit) instance.


adc = Adafruit_ADS1x15.ADS1115()
GAIN = 1
val = [ ]
cnt = 0
plt.ion()

# Start continuous ADC conversions on channel 0 using the previous gain value.
adc.start_adc(0, gain=GAIN)
print('Reading ADS1x15 channel 0')
Python Code
#create the figure function
def makeFig():
plt.ylim(-5000,5000)
plt.title('Osciloscope')
plt.grid(True)
plt.ylabel('ADC outputs')
plt.plot(val, 'ro-', label='Channel 0')
plt.legend(loc='lower right')
while (True):
# Read the last ADC conversion value and print it out.
value = adc.get_last_result()
print('Channel 0: {0}'.format(value))
# Sleep for half a second.
time.sleep(0.5)
val.append(int(value))
drawnow(makeFig)
plt.pause(.000001)
cnt = cnt+1
if(cnt>50):
val.pop(0)
Enjoys Waveform!!!!
Er. Manoj S. Kavedia

Contact on Watsapp to join Students Forum : 9324258878

You might also like