Battery voltage monitor and AD conversion for XIAO_ESP32C

I can’t take credit, it’s Chatgpt with lots of tinkering. I prefer to see the end result and reverse engineer it to learn backwards. Seeps into my head much easier.

1 Like

@msfujino
It’s quite old thread, but could you help me to understand the reasoning behind the selection of resistors?
You use 220 kOhm resistors, which gives me 8 microA.
The other guy here in the thread suggests to use 1MOhm resistors, which gives 1.85 microA.
I believe both options work for you guys, I’m just not sure why would I choose one over another. Which are min and max current limits?
Thanks for the help!

If the current consumed by the resistor is a problem, use a large value (say 1000k). If this is not a problem, use a small value (e.g., 2k2).
A large resistor value reduces current consumption, but it may be sensitive to noise, or phenomena such as POST#33 may appear. A small resistor value will increase unnecessary current consumption.

The maximum practical resistor value is 1 MΩ. To improve the accuracy of AD conversion, the voltage divider resistor should be as small as possible. And finally, the resistor value is determined by your required specifications.

2 Likes

Happy new year folks! I’m back with a brand new set of problems :slight_smile: :slight_smile:
The sketch “works” with the correct resistors. I’m getting messages through but here’s where it gets interesting:
I’ve got 5 of these built now, all of them with the same configuration, same hardware and same sketch bar the hostname being 1-5.
Numbers 1 and 3 have worked perfectly without skipping a beat for days now, 2,4 and 5 seem to hang up, they’ll do their job once then just hang, I can see them sitting on the network the whole time while the working ones are only connected for a few seconds every 15 minutes. If I manually boot them off the WiFi (using unifi cloud key controls) they’ll run the sketch once which will message the info to mqtt broker then hang again. Could my hasty soldering skills be the issue or should I be looking for firmware updates (is that even a thing).
Hoping someone can point me in the right direction again.

I think it would be less confusing to have a separate thread for issues that differ from the title.

That’s a point yeah, I’ve gone so far down this rabbit hole I’d forgotten where I started :confused:

Hello everyone, a noob here. I have a Xiao ESP32C6, but the power wiki referenced the C3, which directed me to this forum. I have some questions that I’m hoping you can help me with or point me to the right place for answers:

  1. I am soldering the resistor and was thinking of using a 1MΩ resistor. Should the equation to get the voltage be the same?
  2. Since I’m a noob, I’m afraid that because both resistors are connected to + and - and both connect to A0, could I cause a short circuit?
  3. If I detect a low battery and put the device in deep sleep in the loop method, will the USB still charge the battery?
  4. Can I use another pin for reading? I was checking the schematic for the C6 and was thinking of using the A6 pin at the back.

Have a wonderfull day

Hi andcoderes,

  1. I am soldering the resistor and was thinking of using a 1MΩ resistor. Should the equation to get the voltage be the same?

Battery voltage is obtained by the same formula.
Vbatt = 2 * analogReadMilliVolts(A0);

  1. Since I’m a noob, I’m afraid that because both resistors are connected to + and - and both connect to A0, could I cause a short circuit?

No problem.

  1. If I detect a low battery and put the device in deep sleep in the loop method, will the USB still charge the battery?

The charge controller charges the battery even in sleep mode.

  1. Can I use another pin for reading? I was checking the schematic for the C6 and was thinking of using the A6 pin at the back.

I have not checked, but I believe it can be used without any problem. Please experiment and post your results.

1 Like

Hi, thanks for the answer!
I tried using pin A6 on the back, and it worked perfectly. thanks for all the answers, those were really usefull

1 Like