Detecting USB Power in code on T-Display-S3
-
I am building firmware for the T-Display-S3 which needs to behave differently when connected to mains power (via USB) versus when on battery. I have not yet found an API or method that I can use to distinguish between the two.
My objective is to conserve power when the device is unplugged.
To be clear, the hardware has built-in behavior which turns off the display when it's unplugged unless GPIO 15 has been asserted, but this doesn't save enough power and I don't know how I can tell when this has happened. What I'd like to do is to put the device into light sleep mode when it's unplugged. Light sleep works fine, but I can't tell when the device has been unplugged.
Any thoughts on detecting the unplug event? -
@hpro You could...use the ESP ADC function on pin GPIO4 to read the Battery Voltage.
in my experience it shows~ 5V on USB and some lower values on Battery.
The ESP has a terrible built in ADC that is not calibrated, stable or linear...but it's free.
-Terry -
Thanks, Terry. I had much the same thought.
Using the method from the GetBatteryVoltage sketch I saw an overlap between the power measured without a battery and that when a small lipo was connected, so voltage doesn't seem to be a very good discriminator.
Interestingly the battery connected (and fully charged) voltage was up to 4808mv, higher than the no battery voltage of 4768-4778mv.
Any such voltage is a disaster if applied to a single cell lipo. Maybe it'll burst out the back of the case ...Henry
-
It would be great to get a definitive response from the LilyGo team because the work-around could be a bit painful.
My thought is that if USB power cannot be determined directly, perhaps it can be inferred from some period of declining voltage.
Any other ideas?
-
@hpro This only a community site, with mostly me.
You could try their GitHub repository and raise an issue:
https://github.com/Xinyuan-LilyGO/T-Display-S3/issues
Lithium batteries do not lose voltage as they are used up, They all of a sudden die!
My suggestion was to calibrate the voltage at USB conditions and anything less than that, accounting for ADC drift would indicate that it was on battery only, no USB.
-Terry