Pull battery level from Wemos Lolin32

I've got a more or less generic version of a Wemos Lolin32 that has a LiPo jack and built in battery charger.

What I'm looking to do is pull a value of the remaining level of charge in the battery. I've done with with some of the Adafruit boards, which usually just mean pulling a value from a pin (like A9). I've attached images of the exact board I have - if anyone has any experience with this board or pulling battery level off something similar, I would be grateful.

I think one way to do is by reading the Vin or 5V Pin value, if the voltage is dropping that means battery depleting. IT will require a lot of testing.

Don't expect long battery life with an AMS1117 voltage regulator on board.

Ideally you need the schematic drawing to determine if it already supplies the battery voltage (through a voltage divider) to one of the analogue pins or if one of the jumper pads has what you need.

AMS1117? Is that really what they use to get 3.3v from the 3.7~4.2v from the LiPo? I sure hope not, because even at full charge that won’t give 3.3v out… (though there are parts with the same package and pinout with dropout as low as 0.3v, albeit with like 6v max input voltage)

I wonder if a more detailed examination would show that they’re doing something different when powered from lipo, and just use than when powered by external 5v.

Unless you can get a schematic of that, you’re going to need to do some investigation. For example, running on LiPo, what voltage is on the 5v pin? If it’s the battery voltage, easy - run it through a resistor divider, probably with a cap on it to stabilize it since you want very high value resistors in the divider to minimize power consumption (maybe even gate the low side of it with a fet so it won’t draw power when device is sleeping, if the ESP32 has a super low power sleep mode that you’re using). I see no Vin pin. I could imagine having to tack a wire onto the positive side of the battery connector, and doing the same as above to that (be sure to put hotmelt glue over the solder joint, otherwise the wire will fatigue and snap unbelievably quickly; always seems to happen when you tack wires onto the top of pads/pins)

heatmizuh:
I've got a more or less generic version of a Wemos Lolin32 that has a LiPo jack and built in battery charger.

The schematic of the Wemos Lolin32 was not difficult to find by entering 'Wemos Lolin32 schematic' into Google.

As is common with a lot of ESP32 boards, there seems to be no pin access to Vin or Vbatt.

So if you want to measure it then you need to hack the board around a bit, adding some wires and a resistor divider.

srnet:
The schematic of the Wemos Lolin32 was not difficult to find by entering 'Wemos Lolin32 schematic' into Google.

I could not find the variant the OP is refering to with the OLED, could you post the link here please.

Riva:
I could not find the variant the OP is refering to with the OLED, could you post the link here please.

I could not find a link for the exact varient the user was using either ......................

Hey heatmizuh or others. I have the same board. Did you solve the issue eventually?

Thanks.

Just connect a wire to the VIN pin and run it to one of the pins assigned to read analog.

Then write some code to do the rest of the work. And this may help:

#include <driver/adc.h>

In setup:

// https://dl.espressif.com/doc/esp-idf/latest/api-reference/peripherals/adc.html
  // set up A:D channels
  adc1_config_width(ADC_WIDTH_12Bit);
  adc1_config_channel_atten(ADC1_CHANNEL_6, ADC_ATTEN_DB_11);


xTaskCreatePinnedToCore( TaskAnalogVoltRead_LIDAR, "fTaskAnalogVoltRead", TaskStack10K1, NULL, Priority2, NULL, TaskCore1 ); // assigned to core 1
  sema_AnalogVoltRead_LIDAR = xSemaphoreCreateMutex();
  xSemaphoreGive( sema_AnalogVoltRead_LIDAR );

The task:

void TaskAnalogVoltRead_LIDAR( void *pvParameters )
{
  String localBuffer;
  localBuffer.reserve ( StringBufferSize300 );
  int iBit = 1;
  float ADbits = 4095.0f;
  float offSET = 1.0f;
  float r1 = 100800.0f; // R1 in ohm, 100k = 100,800.0 //
  float r2 = 38780.0f; // R2 in ohm, 38k = 38000.0 //actual 38780K
  float uPvolts = 3.3f;
  // ADC1 channel 0 is GPIO36
  // ADC1 channel 1 is GPIO37
  // ADC1 channel 6 is GPIO34
  // https://dl.espressif.com/doc/esp-idf/latest/api-reference/peripherals/adc.html
  // to get resistor R2 go to:
  // http://www.ohmslawcalculator.com/voltage-divider-calculator
  //   used 12 volts for the input voltage to calculate R2, used 100K for R1
  for (;;)
  {
    // group handle, WaitForBits, ClearOnExitBit, WaitForAllBits, TicksToWait
    xEventGroupWaitBits( eg, evtAnalogVoltReadTask_LIDAR, pdTRUE, pdTRUE, portMAX_DELAY );
    // read the input
    iBit = iBit << 1;
    if ( iBit == 1073741824 )
    {
      if ( xSemaphoreTake( sema_AnalogVoltRead_LIDAR, xSemaphoreTicksToWait ) == pdTRUE )
      {
        Vbatt_LIDAR += ( ((( uPvolts * adc1_get_raw(ADC1_CHANNEL_6)) / ADbits) / r2 * ( r1 + r2)) + offSET );
        Vbatt_LIDAR = Vbatt_LIDAR /2; // average readings
        xSemaphoreTake( sema_Time, xSemaphoreTicksToWait );
        fMakeTimeStamp ( localBuffer );
        xSemaphoreGive( sema_Time ); // give up semaphore
      } // if ( xSemaphoreTake( sema_AnalogVoltRead_LIDAR, xSemaphoreTicksToWait ) == pdTRUE )
      iBit = 1;
    } // if ( iBit == 1073741824 )
  }
  vTaskDelete( NULL );
}

I found that using the ESP API to read setup and read the analog converter results in a more stable analog reading over using the Arduino read analog thing do. The Arduino read analog thing do does not set these values: adc1_config_width(ADC_WIDTH_12Bit);
adc1_config_channel_atten(ADC1_CHANNEL_6, ADC_ATTEN_DB_11);, which, for the ESP, is quite important when it comes to doing analog read things.