Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading Battery Voltage While USB is Plugged In #97

Open
CanselYalnkaya opened this issue Aug 6, 2024 · 2 comments
Open

Reading Battery Voltage While USB is Plugged In #97

CanselYalnkaya opened this issue Aug 6, 2024 · 2 comments

Comments

@CanselYalnkaya
Copy link

While my device is plugged into USB, I want to read the voltage to see if the battery is charging, but with the code below, I can only read 7.26V. Is there a way to read the battery voltage while it is plugged into USB?

`#include <driver/adc.h>
#include "esp_adc_cal.h"

void setup() {
Serial.begin(115200);
esp_adc_cal_characteristics_t adc_chars;
esp_adc_cal_value_t val_type = esp_adc_cal_characterize((adc_unit_t)ADC_UNIT_1, (adc_atten_t)ADC_ATTEN_DB_2_5, (adc_bits_width_t)ADC_WIDTH_BIT_12, 1100, &adc_chars);
pinMode(14, OUTPUT);
}

void loop() {
digitalWrite(14, HIGH);
delay(1);
float measurement = (float) analogRead(34);
float battery_voltage = (measurement / 4095.0) * 7.26;
digitalWrite(14, LOW);
Serial.println(battery_voltage);
}`

@bartdereu
Copy link

No ,there is not. It's explained in the manual.

@lewisxhe
Copy link
Contributor

Due to hardware limitations, when the USB is plugged in, the power source switches to USB, and the voltage detected at this time is no longer the battery voltage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants