Forum

ESP32 / Lolin32 - r...
 
Notifications
Clear all

ESP32 / Lolin32 - read battery or v_in voltage

2 Posty
1 Users
0 Reactions
1,098 Widok
0
Topic starter

arduino example

2 Answers
0
Topic starter

Lolin32 lite, Pin 34

more info: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/adc.html

https://demo-dijiudu.readthedocs.io/en/latest/api-reference/peripherals/adc.html

void setup() {

  adc1_config_width(ADC_WIDTH_12Bit);
  adc1_config_channel_atten(ADC1_CHANNEL_6, ADC_ATTEN_DB_11);
  esp_adc_cal_get_characteristics(V_REF, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, &characteristics);

}

void readBattery(){
    unsigned int samples = 100;  
    const float rangeFactor = 3300*1.27;
    float factor = (rangeFactor/4096)*2;
    uint32_t sum = 0;                  
    float voltage = 0.0;           
    float calculated_voltage = 0.0;  
   
 
    for (int i = 0; i < samples; i++)
    {
      sum += adc1_to_voltage(ADC1_CHANNEL_6, &characteristics);
      delayMicroseconds(1000);
    }
  
    voltage = sum / (float)samples;
    calculated_voltage = factor*voltage;
    Serial2.print("Voltage = ");
    Serial2.println(calculated_voltage);
}
0
Topic starter

remember about ADC noise.

Odpowiedź

Author Name

Author Email

Your question *

 
Preview 0 Revisions Saved
Share: