ADC currently has three methods available. setup, read and read_raw. You'll need to ensure you use setup prior to reading, otherwise an error will be thrown.

ADC is available on only a few pins, as listed below:
"AIN4", "P9_33"
"AIN6", "P9_35"
"AIN5", "P9_36"
"AIN2", "P9_37"
"AIN3", "P9_38"
"AIN0", "P9_39"
"AIN1", "P9_40"
1.8V is the maximum voltage. Do not exceed 1.8V on the AIN pins! VDD_ADC (P9_32) provides 1.8V. Use GNDA_ADC (P9_34) as the ground.
An easy way to drop the 3.3V of your device to the required 1.8V would be by using resistor divider. Two identical resistors (10K to 100K) in series from your 3v analog signal to ground, then connect the analog input pin between the two. The divider will divide the 0 to 3.3v into 0-1.65V which gives you a little bit of headroom as well.

Setup

To setup ADC, simply import the module, and call setup:
import Adafruit_BBIO.ADC as ADC

ADC.setup()
Then, to read the analog values on P9_40, simply read them:
value = ADC.read("P9_40")
In addition to the key (above), you can also read using the pin name:
value = ADC.read("AIN1")
There is currently a bug in the ADC driver. You'll need to read the values twice in order to get the latest value.
The values returned from read are in the range of 0 - 1.0. You can get the voltage by doing the following:
import Adafruit_BBIO.ADC as ADC

ADC.setup()
value = ADC.read("P9_40")
voltage = value * 1.8 #1.8V
You can also use read_raw to get the actual values:
import Adafruit_BBIO.ADC as ADC

ADC.setup()
value = ADC.read_raw("P9_40")

This guide was first published on Jun 13, 2013. It was last updated on Mar 08, 2024.

This page (ADC) was last updated on Jun 24, 2013.

Text editor powered by tinymce.