How to Measure TinyZero Battery Percent?

Started by bibletech55, April 07, 2025, 08:02:17 PM

Previous topic - Next topic

bibletech55

***
Full Member
Posts: 12
Roger roger - all 120 marching battle droids.
Logged
Hi there!

I have a TinyZero connected to a small LiPo battery. I would like to read the current capacity of the battery to the Serial Monitor. Since the board is based off of the Arduino Zero (and by extension, the MKR Zero), I sought to read the value of ADC_BATTERY and convert this value to my voltage reading. The following tutorial shows how to measure battery voltage using an MKR Zero. (https://projecthub.arduino.cc/Arduino_Genuino/mkr-zero-read-battery-voltage-e31f42)

When verifying the code for the TinyZero, I receive an error that tells me that ADC_BATTERY is not defined in this scope. However, if I verify the exact same code for an MKR Zero, I receive no compilation errors. Since they use the same processor (SAMD21), wouldn't both boards have an ADC_BATTERY pin, and potentially be able to use ADC_BATTERY the same way?

Thank you for any help!

MosheTreutel

*
Newbie
Posts: 1
Logged
You need to check which analog pin is connected to the LiPo battery. The LiPo battery is connected to the charging circuit and can be measured via an internal analog pin, namely pin A7.

bibletech55

***
Full Member
Posts: 12
Roger roger - all 120 marching battle droids.
Logged
Thank you for your reply! I took a look at the TinyZero schematic posted on the product page, but the only pins I see connected to the charging circuit are +5V, VBATT and GND.

How can I identify on the schematic which analog pin is connected to the battery charging circuit? I'd like to learn so I really understand!


rafaelakutch

*
Newbie
Posts: 1
Logged
Quote from: bibletech55 on April 07, 2025, 08:02:17 PMHi there!

I have a TinyZero connected to a small LiPo battery. I would like to read the current capacity of the battery to the Serial Monitor. Since the board is based off of the Arduino Zero (and by extension, the MKR Zero), I sought to read the value of ADC_BATTERY and convert this value to my voltage reading. The following tutorial shows how to measure battery voltage using an MKR Zero. (https://projecthub.arduino.cc/Arduino_Genuino/mkr-zero-read-battery-voltage-e31f42)
Sprunki Game
When verifying the code for the TinyZero, I receive an error that tells me that ADC_BATTERY is not defined in this scope. However, if I verify the exact same code for an MKR Zero, I receive no compilation errors. Since they use the same processor (SAMD21), wouldn't both boards have an ADC_BATTERY pin, and potentially be able to use ADC_BATTERY the same way?

Thank you for any help!
ADC_BATTERY is not a SAMD21 hardware feature but a board variant alias. MKR boards define ADC_BATTERY in their variant so analogRead(ADC_BATTERY) works. TinyZero's variant does not expose ADC_BATTERY so the symbol is undefined. Fix it by checking the TinyZero schematic to find the ADC pin used for battery sense and then use analogRead(thatPin) or add a simple resistor divider to a free analog pin and read that. See MKR variant examples and TinyZero docs for the pin/schematic references.

SMF spam blocked by CleanTalk