General Raspberry Pi

DFR0528 UPS hat for Raspberry PI - Update to program (voltage, battery%)to also show board version

userHead Shaun.Jepson 2025-05-14 14:31:50 340 Views1 Replies

I have updated the python program supplied with the board for voltage and battery %. It now also prints the board version.

 

import smbus
ups_addr=0x10 #ups i2c address
bus=smbus.SMBus(1) #i2c-1
versionboard=bus.read_byte_data(ups_addr,0x02)
vcellH=bus.read_byte_data(ups_addr,0x03)
vcellL=bus.read_byte_data(ups_addr,0x04)
socH=bus.read_byte_data(ups_addr,0x05)
socL=bus.read_byte_data(ups_addr,0x06)

capacity=(((vcellH&0x0F)<<8)+vcellL)*1.25 #capacity
electricity=((socH<<8)+socL)*0.003906 #current electric quantity percentage
mainversionboard=(versionboard)>>4
subversionboard=versionboard&0x0F
print("board version=%d.%d"%(mainversionboard, subversionboard))
print("capacity=%dmV"%capacity)
print("electricity percentage=%.2f"%electricity)

 

2025-05-14 16:17:25

Thank you for sharing the updated code to display voltage, battery percentage, and board version! This will be very helpful for users utilizing the DFR0528 UPS HAT. 

userHeadPic Tonny12138