Close

ADC - Analog to Random Number Converter

A project log for Raspberry Pi Glucometer

A programmable glucometer powered by a Raspberry Pi Zero

jonathan-buchananJonathan Buchanan 07/27/2016 at 21:590 Comments

My ADC arrived the other day. ADC stands for analog to digital converter and it converts voltage into a number readable by a computer. Basically a voltmeter. Its function in the meter is to read the voltage outputted by the amps, which are fed by a tiny current from the electro-chemical reaction in the test strip. The voltage should be proportional to the glucose concentration, though the exact number depends on the gain of all the amps in the circuit.

Since my pi zero hasn't arrived yet, I instead unplugged the barometer from from balloon computer's i2c poins (check out my other project) and downloaded adafruit's libraries.

Not knowing what to expect I hesitantly peeked into one of the example files.

# Simple demo of reading each analog input from the ADS1x15 and printing it to
# the screen.
# Author: Tony DiCola
# License: Public Domain
import time

import Adafruit_ADS1x15

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

# Choose a gain of 1 for reading voltages from 0 to 4.09V.
# Or pick a different gain to change the range of voltages that are read:
#  - 2/3 = +/-6.144V
#  -   1 = +/-4.096V
#  -   2 = +/-2.048V
#  -   4 = +/-1.024V
#  -   8 = +/-0.512V
#  -  16 = +/-0.256V
GAIN = 1

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.
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.read_adc(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 16 bit signed integer
    # Print the ADC values.
    print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*values))
    # Pause for half a second.
    time.sleep(0.5)

Looked simple enough.

Feeling more confidant, I hooked the pi's 3.3v pin to the ADC's A0 pin.

I then ran simpletest.py. The result was an string of numbers around 13000, give or take a few hundred. I disconnected the pin and they all went to 0, so something was definitely happening.

I played with the gain a bit and got the numbers to change a little, but when I set it at 2/3 and hooked up the 5v pin (the code above says 2/3 reads up to 6.144) the program crashed. Still need to look into that.

Emboldened by success, I ran another 3.3v pin to A1 and started up differential.py. In the schematic I discovered in the last post, there are two ADC inputs, which I assume means I need to find the difference between them.

Interestingly, though not altogether surprisingly, though the pins on the raspberry pi fluctuate slightly in voltage, they always changed together so that the difference was always -1.

Trying to hook the 5v up to either pin still crashed the program, even while subtracting.

Discussions