I would like to measure the battery voltage of my data logger. I did some research and found that I need a voltage divider. I also learned that if you want to minimize the battery drain you need to use higher rated resistors. I found the blogpost https://jeelabs.org/2013/05/16/measurin ... aining-it/, which also adds a 0.1μF capacitor to the circuit.

So I wired up a voltage divider with two 1MΩ resistors, and a 104 capacitor to my battery and PA1 of my Blue Pill. I use the following code:

Code: Select all

```
analogReadResolution(ADC_RESOLUTION);
pinMode(PA1, INPUT_ANALOG);
for (byte i = 0; i < 3; ++i) {
x = analogRead(PA1);
Serial1.print("ADC: ");
Serial1.println(x);
}
```

Code: Select all

```
ADC: 173
ADC: 49
ADC: 14
--
ADC: 177
ADC: 51
ADC: 13
--
ADC: 181
ADC: 52
ADC: 15
```

Can anybody give some tips on what I'm doing wrong? Are there better options? Other resistors? Other capacitor?

Thanks in advance!

(Note: I use STM32 Cores v1.9.0).