Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'm having issues regarding showing the battery percentage. #15

Closed
Cicrumstonce opened this issue Feb 23, 2022 · 5 comments
Closed

I'm having issues regarding showing the battery percentage. #15

Cicrumstonce opened this issue Feb 23, 2022 · 5 comments
Labels
question Further information is requested

Comments

@Cicrumstonce
Copy link

Cicrumstonce commented Feb 23, 2022

So, for the last month I've been using this code and the module that someone suggested to and everything in your code works, except one thing that's quite crucial to my project. Which is showing the percentage of the battery through my LCD. I've made sure everything was connected properly and everything else worked properly which it does fortunately. I can show the voltage on the LCD but the percentage constantly stays at 0.00% which is rather strange to me.
64151a68ee4de04e02e47f2667c2d9be

You'll see that I have a voltage going through, but no percentage. I've tested the other properties in your code and they work properly.
I'm currently doing this through a Serial monitor on Arduino fyi

@Cicrumstonce Cicrumstonce added the question Further information is requested label Feb 23, 2022
@porrey
Copy link
Owner

porrey commented Feb 24, 2022

I added a standalone sketch called Debug to the examples folder. It will display the device register values as well as the calculated values. This may help debug your issue.

Output from SparkFun fuel gauge:

Serial port initialized.

ADDRESS...........: 0x36	(54)
VCELL HIGH BYTE...: 0xC3	(195)
VCELL LOW BYTE....: 0x40	(64)
SOC HIGH BYTE.....: 0x40	(64)
SOC LOW BYTE......: 0xB3	(179)
MODE LOW BYTE.....: 0x00	(0)
MODE LOW BYTE.....: 0x00	(0)
VERSION LOW BYTE..: 0x00	(0)
VERSION LOW BYTE..: 0x03	(3)
CONFIG LOW BYTE...: 0x97	(151)
CONFIG LOW BYTE...: 0x1C	(28)

PERCENT...........: 64.70%
ADC...............: 3124
VOLTAGE...........: 3905.00 mV

Output from clone device (this device does not work):

Serial port initialized.

ADDRESS...........: 0x32	(50)
VCELL HIGH BYTE...: 0xFA	(250)
VCELL LOW BYTE....: 0xC0	(192)
SOC HIGH BYTE.....: 0xCC	(204)
SOC LOW BYTE......: 0xEC	(236)
MODE LOW BYTE.....: 0x00	(0)
MODE LOW BYTE.....: 0x00	(0)
VERSION LOW BYTE..: 0x00	(0)
VERSION LOW BYTE..: 0x03	(3)
CONFIG LOW BYTE...: 0x97	(151)
CONFIG LOW BYTE...: 0x1C	(28)

PERCENT...........: 204.92%
ADC...............: 4012
VOLTAGE...........: 5015.00 mV

@Cicrumstonce
Copy link
Author

Alright, so from what I am seeing in the Serial monitor is that I am not receiving SOC HIGH and LOW, as well as VCELL LOW BYTE.

Serial port initialized.

ADDRESS...........: 0x36	(54)
VCELL HIGH BYTE...: 0x86	(134)
VCELL LOW BYTE....: 0x00	(0)
SOC HIGH BYTE.....: 0x00	(0)
SOC LOW BYTE......: 0x00	(0)
MODE LOW BYTE.....: 0x00	(0)
MODE LOW BYTE.....: 0x00	(0)
VERSION LOW BYTE..: 0x00	(0)
VERSION LOW BYTE..: 0x03	(3)
CONFIG LOW BYTE...: 0x97	(151)
CONFIG LOW BYTE...: 0x7C	(124)

PERCENT...........: 0.00%
ADC...............: 2144
VOLTAGE...........: 2680.00 mV

@porrey
Copy link
Owner

porrey commented Feb 25, 2022

If the voltage is correct, the battery is low and 0% makes sense. The voltage should be above 3.7v to operate effectively. At 100% it is usually at 4.2v or more. It is odd, however, that the VCELL LOW byte is 0.

@Cicrumstonce
Copy link
Author

Here I am again, as of right now I got it 'working'. What issue seems to be occurring now is the follwing, I have a battery holder which can hold 2 batteries and it showcases a total of 5.12V (They have a max of 7.4V and they aren't fully charged. They have around 6V of power.) This isn't changing at all. I've implemented the adc and it's the same also, it remains at 4095. Nothing higher, nothing lower. What does change is the percentage, it's continuously rising and not stopping at 100%. However this is in my part of the code, when I am using your debugging code. It shows something completely different.
`Serial port initialized.

ADDRESS...........: 0x36 (54)
VCELL HIGH BYTE...: 0x2C (44)
VCELL LOW BYTE....: 0x40 (64)
SOC HIGH BYTE.....: 0x00 (0)
SOC LOW BYTE......: 0x00 (0)
MODE LOW BYTE.....: 0x00 (0)
MODE LOW BYTE.....: 0x00 (0)
VERSION LOW BYTE..: 0x00 (0)
VERSION LOW BYTE..: 0x03 (3)
CONFIG LOW BYTE...: 0x97 (151)
CONFIG LOW BYTE...: 0x1C (28)

PERCENT...........: 0.00%
ADC...............: 708
VOLTAGE...........: 885.00 mV
`
In your debug, the problem reoccurs where the percentage isn't showing, but we know what that reason is. But the one thing that confuses me a lot is where it shows different adc's.

I'm mainly using this code:
`
#include <MAX17043.h>
#include <Wire.h>
#include <LiquidCrystal.h>
#include <Arduino.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup(){
Serial.begin(115200);
Wire.begin();
FuelGauge.begin();

lcd.begin(16, 2);

lcd.clear();

void loop(){

float capaciteit = FuelGauge.percent();
float voltage = FuelGauge.voltage() / 1000;

Serial.print("Battery Percentage: ");
Serial.println(capaciteit);

Serial.print("Battery Voltage: ");
Serial.println(voltage);

delay(2000);

lcd.setCursor(0,0);
lcd.print("U: ");
lcd.setCursor(3, 0);
lcd.print(voltage);
lcd.setCursor(7,0);
lcd.print("V");

lcd.setCursor(0, 1);
lcd.print("Q: ");
lcd.setCursor(3, 1);
lcd.print(capaciteit);
lcd.setCursor(7,1);
lcd.print("%");

lcd.setCursor(10, 0);
lcd.print("T: ");
}
`
I'm currently working on a project for school and I hope this'll be resolved.

@porrey
Copy link
Owner

porrey commented Mar 27, 2022

The MAX17043 can only read a voltage of a single cell up to approximately 4.7V. Using two batteries in parallel would not be supported either.

Try issuing a reset() and then a quickstart() during initialization. See this example for more details: https://porrey.github.io/max1704x/examples/basic.

@porrey porrey closed this as completed Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants