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

ESP32-WROOM battery measuring / monitoring #2158

Closed
qaldak opened this issue Dec 5, 2018 · 4 comments
Closed

ESP32-WROOM battery measuring / monitoring #2158

qaldak opened this issue Dec 5, 2018 · 4 comments

Comments

@qaldak
Copy link

qaldak commented Dec 5, 2018

Hardware:

Board: doit ESP32 devkit v1 (36 Pins) (ESP32-WROOM)
Core Installation/update date: ?11/jul/2017?
IDE name: Arduino IDE
Flash Frequency: 80MHz
Upload Speed: 921600
Computer OS: Windows 10

Description:

Hi folks

I use doit esp32-wroom (doit esp32 devkitv1) as temperature sensor in my tortoise enclosure.
I use this microcontroller with an 3.7v 18650 battery (4200 mAh). And it works. I connected the battery to the VIN pin.

Now I would like to measure the battery power level and send a MQTT message to log this. Because I would like to know when the battery is empty and send a message to change the battery. Another use case is how the battery will be reloaded (by solar panel)… but this comes later.

My problem is: I can't find how I can measure the power correctly.

I found a method with "extern "C" int rom_phy_get_vdd33();", but I don’t know what kind of data these are:

5471.00
5474.00
5477.00
5477.00
5480.00
5473.00
5474.00

Do I have to calculate something? Is there a better/standard way to calculate battery level?
These values seems to have no relevance to my 18650 (3.7v, 4200mAh)...

I don't have used any resistors from 18650 to VIN pin. I found a lot posts about use resistors for analog pins, but nothing about VIN pin.

That's my first "battery"-project, and I didn't find anything to help me.

Sketch:

extern "C" int rom_phy_get_vdd33();
...
...
void setup() {
...
  /* battery power measuring */
  int internalBatReading;
  if (WiFi.status() == 255) {
    btStart();
    internalBatReading = rom_phy_get_vdd33();
    Serial.println(internalBatReading);
    btStop();
  }
...
}

20181205_214431

@lbernstone
Copy link
Contributor

Weird- an undocumented function doesn't do what you think it should? 😄
Run a voltage divider from the battery to an ADC pin, set to be 1.1V at your max voltage and read it with standard ADC functions.

@qaldak
Copy link
Author

qaldak commented Dec 6, 2018

Weird- an undocumented function doesn't do what you think it should? 😄

You're absolutely right.;-)

@qaldak qaldak closed this as completed Dec 19, 2018
@mixaobo
Copy link

mixaobo commented Jul 1, 2019

Weird- an undocumented function doesn't do what you think it should? 😄
Run a voltage divider from the battery to an ADC pin, set to be 1.1V at your max voltage and read it with standard ADC functions.

could you help me more detail with the code?
Do i need voltage divider to drop 3.7v to 1.1v ?

@lbernstone
Copy link
Contributor

lbernstone commented Jul 1, 2019

Calculate the needed resistors with a voltage divider calculator. Try to get your typical values in the middle of the range.
There's a code example for calibrated ADC readings at #1804.

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