ESP32 and lipo fuel guage

Hey guys I am using max17043 lipo fuel guage at (SparkFun LiPo Fuel Gauge - TOL-20680 - SparkFun Electronics) with esp32 on arduino. But it is not giving me good results. Some are not stable, and some are showing me less battery capacity and there is a drop of 0.1V in voltage when we compared to multimeter. I think there is a problem with i2C of esp32. I am using 21 and 22 pins and there is a library at (SparkfunTechSupport · GitHub ... /TOL-10617), which I am using and is mentioned by sparkfun.

Kindly give me suggestions.

Regards,

Please post your program and your wiring diagram. See this Simple Image Guide

...R

#include <Wire.h>
#define MAX17043_ADDRESS 0x32
#define SOC_REGISTER 0x04
#define MODE_REGISTER 0x06
#define COMMAND_REGISTER 0xFE

void readRegister(byte startAddress, byte &MSB, byte &LSB) {

    Wire.beginTransmission(MAX17043_ADDRESS);
    Wire.write(startAddress);
    Wire.endTransmission();

    Wire.requestFrom(MAX17043_ADDRESS, 2);
    MSB = Wire.read();
    LSB = Wire.read();
}

void writeRegister(byte address, byte MSB, byte LSB) {

    Wire.beginTransmission(MAX17043_ADDRESS);
    Wire.write(address);
    Wire.write(MSB);
    Wire.write(LSB);
    Wire.endTransmission();
}

int getSoC() {

    byte MSB = 0;
    byte LSB = 0;

    readRegister(SOC_REGISTER, MSB, LSB);
    //float decimal = LSB / 256.0;
    return MSB;
}

int Battery;

int get_battery_status(void) {
  Wire.begin(21,22);
  //writeRegister(COMMAND_REGISTER, 0x00, 0x54);
  writeRegister(MODE_REGISTER, 0x40, 0x00); 
  delay(2000);
  int stateOfCharge = getSoC();
  Serial.println(stateOfCharge);
  Serial.println();
  return stateOfCharge;
}

void loop() {

  Battery = get_battery_status();
  delay(1000);

}

Regards,

What I am saying is that it is not giving me results. It is not stable, means if it shows 60 %, next time it shows 58 % and after 15-20 mins it shows 51 %.

There is one idea that if I can be able to get voltage correctly through the module. So if I use a map function of arduino to map 3.5 to 4.2 into 0-100 %. Would it be correct, as I know 18650 cells can go down to 3.5V, and I can also afford to go down to 3.5V because I am using 3.3V buck converter. So I think this approach is good?

Kindly give me your expert opinion.

Regards,

There is "electronics" in the 18650 cell that will muck with the readings. Try an internet search on the matter.

If the library is NOT using the ESP32 A:D API to set up and make read calls to the ESP32 A:D converters, expect erratic readings.