Untitled

mail@pastecode.io avatar
unknown
plain_text
15 days ago
549 B
1
Indexable
Never
# x728.py
import smbus
import time

bus = smbus.SMBus(0)
address = 0x36

def readVoltage():
    read = bus.read_word_data(address, 2)
    swapped = ((read & 0xFF) << 8) | (read >> 8)
    voltage = swapped * 78.125 / 1000000
    return voltage

def readCapacity():
    read = bus.read_word_data(address, 4)
    swapped = ((read & 0xFF) << 8) | (read >> 8)
    capacity = swapped / 256
    return capacity

while True:
    print("Voltage: %.2fV" % readVoltage())
    print("Capacity: %.2f%%" % readCapacity())
    time.sleep(2)
Leave a Comment