Problem with deep sleep in ESP32

quangminh.le0701
Posts: 6
Joined: Mon Jul 01, 2019 2:55 pm

Problem with deep sleep in ESP32

Postby quangminh.le0701 » Fri Jul 05, 2019 4:58 am

i'm currently measure battery and send it to master using nrf24l01 module. but the first time after reset the battery measure always incorrect value. it's the same if wake up from deep sleep. i dont know how to fix. anyone help me?

Code: Select all

void setup() {
  esp_adc_cal_value_t val_type =
  esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_0, ADC_WIDTH_BIT_11, REF_VOLTAGE, adc_chars);
}
float battery_read(uint8_t channel, adc_atten_t attenuation) {
  float voltage = 0.0;           // calculated voltage
  float output = 0.0;            //output value
  const float battery_max = 4.2; //maximum voltage of battery
  const float battery_min = 3.0; //minimum voltage of battery before shutdown
  float R1 = 100000; // resistance of R1 (100K)
  float R2 = 27000;  // resistance of R2 (27K)
  adc1_channel_t channelNum;
  switch (channel) {
    case (36):
      channelNum = ADC1_CHANNEL_0;
      break;

    case (39):
      channelNum = ADC1_CHANNEL_3;
      break;

    case (34):
      channelNum = ADC1_CHANNEL_6;
      break;

    case (35):
      channelNum = ADC1_CHANNEL_7;
      break;

    case (32):
      channelNum = ADC1_CHANNEL_4;
      break;

    case (33):
      channelNum = ADC1_CHANNEL_5;
      break;
  }
  adc1_config_channel_atten(channelNum, attenuation);
  voltage = esp_adc_cal_raw_to_voltage(analogRead(channel), adc_chars);
  Serial.println(voltage);
  return output = voltage*(R1+R2)/R2;
}
Image

Who is online

Users browsing this forum: No registered users and 88 guests