If you went through our series of lesson on the Raspberry Pi, you will remember that we found the major limitation of the Pi is that it has no analog input pins. Luckily, the Beaglebone Black as a number of analog input pins, so we can greatly expand the scope of projects we can do. The pinout below shows the pins that are available on the Beaglebone Black for analog input. (If you do not already have your Beaglebone Black, you can pick one up HERE.)
You can see the blue shaded pins in the diagram above are for analog input.
A couple of very important points. These pins are designed to read analog voltages between 0 and 1.8 volts. Applying voltages above 1.8 volts can burn out the pin, or even smoke the Beaglebone. Hence, as you set up voltage divider circuits you must ensure they have a rail of 1.8 Volts, to ensure that the analog in pins will never see more than 1.8 Volts. Luckily, the Beaglebone provides a handy 1.8 Volt reference signal on pin 32 (on P9 header). Always use pin 32 as your reference rail when working with analog inputs. Similarly, you should use pin 34 (on P9 header) as your reference ground on your analog input circuits.
To demonstrate how to do analog reads, we will set up a simple voltage divider using a potentiometer. Go ahead and hook up your circuit as follows:
Note we are using P9_32 as the reference voltage on the voltage divider, we are using P9_34 as the reference ground, and we are using P9_33 as the analog sense pin.
With this circuit hooked up we are ready to develop some code. In the attached video we take you through this program step-by-step to show you how you can make analog readings from the potentiometer using python.
1 2 3 4 5 6 7 8 9 | import Adafruit_BBIO.ADC as ADC ADC.setup() from time import sleep analogPin="P9_33" while(1): potVal=ADC.read(analogPin) potVolt=potVal*1.8 print "The Potentiometer Voltage is: ",potVolt sleep(.5) |
Note the analog read returns a number between 0 and 1, which is proportional to the applied voltage. Hence to convert to actual voltage, we multiply this read value by 1.8 Volts.