I need to monitor a 12V battery, but when I moved from the dev board to the single module the readings got way off.
Below the results and the code used
To simulate the battery I am using a 12V dc power supply
I started developing the circuit using a Doit Esp32 Dev board and I was able to get close enough to what I need, here are the results
Esp32 Dev Module (Has a 5.5 linear voltage regulator)
Vref output pin 25 1110 mV ( using the adc2_vref_to_gpio() )
ADC VRef calibration: 1128 mV using espefuse.py
Adc reading 2829 voltage: 758 Vin: 11938.500000
Adc reading 2816 voltage: 755 Vin: 11891.250000
Adc reading 2815 voltage: 754 Vin: 11875.500000
Adc reading 2814 voltage: 754 Vin: 11875.500000
Adc reading 2822 voltage: 756 Vin: 11907.000000
Adc reading 2819 voltage: 755 Vin: 11891.250000
Multimeter 11.90 (here the numbers are accurate enough for my need)
But now with the bare module
Esp32-wroom-32 (Has a 3.3 linear voltage regulator)
Vref output pin 25 1170 mV
ADC VRef calibration: 1086 mV using espefuse.py
Adc reading 2758 voltage: 716 Vin: 11277.000000
Adc reading 2748 voltage: 713 Vin: 11229.750000
Adc reading 2790 voltage: 723 Vin: 11387.250000
Adc reading 2771 voltage: 719 Vin: 11324.250000
Adc reading 2767 voltage: 718 Vin: 11308.500000
Multimeter 12.16 (here the result is way off)
Here is the code that I used to test
Code: Select all
#include "soc/rtc_cntl_reg.h"
#include "driver/rtc_io.h"
#include "driver/adc.h"
#include <esp_adc_cal.h>
static esp_adc_cal_characteristics_t *adc_chars;
void setup() {
Serial.begin(115200);
while( !Serial ){}
Serial.println("Init");
gpio_set_direction(GPIO_NUM_32, GPIO_MODE_INPUT);
adc1_config_channel_atten(ADC1_CHANNEL_4, ADC_ATTEN_DB_0);
adc1_config_width(ADC_WIDTH_BIT_12);
adc_chars = (esp_adc_cal_characteristics_t *)calloc(1, sizeof(esp_adc_cal_characteristics_t));
esp_adc_cal_value_t adc_type = esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_0, ADC_WIDTH_BIT_12, 1100, adc_chars);
if (adc_type == ESP_ADC_CAL_VAL_EFUSE_VREF)
{
Serial.printf("Vref eFuse found: %umV", adc_chars->vref);
}
else if (adc_type == ESP_ADC_CAL_VAL_EFUSE_TP)
{
Serial.printf( "Two Point eFuse found");
}
else
{
Serial.printf("Nothing found, using standard Vref: %umV", adc_chars->vref);
}
}
void loop() {
delay(500);
double_t voltageIN = 0;
uint32_t adc_reading = 0;
for (int i = 0; i < 400; i++)
{
adc_reading += adc1_get_raw(ADC1_CHANNEL_4); //RAW ADC
}
adc_reading /= 400;
uint32_t voltage = esp_adc_cal_raw_to_voltage(adc_reading, adc_chars);
voltageIN = (double_t) ((double_t)(voltage * 10710) / 680 ); // voltage divider 10.03K - 680ohms
Serial.printf("Adc reading %d voltage: %d Vin: %f\n", adc_reading, voltage, voltageIN );
}
Thanks