Created
September 19, 2019 10:25
-
-
Save KunalGautam/b6f8265889c3798556164d047525c0b3 to your computer and use it in GitHub Desktop.
M5 Stack Battery Status using MicroPython
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
from m5stack import * | |
from m5ui import * | |
from uiflow import * | |
import machine | |
buf = bytearray(1) | |
CHARGE_100 = '0x00' | |
CHARGE_75 = '0x80' | |
CHARGE_50 = '0xC0' | |
CHARGE_25 = '0xE0' | |
CHARGE_0 = '0xF0' | |
value = 1 | |
setScreenColor(0x222222) | |
i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21)) | |
# devices = i2c.scan() | |
# if len(devices) == 0: | |
# text = "No Devices Found" | |
# else : | |
# for device in devices: | |
# text = device | |
label3 = M5TextBox(14, 140, str(value), lcd.FONT_Default, 0xFFFFFF, rotate=0) | |
while True: | |
i2c.readfrom_mem_into(0x75, 0x78, buf) | |
if bytearray([int(CHARGE_100)]) == buf: | |
value = 100 | |
else: | |
value = 2 | |
if bytearray([int(CHARGE_75)]) == buf: | |
value = 75 | |
if bytearray([int(CHARGE_50)]) == buf: | |
value = 50 | |
if bytearray([int(CHARGE_25)]) == buf: | |
value = 25 | |
if bytearray([int(CHARGE_0)]) == buf: | |
value = 0 | |
label3.setText(str(value)) | |
wait_ms(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment