Navigation

    LILYGO

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

    ESP32-C3 T-OI Plus. Reading battery level

    Technical Discussion
    2
    4
    580
    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.
    • E
      etolocka last edited by

      Hi

      I'm working on a project where I need to know the charge level of the battery mounted in the ESP32-C3 T-OI Plus (Ver 1.3).
      From what I see on the schematic, Vbat is connected to the ADC input through a resistive divider made up of two 100K resistors that cut the voltage in half.

      Building on that assumption, I'm using the following Micropython code:

      ...
      #adc
      a0 = 2

      conversorAD = ADC (Pin(a0))
      conversorAD.width (ADC.WIDTH_12BIT)
      conversorAD.atten(ADC.ATTN_11DB)
      ...
      def leerBateria ():
      #Reads the battery charge percentage
      batVolt = 2*(conversorAD.read_uv ()/1000000)
      if (batVolt > 4.2):
      batVolt=4.2
      return (100*(batVolt/4.2))

      I think it is correct because it reads values ​​consistent with the battery voltage measured with a multimeter.
      What catches my attention is the variability of the values ​​read, for example if I read every 20 seconds I can have (with USB connected)

      Bat = 99.57
      Bat = 98.67
      Bat = 99.57
      Bat = 100.00

      What could this variation be due to?

      Thankfully,
      Ernesto.

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

        @etolocka The ESP32 is notoriously bad at ADC function, so...this is just a rough estimate of your battery life, 'for your information'

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

          @teastain2 Thank you!

          Am I interpreting the schematic correctly and is the voltage calculation also correct?

          Thankfully,
          Ernesto.

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

            @etolocka Well, Ernesto, if the returned value is saying that the battery is 100% of 4.2 volts...I think you are THERE!
            I do not use Python, have a board like yours or ever monitored battery voltage, so I am no expert, it looks like you are OK!
            -Terry

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