Battery API
vshymanskyy opened this issue ยท 22 comments
Is there any way to get the battery charge level/status?
Sorry, the hardware nonsupport get the battery charge level.
@0x1abin I'm talking about FIRE, which presumably has IP5306_I2C
.
Also this:
The FIRE can get the battery charge status by i2c, but can't get level.
@0x1abin cool. Is there any info on how to get the status at least? )
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
@0x1abin
This function looks great.
Is there any chance of getting an I2C register map for the power IC?
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.
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
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;
}
It looks great, I will check it and add put it to power.c
BASIC no work. Return -1
My BASIC is 2018.03 . Can you post all Code here ?
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
Did you run "Wire.begin()" ?
void setup() {
M5.begin();
Wire.begin();
ใปใปใป
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("%");
}
Will it work with the 700mAh battery board attached?
Will it work with the 700mAh battery board attached?
It worked for me with 700mAh battery.
Would this work in the 2018.2A version?
Is there any way to make this work on the M5Stick-C as well?
Update: Try M5.Power.getBatteryLevel() and M5.Power.isChargeFull() functions in standard M5Stack.h library.
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.