BFF for QT Py not reading battery voltage

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
CR34T0R
 
Posts: 24
Joined: Wed Aug 31, 2022 8:58 am

BFF for QT Py not reading battery voltage

Post by CR34T0R »

Hello,

I'm reading A2 on the LiPoly Charger BFF Add-On for QT Py

With the following code:

Code: Select all

def get_voltage(pin):
    return (pin.value * 3.3) / 65536
And I'm getting:
2.20188V
While plugged in, also when unplugged voltage doesn't seem right.

Not sure what I'm doing wrong, I double checked everything.

qtpy and bff are connected with the suggested female header method, picture attached.
Attachments
IMG_9292.jpeg
IMG_9292.jpeg (690.6 KiB) Viewed 105 times

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: BFF for QT Py not reading battery voltage

Post by dastels »

The voltage divider that A2 is connected to halves the voltage, so that what's on A2 will be less than 3.3v as required by the ADC. To compensate, double the result.

From https://learn.adafruit.com/adafruit-qt-py-charger-bff:
A simple voltage divider on the cathode side of the diode and connected to pin A2 will let your firmware detect basic modes: if the voltage is over 4.3V, it is probably plugged into USB. If the voltage is 4.2V or below its probably running on the Lipoly battery and you can roughly determine the battery state.
Dave

User avatar
CR34T0R
 
Posts: 24
Joined: Wed Aug 31, 2022 8:58 am

Re: BFF for QT Py not reading battery voltage

Post by CR34T0R »

Makes a lot of sense, missed that completely.

Thank you!

User avatar
CR34T0R
 
Posts: 24
Joined: Wed Aug 31, 2022 8:58 am

Re: BFF for QT Py not reading battery voltage

Post by CR34T0R »

dastels wrote: Thu Sep 22, 2022 9:58 am The voltage divider that A2 is connected to halves the voltage, so that what's on A2 will be less than 3.3v as required by the ADC. To compensate, double the result.
Dave
[/quote]

I ended up multiplying for 2.2 for correction calibrating the LC709203F battery gauge and a fully charged battery.

The lack of precision is to be expected I guess.

Is my compensation correct?

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: BFF for QT Py not reading battery voltage

Post by dastels »

It will vary a bit due to resistor tolerances. The main goal for reading it on A2 is to be able to tell whether power is from USB or battery.

Dave

User avatar
CR34T0R
 
Posts: 24
Joined: Wed Aug 31, 2022 8:58 am

Re: BFF for QT Py not reading battery voltage

Post by CR34T0R »

dastels wrote: Thu Sep 22, 2022 3:34 pm It will vary a bit due to resistor tolerances. The main goal for reading it on A2 is to be able to tell whether power is from USB or battery.

Dave
Got it, thanks.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”