2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

M5Stack Core2でバッテリー関連の情報を得る時

Last updated at Posted at 2021-02-28

M5Stackで電源関連は

#include <M5Stack.h>

void setup(){
  M5.begin();
  M5.Power.begin();
}
void loop(){
  if(M5.Power.canControl()){
    M5.Lcd.printf("%3d \%",M5.Power.getBatteryLevel());
  }
}

もしくは

#include <M5Stack.h>

void setup(){
  M5.begin();
  Wire.beginTransmission(0x75);
  Wire.begin();
}
void loop(){
  int battlevel = -1;
  byte retval;

  Wire.beginTransmission(0x75);
  Wire.write(0x78);
  Wire.endTransmission(false);
  if (Wire.endTransmission(false) == 0 && Wire.requestFrom(0x75, 1)) {
    retval = Wire.read() & 0xF0;
    if (retval == 0xE0) battlevel = 25;
    else if (retval == 0xC0) battlevel = 50;
    else if (retval == 0x80) battlevel = 75;
    else if (retval == 0x00) battlevel = 100;
  }
  M5.Lcd.printf("%3d \%",battlevel);
}

のようなコードで取得できます。
ですがCore2にはM5.Powerというものがありません。
なので以下のようにして取得します。
※残量のパーセンテージなどでは取得できないので要注意

#include <M5Core2.h>
#include <Wire.h>
#include <AXP192.h>
AXP192 power;

void setup(){
  M5.begin();
}
void loop(){
  M5.Lcd.printf("%3.4f V",power.GetBatVoltage());
}
2
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?