Beaglebone Black LESSON 9: Reading Analog Inputs from Python

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.)

Beaglebone Black Pinout
Default Pin Configuration for the Beaglebone Black Rev. C.

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:

A Simple Voltage Divider Using a Potentiometer

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.

 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.

9 thoughts on “Beaglebone Black LESSON 9: Reading Analog Inputs from Python”

  1. If you only want 4 digit values to print out, try this:
    print(‘%4.3f\t\t%4.2f’ % (potVal,potVolt))

    4 characters and the dot 3(.3) with the “f” is a format specifier!
    the \t is to Tab to next tab space.

  2. Thanks for the tutorials! My only suggestion for this is I didn’t understand how to wire up the potentiometer. The wiring diagram doesn’t show which potentiometer pin goes to which BBB pin. After some online research I was able to figure it out, but it seems that different models have different pin layouts. And this could very well be me as a beginner.

    1. Pretty much all potentiometers have three pins, with the middle pin being the one that you read from.

  3. I’m new to programming but I’m picking it up pretty well for an old dog. I’ve enjoyed your tutorials on arduino and BBB. I’ve found a jot or title off makes a big difference in programming success. However, I’ve entered it correctly but can’t get this one to work. This is error code I get: line 6, in
    I don’t see any errors?
    What is wrong?

  4. Hello
    i am very interesting in using beaglebone black in my project.
    i need to drive 24 V DC motor (about 8 amp) .
    What motor drive do you recommend to use with Beaglebone black ?
    Also i want capability to increase -decrease RPM of 24V DC motor.
    From 0 rpm to 180 RPM. Maybe use Potentiometer and range from 0 to 3.3 v .
    motor should start spin when digital signal 5 V DC in to one pin.
    motor should stop spin when digital signal 5 V DC in to another pin.
    when both pin get 5 v dc – set up Alarm stop process.

    it is not all but about most of my project.

    thank you

  5. Awesome. since it is capable of reading analog input. Is it possible to display analog signal just like the oscilloscope do? I am curious and I wanted to build one using beaglebone black.

Comments are closed.