🇺🇸Adafruit will not be shipping orders on Independence Day Monday 7/4/2022. Please allow extra time for your order to ship and plan accordingly.🇺🇸

QT PY - reading voltage from A2

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

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

Posts: 186
Joined: Wed Apr 27, 2016 2:38 pm

Re: QT PY - reading voltage from A2

Nera,

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

-- Paul

imgodot

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