Lolin D32 battery voltage using microppython
Posted: Wed Jan 12, 2022 4:58 am
I got a Lolin D32 preloaded with micropython & the battery voltage presented to gpio35 via a voltage divider with 1% 100k resitors. The battery is sitting @ 4138mv but the value I get from gpio35 can vary from 4080mv to 4196mv. I've struck this variation with the 12 bit adc on other esp32 based boards, so I thought I'd try to smooth the jitter.
If I do 100 sequential adc.read()s the count always increases between the first & last read, eg [2380, 2382, 2427, 2427, 2428, 2429, 2429, 2430, 2430, 2431, 2431, 2431, 2431, 2431, 2432, 2432, 2432, 2432, 2432, 2432, 2433, 2433, 2433, 2433, 2434, 2434, 2434, 2435, 2435, 2435, 2436, 2437, 2437, 2437, 2437, 2437, 2437, 2437, 2438, 2438, 2439, 2439, 2439, 2439, 2440, 2441, 2441, 2442, 2442, 2442, 2442, 2442, 2443, 2443, 2443, 2443, 2444, 2445, 2445, 2445, 2445, 2445, 2445, 2446, 2446, 2447, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2449, 2449, 2449, 2450, 2450, 2451, 2451, 2451, 2452, 2452, 2452, 2453, 2453, 2453, 2453, 2455, 2455, 2455, 2455]
I've tried using the mean, the median, varying the number of reads, reducing the adc width, but nothing seems to narrow the variation from one battery voltage call to the next. Just wondering if anyone has come up with a way of getting more consistent results from the ADC?
If I do 100 sequential adc.read()s the count always increases between the first & last read, eg [2380, 2382, 2427, 2427, 2428, 2429, 2429, 2430, 2430, 2431, 2431, 2431, 2431, 2431, 2432, 2432, 2432, 2432, 2432, 2432, 2433, 2433, 2433, 2433, 2434, 2434, 2434, 2435, 2435, 2435, 2436, 2437, 2437, 2437, 2437, 2437, 2437, 2437, 2438, 2438, 2439, 2439, 2439, 2439, 2440, 2441, 2441, 2442, 2442, 2442, 2442, 2442, 2443, 2443, 2443, 2443, 2444, 2445, 2445, 2445, 2445, 2445, 2445, 2446, 2446, 2447, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2449, 2449, 2449, 2450, 2450, 2451, 2451, 2451, 2452, 2452, 2452, 2453, 2453, 2453, 2453, 2455, 2455, 2455, 2455]
I've tried using the mean, the median, varying the number of reads, reducing the adc width, but nothing seems to narrow the variation from one battery voltage call to the next. Just wondering if anyone has come up with a way of getting more consistent results from the ADC?