Created
October 14, 2019 10:00
-
-
Save weldtype/187fc9d3f1b29d7a0db6632881dff075 to your computer and use it in GitHub Desktop.
M5StickCのバッテリー電圧、放電電流、充電電流を測る
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
M5StickC | |
バッテリ電圧、放電電流、充電電流を調べてみる | |
2019/10/09 edy | |
*/ | |
#include <M5StickC.h> | |
#include <Wire.h> | |
void setup() { | |
M5.begin(); | |
Wire.begin(0, 26); | |
M5.Lcd.setRotation(3); | |
M5.Lcd.fillScreen(BLACK); | |
M5.Axp.ScreenBreath(10); // 画面の輝度を設定(7-15) | |
//setCpuFrequencyMhz(20); // CPUクロック設定 | |
} | |
void loop() { | |
double vbat = M5.Axp.GetVbatData() * 1.1 / 1000; // バッテリー電圧 | |
double idischarge = M5.Axp.GetIdischargeData() * 0.5; // バッテリー放電電流 | |
double icharge = M5.Axp.GetIchargeData() * 0.5; // バッテリー充電電流 | |
M5.Lcd.setCursor(0, 2, 4); | |
M5.Lcd.fillScreen(BLACK); // 不要だが画面アップデート確認のため入れてある。 | |
M5.Lcd.printf("vbat: %4.2fV\r\n", vbat); | |
M5.Lcd.printf("Idis: %4.0fmA \r\n", idischarge); // mAの後に二つスペースを入れてある。描画ごみ対策 | |
M5.Lcd.printf("Ichg: %4.0fmA \r\n", icharge); | |
delay(500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment