0

QT PY - reading voltage from A2
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

QT PY - reading voltage from A2

by imgodot on Sat May 14, 2022 9:17 pm

I have a QT PY and the lipoly breakout board and the 3.7V battery from Adafruit.

I want to display the power source and voltage.
My code below reads the A2 pin.

With the USB powering things, the "voltage" reads 3.62.
When the battery is powering it, the "voltage" reads 3.05.

The breakout board text stated anything over 4.7 V was USB.
Does that mean my USB is outputting less voltage or an I determining the voltage incorrectly?

Code: Select all | TOGGLE FULL SIZE
  int sensorValue = analogRead(A2);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.println(voltage); 

imgodot
 
Posts: 12
Joined: Fri Apr 15, 2022 9:36 am

Re: QT PY - reading voltage from A2

by neradoc on Sat May 14, 2022 10:14 pm

Hmmmm according to the schematic, the pin is connected via a 100k/100k voltage divider, so divided by two.
And since the QT PY is a 3.3V device, that means that 3.3V = 1023.

So math math math and: V = analog_read * 2 * 3.3 / 1023 if I'm not mistaken.
Your 3.62 turns into 4.78. Not quite 5V but above the threshold.

That is, if my EE and math are not failing me (or me failing them).

neradoc
 
Posts: 174
Joined: Wed Apr 27, 2016 2:38 pm

Re: QT PY - reading voltage from A2

by imgodot on Sun May 15, 2022 12:58 pm

Nera,

Thanks for the help.
It appears to work as expected.

-- Paul

imgodot
 
Posts: 12
Joined: Fri Apr 15, 2022 9:36 am

Please be positive and constructive with your questions and comments.