Making an ESP32 controlled MicroPyhton Power Management script #15490
-
Hi, I'm a Product design student and as one of my projects during the previous year I had to design a voice recorder that fulfilled specific requirements. I ended up with a project that I liked so to have something to do over the summer holidays as well as expand my limited knowledge about designing electronic devices I decided to try to make a working prototype. The prototype I'm making is based on an ESP32, coded in MicroPython (Since that's what we've learned to work with in class, and I already had some of the required electronic components for the project) The device is supposed to have a battery, which is supposed to be charged via USB C. I am currently working on creating a solution that allows for power management for the device. I already have a battery for the prototype (980mAh 3.7V single cell LiPo battery) and a dedicated USB C LiPo Battery charging module From what I understand about Power Management systems they usually work by taking Voltage measurements of the battery to access the charge level (for 3.7V battery it should be between 3.3V and 4.2V), which is then converted to a % value, they also turn off the device when the battery falls below 3.3V to prevent wearing out the battery. I have created some code based on my understanding of the problem. In theory the code works and (sometimes) provides voltage readings very similar to those of a multimeter while connected to my laptop. In practice however I've tried setting up two experiments. In one of them I attach the battery to the ESP32, and a few green LEDs, then run the code for a while in hopes of getting the reading that the battery level is decreasing over time. In the other one I attach the battery to the ESP32 and the charging module and run the code for a while in hopes of getting a reading that the battery level is increasing over time. The experiments haven't worked correctly yet, either returning values that don't change as expected or showing that the battery is at over 4.2V which doesn't line up with the multimeter readings. (I tried running the experiments both with the ESP32 powered by the battery and disconnected from any external power sources and with the ESP32 powered by the micro USB port) The Voltage values also change when attaching the charging module or connecting the LEDs/ using the battery to power the ESP32 by connecting the + rail to the VIN Pin, in a way that I'm unable to predict, but even if they didn't have any impact on the Voltage values I would still expect the code to detect gradual increase/decrease of the Voltage values (even if the Voltage/Battery percentage values weren't accurately reflecting the charge state of the battery) This is my code:
This is a picture of the very simple ESP32 testing setup I'm using The battery, and the charging module are connected to the + and - rails respectively, ESP32 is connected to the - rail with the GND Pin, Pin 35, is connected with a 10kOhm resistor to the - Rail, and with a 4.7kOhm resistor to the + rail. (When testing discharging the battery the + and - rails to which the LEDs are connected get connected to the already utilized + and - rails with jumper cables) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
To get a voltage reading, try ADC.read_uv() instead of converting the raw reading. That's easier and is already factory calibrated. See https://docs.micropython.org/en/latest/esp32/quickref.html |
Beta Was this translation helpful? Give feedback.
To get a voltage reading, try ADC.read_uv() instead of converting the raw reading. That's easier and is already factory calibrated.
See https://docs.micropython.org/en/latest/esp32/quickref.html