Read voltage from ADC using an external power supply

Hi All,

I have a new BBB. I’m trying to read voltages from a DC power supply. I’m having trouble doing so. I connected the output from the power supply to AIN0, and the ground from the power supply to the ADC_GND, and tried to run the code, but the voltages that I’m reading doesn’t make sense.

So I went back to the basic, and just ran the code without plugging anything in, and yet the voltage value I’m printing says 1.6 instead of 0. Below shows the code, which I got from adafruit. I’m aware that I’m not supposed to connect BBB ADC to anything above 1.8V or below 0V, which I don’t believe I have.

import Adafruit_BBIO.ADC as ADC
ADC.setup()
value = ADC.read(“P9_40”)
voltage = value * 1.8
print (voltage)

I’ve also been reading somewhere that I may have to enable the ADC before I can read it??

Help?

Thanks.

I have a new BBB. I’m trying to read voltages from a DC power supply. I’m having trouble doing so. I connected the output from the power supply to AIN0, and the ground from the power supply to the ADC_GND, and tried to run the code, but the voltages that I’m reading doesn’t make sense.

What voltage is the external DC power supply ? Unless the dc power supply voltage is 1.8v then voltage = value * 1.8 will not make sense.

How this works is voltage = value * scale, where scale is the external voltage to be measured. So for example if your external powr supply is 12v, then scale would be 12.0. Just to make sure it is understood however, the input voltage to the ADC pins must never exceed 1.8v, or you risk at minimum burning out that pin.

What voltage is the external DC power supply ? Unless the dc power supply voltage is 1.8v then voltage = value * 1.8 will not make sense.

Sorry this is wrong. Values read out of the ADC are in range of 0 to 4095. so . . .

voltage = ( value / 4096 ) * scale

Chelsea, As was mentioned, the BBB input pins can’t be more than 1.8V so you will need a voltage divider to take your power supply voltage down between 0 and 1.8V.
This page might help you: http://www.alfonsomartone.itb.it/hclbmf.html

And it is possible you have already damaged that pin if you connected up anything more than 1.8V so when you make your resistor divider circuit and try it, if it doesn’t work, try another ADC input pin. Also test the divider circuit with a volt meter first to be sure the max voltage of your power supply presents a max of 1.8V on the voltage divider circuit.

Doug

Hi Chelsea Orefice!

1V6 at an open pin looks good. AIN7 is connected to 1V65 at the board (half of power line) and that voltage pulls up the other pins, when open. When connecting P9_40 to ADC_GND you should see a values close to zero.

You could use the libpruio example oszi to study the ADC behaviour.

BR

So I went back to the basic, and just ran the code without plugging anything in, and yet the voltage value I’m printing says 1.6 instead of 0. Below shows the code, which I got from adafruit. I’m aware that I’m not supposed to connect BBB ADC to anything above 1.8V or below 0V, which I don’t believe I have.

Ok, somehow I managed to miss this paragraph when I first posted. So Chelsea, if you have not enabled the internal pulldown for the ADC pin in question, where you’re getting 1.6v. That makes perfect sense. These pins will return a value in the mid to high range values when left floating. Typically when I did experimentation I would read between 2500’s and 4500’s.

I’ve also been reading somewhere that I may have to enable the ADC before I can read it??

I really do not see how you can be getting any values out of the ADC at all if it’s not already enabled. ut here is a short “primer” I wrote concerning the onchip ADC: http://www.embeddedhobbyist.com/2015/10/beaglebone-black-adc/

Typically when I did experimentation I would read between 2500’s and 4500’s.

typo . . should be 3500’s and that is out of 4095 possible as max value for the onchip ADC.

@ William: you missed more than a paragraph.

Thank you all for helping out. The clarification is much appreciated. I am also wondering if there is anyway to reset the bbb without using an sd card? I was working on trying to enable the SPI on the bbb, but now think I might have damaged something since it's not able to be detected by my pc...