Skip to content

Instantly share code, notes, and snippets.

@ScienceElectronicsFun
Last active February 15, 2023 11:50
Show Gist options
  • Save ScienceElectronicsFun/3fb4ea625e14f428d21e07e918fe75d8 to your computer and use it in GitHub Desktop.
Save ScienceElectronicsFun/3fb4ea625e14f428d21e07e918fe75d8 to your computer and use it in GitHub Desktop.
Code for rasperry pi pico; reads ADS1015 ADC from Adafruit using I2C; calibrated for pressure sensor 4-20 mA
#Modified from https://learn.adafruit.com/raspberry-pi-analog-to-digital-converters/ads1015-slash-ads1115
import time
import Adafruit_ADS1x15_modified as Adafruit_ADS1x15
adc = Adafruit_ADS1x15.ADS1x15()
print('Reading ADS1x15 values, press Ctrl-C to quit...')
# Print nice channel column headers.
print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*range(4)))
print('-' * 37)
# Main loop.
GAIN = 1
while True:
# Read all the ADC channel values in a list.
values = [0]*4
for i in range(4):
# Read the specified ADC channel using the previously set gain value.
values[i] = adc.readADC(channel = i)#, gain=GAIN
# Note you can also pass in an optional data_rate parameter that controls
# the ADC conversion time (in samples/second). Each chip has a different
# set of allowed data rate values, see datasheet Table 9 config register
# DR bit values.
#values[i] = adc.read_adc(i, gain=GAIN, data_rate=128)
# Each value will be a 12 or 16 bit signed integer value depending on the
# ADC (ADS1015 = 12-bit, ADS1115 = 16-bit).
# Print the ADC values.
print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*values))
voltage = values[3] / 1000.0
psi = voltage * 104.1666667 - 75
print(str(voltage) + ' V')
print(str(psi) + ' psi')
# Pause for half a second.
time.sleep(0.5)
@underwater2003
Copy link

Where can i find Adafruit_ADS1x15_modified?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment