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

Battery API #74

Closed
vshymanskyy opened this issue Jul 6, 2018 · 22 comments
Closed

Battery API #74

vshymanskyy opened this issue Jul 6, 2018 · 22 comments

Comments

@vshymanskyy
Copy link

Is there any way to get the battery charge level/status?

@0x1abin
Copy link
Contributor

0x1abin commented Jul 7, 2018

Sorry, the hardware nonsupport get the battery charge level.

@vshymanskyy
Copy link
Author

vshymanskyy commented Jul 7, 2018

@0x1abin I'm talking about FIRE, which presumably has IP5306_I2C.
Also this:
image

@0x1abin
Copy link
Contributor

0x1abin commented Jul 9, 2018

The FIRE can get the battery charge status by i2c, but can't get level.

@vshymanskyy
Copy link
Author

@0x1abin cool. Is there any info on how to get the status at least? )

@0x1abin
Copy link
Contributor

0x1abin commented Jul 10, 2018

The power IC IP5306 datasheet is Chinese :D ..., I write a simple function:
https://github.com/m5stack/M5Stack/blob/m5stack-fire/src/M5Stack.cpp#L70

@Loran425
Copy link

@0x1abin
This function looks great.
Is there any chance of getting an I2C register map for the power IC?

@plex555
Copy link

plex555 commented Dec 19, 2018

IP5306 registers map:
https://yadi.sk/i/dRp0HTF4oPCo2g

IP5209 IP5109 IP5207 IP5108 registers map:
https://yadi.sk/i/oNhqTei36jFwSg

A bit more about IP5108, but only russian language (google translater help you):
https://wiki.iarduino.ru/page/Battery_Shield/

Battery Shield Libary for arduino (with Register description):
http://iarduino.ru/file/344.html

P.S. If somebody understand power IC (such as IP5*) programming, can you help save my settings in default register. If I put power off, all my I2C settings will set default and don't want each time connect my power chip to arduino and change settings.

@lovyan03
Copy link
Contributor

I found it.
If manufacturing time is newer than FIRE release, it is also possible for GRAY and BASIC.

https://mobile.twitter.com/lovyan03/status/1104548868199337984

image

@lovyan03
Copy link
Contributor

int8_t getBatteryLevel()
{
  Wire.beginTransmission(0x75);
  Wire.write(0x78);
  if (Wire.endTransmission(false) == 0
   && Wire.requestFrom(0x75, 1)) {
    switch (Wire.read() & 0xF0) {
    case 0xE0: return 25;
    case 0xC0: return 50;
    case 0x80: return 75;
    case 0x00: return 100;
    default: return 0;
    }
  }
  return -1;
}

@EeeeBin
Copy link
Contributor

EeeeBin commented Mar 11, 2019

It looks great, I will check it and add put it to power.c

@KOsterOk2
Copy link

BASIC no work. Return -1

@lovyan03
Copy link
Contributor

image

It will not work if the manufacturing date is old.
If it is new, BASIC and GRAY will also work.

@KOsterOk2
Copy link

My BASIC is 2018.03 . Can you post all Code here ?

@lovyan03
Copy link
Contributor

Perhaps the differences between versions of various libraries may affect you.
If there is a 0x75 response with "I2C Scanner" it should work.

I cut out only the necessary parts from this project.
https://github.com/lovyan03/M5Stack_LovyanLauncher

@lovyan03
Copy link
Contributor

Did you run "Wire.begin()" ?

void setup() {
  M5.begin();
  Wire.begin();
・・・

@KOsterOk2
Copy link

Now it works! Thanks you!

#include <M5Stack.h>

int8_t getBatteryLevel()
{
  Wire.beginTransmission(0x75);
  Wire.write(0x78);
  if (Wire.endTransmission(false) == 0
   && Wire.requestFrom(0x75, 1)) {
    switch (Wire.read() & 0xF0) {
    case 0xE0: return 25;
    case 0xC0: return 50;
    case 0x80: return 75;
    case 0x00: return 100;
    default: return 0;
    }
  }
  return -1;
}

void setup() {
    M5.begin();
    Wire.begin();
  }

void loop() {
  delay(1000);
  M5.Lcd.clear();
  M5.Lcd.setTextColor(GREEN);
  M5.Lcd.setCursor(0, 20);
  M5.Lcd.setTextSize(2);
  M5.Lcd.print("Battery Level: ");
  M5.Lcd.print(getBatteryLevel());
  M5.Lcd.print("%");
}

@ghost
Copy link

ghost commented May 4, 2019

Will it work with the 700mAh battery board attached?

@tatsuya-takahashi
Copy link

Will it work with the 700mAh battery board attached?

It worked for me with 700mAh battery.

@tialm
Copy link

tialm commented May 18, 2020

Would this work in the 2018.2A version?

@guido-visser
Copy link

Is there any way to make this work on the M5Stick-C as well?

@Neil-McK
Copy link

Update: Try M5.Power.getBatteryLevel() and M5.Power.isChargeFull() functions in standard M5Stack.h library.

@Knockoi
Copy link

Knockoi commented Sep 27, 2023

Excuse me. Can I help you? Do you have a more detailed Arduino program? I don't know much about the I2C mechanism of the IP series charging ICs, I just need to display the battery level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests