Navigation

    LILYGO

    • Register
    • Login
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Detecting USB Power in code on T-Display-S3

    Technical Discussion
    t-display-s3 power
    2
    5
    494
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      hpro last edited by

      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?

      teastain2 1 Reply Last reply Reply Quote 0
      • teastain2
        teastain2 @hpro last edited by

        @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

        H 1 Reply Last reply Reply Quote 0
        • H
          hpro @teastain2 last edited by hpro

          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

          1 Reply Last reply Reply Quote 1
          • H
            hpro last edited by

            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?

            teastain2 1 Reply Last reply Reply Quote 0
            • teastain2
              teastain2 @hpro last edited by teastain2

              @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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB | Contributors