LiPo Battery Fuel Gauge (MAX1704X) on SparkFun Thing Plus - ESP32 WROOM (U.FL) pinout

What are the breakout pins for use on the LiPo Battery Fuel Gauge (MAX1704X) connected to SparkFun Thing Plus - ESP32 WROOM (U.FL).

Pins on the 1704X

QST = ???

VCC = ???

ALT = ???

GND = GND

SDA = A2 (or should this be GPIO23/SDA?)

SCL = A1 (or should this be GPIO22/SCL?)

Power + = VBAT

Ground = GND

Charge LED is on (suggesting the ESP32 can see the LIPO that is connected into the MAX170X)

22:06:59.874 → MAX17043 Example

22:06:59.874 → begin: isConnected returned false

22:06:59.874 → MAX17043 not detected. Please check wiring. Freezing.

Thanks for reaching out to us on this.

Double-check your wiring versus page 5 of this http://cdn.sparkfun.com/datasheets/Prot … X17044.pdf

Hope this helps, and happy sparking!

No joy. I added comments in the attached snip, from the documentation.

In the Arduino IDE:

SFE_MAX1704X lipo(MAX1704X_MAX17043); // Create a MAX17043

Board: ESP32 Dev Module

Error:

01:17:24.460 → rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)

01:17:24.460 → configsip: 0, SPIWP:0xee

01:17:24.460 → clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00

01:17:24.460 → mode:DIO, clock div:1

01:17:24.460 → load:0x3fff0018,len:4

01:17:24.460 → load:0x3fff001c,len:1216

01:17:24.460 → ho 0 tail 12 room 4

01:17:24.460 → load:0x40078000,len:9720

01:17:24.460 → ho 0 tail 12 room 4

01:17:24.460 → load:0x40080400,len:6352

01:17:24.460 → entry 0x400806b8

01:17:24.603 → MAX17044 Example

01:17:24.603 → begin: isConnected returned false

01:17:24.603 → MAX17044 not detected. Please check wiring. Freezing.

You don’t have a ground connected between the ESP32 and the MAX17043, that may be the source of your issues.

no joy. See highlight

This is still not working. I ended up frying the ESP Wroom (ordered a new one). Put the smoke out.

Any suggestions on getting my SparkFun Thing Plus - ESP32 WROOM (U.FL) to work? the replacement arrived.

What isn’t working?

Sadly we don’t really have much in the way of a guide for the Fuel Gauge but the example code below might help. It hasn’t been tested on the ESP32 but should work on an Uno.

/* Wireless Joystick battery monitoring Example Code
  by: Jim Lindblom and modified by Alex Wende
  SparkFun Electronics
  date: 9/28/16

  license: Creative Commons Attribution-ShareAlike 4.0 (CC BY-SA 4.0)
  Do whatever you'd like with this code, use it for any purpose.
  Please attribute and keep this license.

  This is example code for the MAX17043G chip on the Wireless Joystick.
  The MAX17043G+U is a compact, low-cost 1S LiPo fuel gauge.
  The SAMD21 talks with the MAX17043 over an I2C (two-wire) interface,
  so we'll use the Wire.h library to talk with it.

  It's a silly example. It reads the battery voltage, and its percentage
  full and prints it out over SerialUSB. You probably wouldn't care about
  the battery voltage if you had the Wireless Joystick connected via USB.
  But this code does show you how to configure the MAX17043G, and how to
  read and manipulate the voltage values.
*/
#include <Wire.h>

#define MAX17043_ADDRESS 0x36  // R/W =~ 0x6D/0x6C

// Pin definitions
int alertPin = 7;  // This is the alert interrupt pin, connected to pin 7 on the Wireless Joystick

// Global Variables
float batVoltage;
float batPercentage;
int alertStatus;

void setup()
{
  pinMode(alertPin, INPUT_PULLUP);

  SerialUSB.begin(9600);  // Start hardware SerialUSB
  delay(500);
  SerialUSB.println("Hello World");

  Wire.begin();  // Start I2C
  configMAX17043(32);  // Configure the MAX17043's alert percentage
  qsMAX17043();  // restart fuel-gauge calculations
}

void loop()
{
  batPercentage = percentMAX17043();
  batVoltage = (float) vcellMAX17043() * 1/800;  // vcell reports battery in 1.25mV increments
  alertStatus = digitalRead(alertPin);

  SerialUSB.print(batPercentage, 2);  // Print the battery percentage
  SerialUSB.println(" %");
  SerialUSB.print(batVoltage, 2);  // print battery voltage
  SerialUSB.println(" V");
  SerialUSB.print("Alert Status = ");
  SerialUSB.println(alertStatus, DEC);
  SerialUSB.println();
  delay(1000);
}

/*
vcellMAX17043() returns a 12-bit ADC reading of the battery voltage,
as reported by the MAX17043's VCELL register.
This does not return a voltage value. To convert this to a voltage,
multiply by 5 and divide by 4096.
*/
unsigned int vcellMAX17043()
{
  unsigned int vcell;

  vcell = i2cRead16(0x02);
  vcell = vcell >> 4;  // last 4 bits of vcell are nothing

  return vcell;
}

/*
percentMAX17043() returns a float value of the battery percentage
reported from the SOC register of the MAX17043.
*/
float percentMAX17043()
{
  unsigned int soc;
  float percent;

  soc = i2cRead16(0x04);  // Read SOC register of MAX17043
  percent = (byte) (soc >> 8);  // High byte of SOC is percentage
  percent += ((float)((byte)soc))/256;  // Low byte is 1/256%

  return percent;
}

/* 
configMAX17043(byte percent) configures the config register of
the MAX170143, specifically the alert threshold therein. Pass a 
value between 1 and 32 to set the alert threshold to a value between
1 and 32%. Any other values will set the threshold to 32%.
*/
void configMAX17043(byte percent)
{
  if ((percent >= 32)||(percent == 0))  // Anything 32 or greater will set to 32%
    i2cWrite16(0x9700, 0x0C);
  else
  {
    byte percentBits = 32 - percent;
    i2cWrite16((0x9700 | percentBits), 0x0C);
  }
}

/* 
qsMAX17043() issues a quick-start command to the MAX17043.
A quick start allows the MAX17043 to restart fuel-gauge calculations
in the same manner as initial power-up of the IC. If an application's
power-up sequence is very noisy, such that excess error is introduced
into the IC's first guess of SOC, the Arduino can issue a quick-start
to reduce the error.
*/
void qsMAX17043()
{
  i2cWrite16(0x4000, 0x06);  // Write a 0x4000 to the MODE register
}

/* 
i2cRead16(unsigned char address) reads a 16-bit value beginning
at the 8-bit address, and continuing to the next address. A 16-bit
value is returned.
*/
unsigned int i2cRead16(unsigned char address)
{
  int data = 0;

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

  Wire.requestFrom(MAX17043_ADDRESS, 2);
  while (Wire.available() < 2)
    ;
  data = ((int) Wire.read()) << 8;
  data |= Wire.read();

  return data;
}

/*
i2cWrite16(unsigned int data, unsigned char address) writes 16 bits
of data beginning at an 8-bit address, and continuing to the next.
*/
void i2cWrite16(unsigned int data, unsigned char address)
{
  Wire.beginTransmission(MAX17043_ADDRESS);
  Wire.write(address);
  Wire.write((byte)((data >> 8) & 0x00FF));
  Wire.write((byte)(data & 0x00FF));
  Wire.endTransmission();
}