Brandon222
Posts: 12
Joined: Mon Oct 19, 2015 5:17 pm

Reading Voltage

Mon Oct 19, 2015 5:36 pm

I am new to Raspberry Pi and just got my self a new one. I have installed raspian OS on it. My plan is to plug a power source into one of the GPIO pins and read the voltage. Is this possible?

Ex. Get the voltage of USB of a TV and read it to the Raspberry Pi.

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: Reading Voltage

Mon Oct 19, 2015 5:50 pm

Reading voltage requires an analog input and the RPi doesn't have any analog inputs. You'd need an analog to digital converter (ADC) or a microcontroller to read the varying voltage and then pass that information to the RPi.

User avatar
rpdom
Posts: 17173
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Reading Voltage

Mon Oct 19, 2015 5:53 pm

The GPIO pins are digital, not analogue, and can not measure voltages without an external ADC.

Also they work at 3.3V logic levels. Putting 5V from a USB supply into them will kill the GPIO and probably the Pi.

Brandon222
Posts: 12
Joined: Mon Oct 19, 2015 5:17 pm

Re: Reading Voltage

Mon Oct 19, 2015 7:53 pm

Thank you for your replys. ADC seems the way to go from what I can read online. Any suggestions on ones. And cheaper would be better. Also I am assuming there is a command like read voltage to actually read the value from the GPIO?

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Reading Voltage

Mon Oct 19, 2015 8:28 pm

The Microchip MCP3002 two channel, 10-bit SPI ADC is cheap (£1.22), is easy to program and works well.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Brandon222
Posts: 12
Joined: Mon Oct 19, 2015 5:17 pm

Re: Reading Voltage

Mon Oct 19, 2015 9:15 pm

Excellent. I am currently looking into that now. My last question I have is what command can I use to show the value of the GPIO input?

Brandon222
Posts: 12
Joined: Mon Oct 19, 2015 5:17 pm

Re: Reading Voltage

Tue Oct 20, 2015 11:50 pm

So I bought myself one of these

https://www.creatroninc.com/product/pcf ... &results=1

I have been doing some research and turns that for what I need I can connect the voltage of the USB port into the VCC and than I would connect my raspberry PI to AOut? is this correct?

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Reading Voltage

Wed Oct 21, 2015 9:32 am

Brandon222 wrote:So I bought myself one of these

https://www.creatroninc.com/product/pcf ... &results=1

I have been doing some research and turns that for what I need I can connect the voltage of the USB port into the VCC and than I would connect my raspberry PI to AOut? is this correct?
Nope.

You would connect the PCF8591 to the Pi by i2c (SDA and SCL, 0v and 3v3 (Vcc)).

You will need to use a voltage divider to ensure that the voltage you are measuring is scaled to the range of 0v (minimum) to 3V3 (maximum) so that it can be read by the ADC. The voltage input would go to the Ain.
Doug.
Building Management Systems Engineer.

Brandon222
Posts: 12
Joined: Mon Oct 19, 2015 5:17 pm

Re: Reading Voltage

Wed Oct 21, 2015 1:52 pm

Thank you for getting back to me and explaining it to me so well. Now if I only needed to know if power was in or not would I still need the voltage divider. What I mean to say is I dont specifically need to know how much power is going in rather if there is or not. So like a boolean.

User avatar
mikronauts
Posts: 2783
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Reading Voltage

Wed Oct 21, 2015 2:52 pm

Yes, you still need the voltage divider.
Brandon222 wrote:Thank you for getting back to me and explaining it to me so well. Now if I only needed to know if power was in or not would I still need the voltage divider. What I mean to say is I dont specifically need to know how much power is going in rather if there is or not. So like a boolean.
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

Brandon222
Posts: 12
Joined: Mon Oct 19, 2015 5:17 pm

Re: Reading Voltage

Wed Oct 21, 2015 3:36 pm

Ok that makes sense. My final question and I'm sorry I've been asking a lot. In terms of reading the GPIO. I'm assuming I would need to read GPIO 3. I would first need to make GPIO 3 and input using the command GPIO.setup(3, input)

But than to read it what would it be?

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Reading Voltage

Thu Oct 22, 2015 8:02 am

Brandon222 wrote:Ok that makes sense. My final question and I'm sorry I've been asking a lot. In terms of reading the GPIO. I'm assuming I would need to read GPIO 3. I would first need to make GPIO 3 and input using the command GPIO.setup(3, input)

But than to read it what would it be?

To read the voltage level?

You would communicate with the i2c PCF8591, you would need to pick a programming language (Python or C perhaps) and modify some sample code.

Here is a guide by Grumpy Mike on communicating with a PCF8591.
Doug.
Building Management Systems Engineer.

RetiredProgrammer
Posts: 14
Joined: Sat Jan 10, 2015 10:42 pm

Re: Reading Voltage

Fri Oct 23, 2015 3:51 am

Brandon222 wrote:Thank you for getting back to me and explaining it to me so well. Now if I only needed to know if power was in or not would I still need the voltage divider. What I mean to say is I dont specifically need to know how much power is going in rather if there is or not. So like a boolean.
If you are only interested in a yes /no response you do not need an ADC. You still need the voltage divider but the digital pin on the GPIO can be read.

boyoh
Posts: 1468
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Reading Voltage

Sun Oct 25, 2015 10:42 am

Using a potential devider is is all well and good., providing the the desinged out/put voltage

of the devider don't go above the 3.3v GPIO in/put. This can appen if the voltage fluxuates

above the the desinged voltage across the potenstial devider. One possible alternative

could be a Zener diode ( This is only ok if you want to know if there is volt or no volts )
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

Return to “Beginners”