Stick Lite V3 battery voltage

As far as I can tell, to read the Lipo battery voltage, I enable the Vext pin( digitalWrite(36, LOW) ) in setup(), then do analogRead’s on pin 1. But this just seems to give a floating voltage value, ie. it varies greatly each time I run the code. (I also have adcAttachPin(1) in setup()).

On the Stick Lite V2, this all worked fine, but with Vext on pin 21, and analogReads on pin 37.

Look at the electrical diagram
You need to use Pin 37 “ADC CTRL”
digitalWrite(37, LOW );

1 Like

Thanks for that. Works now.

Can you share a more complete example? I have the Wireless Stick V3 and code like the following, but it always reads about the same with/without battery and with/without USB power:

pinMode(37,OUTPUT);
digitalWrite(37, LOW);
Serial.printf("Battery power on GPIO 1: ");
Serial.println(analogRead(1));

I’m expecting that when I unhook the battery it will show 0, but it shows about 960ish, the same number as when the battery is hooked up.

1 Like

This is the code I am using now:

#define VBAT_PIN 1

void VBAT_Init() {
pinMode(VBAT_PIN, INPUT);
adcAttachPin(VBAT_PIN);
analogReadResolution(10);

pinMode(37, OUTPUT); // ADC_Ctrl
}

#define BATTERY_SAMPLES 20

float readBattVoltage() {
digitalWrite(37, LOW); // ADC_Ctrl

uint32_t raw = 0;
for (int i = 0; i < BATTERY_SAMPLES; i++) {
raw += analogRead(VBAT_PIN);
}
raw = raw / BATTERY_SAMPLES;

digitalWrite(37, HIGH); // ADC_Ctrl

return 5.42 * (3.3 / 1024.0) * raw;
}

1 Like

Ok thank you, that helped a lot. It looks like with no battery it doesn’t report 0V like I had thought. I had to adjust the ratio for my wireless stick v3, it looks like the voltage divider circuit is slightly different than the wireless stick lite:

Serial.println("Calculating battery voltage:");
sprintf(txpacket,"Battery Voltage %s V",String(c1/232.62));

For the record I found changing the voltage regulation adjustment from 5.42 to 5.11

According to the schematics it should be 4.9
r1 390k
r2 100k
0.204 = r2 / (r1 + r2)
1/0.204 = 4.9

It’s not linear!

The closest I can get it, by having a ppk2 input voltages from 3.3v to 4.0v is 5.11
(tested on 3 separate stick-lite-V3) with an error of 0 - 1.8% depending on input voltage.