From 5147f07ae38440100873353ac4e1bd0322badf9b Mon Sep 17 00:00:00 2001 From: Phil Martin Date: Wed, 12 Feb 2020 13:33:56 +0000 Subject: [PATCH] Ported pico_status_hv3.0.py to python3 Also added Li-Ion battery support, support for auto fan mode, reading of fan auto on temperature and fan_speed now returns PWM % rather than RPM --- pico_status/pico_status_hv3.0.py | 125 +++++++++++++++++-------------- 1 file changed, 67 insertions(+), 58 deletions(-) diff --git a/pico_status/pico_status_hv3.0.py b/pico_status/pico_status_hv3.0.py index 9e7be5d..783d6c5 100644 --- a/pico_status/pico_status_hv3.0.py +++ b/pico_status/pico_status_hv3.0.py @@ -2,6 +2,15 @@ ##################################################################################### # pico_status_hv3.0.py +# +# updated: 20-01-2020 by frillip +# - Ported to python3 as python2 is now end of life +# - Added support for Li-Ion battery type +# - Removed sleep(0.1) statements +# - Added read of fan auto on temperature +# - Added support for 'auto' fan mode +# - fan_speed() now properly returns percentage rather than RPM +# # updated: 20-01-2017 # Script to show you some statistics pulled from your UPS PIco HV3.0A @@ -18,26 +27,21 @@ # It's not necessary to edit anything below this line unless your knowing what to do! ##################################################################################### -import smbus -import time -import datetime +from smbus2 import SMBus -i2c = smbus.SMBus(1) +i2c = SMBus(1) def fw_version(): - time.sleep(0.1) data = i2c.read_byte_data(0x69, 0x26) data = format(data,"02x") return data def boot_version(): - time.sleep(0.1) data = i2c.read_byte_data(0x69, 0x25) data = format(data,"02x") return data def pcb_version(): - time.sleep(0.1) data = i2c.read_byte_data(0x69, 0x24) data = format(data,"02x") return data @@ -53,7 +57,6 @@ def pwr_mode(): return "ERROR" def bat_version(): - time.sleep(0.1) data = i2c.read_byte_data(0x6b, 0x07) if (data == 0x46): return "LiFePO4 (ASCII : F)" @@ -63,11 +66,14 @@ def bat_version(): return "LiPO (ASCII: S)" elif (data == 0x50): return "LiPO (ASCII: P)" + elif (data == 0x49): + return "Li-Ion (ASCII: I)" + elif (data == 0x4F): + return "Li-Ion (ASCII: O)" else: return "ERROR" def bat_runtime(): - time.sleep(0.1) data = i2c.read_byte_data(0x6b, 0x01) + 1 if (data == 0x100): return "TIMER DISABLED" @@ -78,30 +84,27 @@ def bat_runtime(): return data def bat_level(): - time.sleep(0.1) data = i2c.read_word_data(0x69, 0x08) data = format(data,"02x") return (float(data) / 100) def bat_percentage(): - time.sleep(0.1) datavolts = bat_level() databattery = bat_version() if (databattery == "LiFePO4 (ASCII : F)") or (databattery == "LiFePO4 (ASCII : Q)"): datapercentage = ((datavolts-2.9)/1.25)*100 - elif (databattery == "LiPO (ASCII: S)") or (databattery == "LiPO (ASCII: P)"): datapercentage = ((datavolts-3.4)/0.75)*100 + elif (databattery == "Li-Ion (ASCII: I)") or (databattery == "Li-Ion (ASCII: O)"): + datapercentage = ((datavolts-3.4)/0.75)*100 return datapercentage def rpi_level(): - time.sleep(0.1) data = i2c.read_word_data(0x69, 0x0a) data = format(data,"02x") return (float(data) / 100) def ntc1_temp(): - time.sleep(0.1) data = i2c.read_byte_data(0x69, 0x1b) data = format(data,"02x") if (degrees == "C"): @@ -110,7 +113,6 @@ def ntc1_temp(): return (float(data) * 9 / 5) + 32 def to92_temp(): - time.sleep(0.1) data = i2c.read_byte_data(0x69, 0x1C) data = format(data,"02x") if (degrees == "C"): @@ -119,22 +121,21 @@ def to92_temp(): return (float(data) * 9 / 5) + 32 def epr_read(): - time.sleep(0.1) data = i2c.read_word_data(0x69, 0x0c) data = format(data,"02x") return (float(data) / 100) def ad2_read(): - time.sleep(0.1) data = i2c.read_word_data(0x69, 0x14) data = format(data,"02x") return (float(data) / 100) - + def fan_mode(): - time.sleep(0.1) data = i2c.read_byte_data(0x6b, 0x11) data = data & ~(1 << 2) - if (data == 1): + if (data == 2): + return "AUTO" + elif (data == 1): return "ENABLED" elif (data == 0): return "DISABLED" @@ -142,7 +143,6 @@ def fan_mode(): return "ERROR" def fan_state(): - time.sleep(0.1) data = i2c.read_byte_data(0x6b, 0x13) data = data & ~(1 << 2) if (data == 1): @@ -153,13 +153,18 @@ def fan_state(): return "ERROR" def fan_speed(): - time.sleep(0.1) data = i2c.read_word_data(0x6b, 0x12) + return data + +def fan_auto_temp(): + data = i2c.read_byte_data(0x6B, 0x14) data = format(data,"02x") - return (float(data) * 10) + if (degrees == "C"): + return data + elif (degrees == "F"): + return (float(data) * 9 / 5) + 32 def r232_state(): - time.sleep(0.1) data = i2c.read_byte_data(0x6b, 0x02) if (data == 0x00): return "OFF" @@ -178,41 +183,45 @@ def r232_state(): else: return "ERROR" -print " " -print "***********************************" -print " UPS PIco HV3.0A Status " -print "***********************************" -print " " -print " ","UPS PIco Firmware.....:",fw_version() -print " ","UPS PIco Bootloader...:",boot_version() -print " ","UPS PIco PCB Version..:",pcb_version() -print " ","UPS PIco BAT Version..:",bat_version() -print " ","UPS PIco BAT Runtime..:",bat_runtime() -print " ","UPS PIco r232 State...:",r232_state() -print " " -print " ","Powering Mode.........:",pwr_mode() -print " ","BAT Percentage........:",bat_percentage(),"%" -print " ","BAT Voltage...........:",bat_level(),"V" -print " ","RPi Voltage...........:",rpi_level(),"V" +print(" ") +print("***********************************") +print(" UPS PIco HV3.0A Status ") +print("***********************************") +print(" ") +print(" ","UPS PIco Firmware.....:",fw_version()) +print(" ","UPS PIco Bootloader...:",boot_version()) +print(" ","UPS PIco PCB Version..:",pcb_version()) +print(" ","UPS PIco BAT Version..:",bat_version()) +print(" ","UPS PIco BAT Runtime..:",bat_runtime()) +print(" ","UPS PIco r232 State...:",r232_state()) +print(" ") +print(" ","Powering Mode.........:",pwr_mode()) +print(" ","BAT Percentage........:",bat_percentage(),"%") +print(" ","BAT Voltage...........:",bat_level(),"V") +print(" ","RPi Voltage...........:",rpi_level(),"V") if (degrees == "C"): - print " ","NTC1 Temperature......:",ntc1_temp(),"C" - print " ","TO-92 Temperature.....:",to92_temp(),"C" + print(" ","NTC1 Temperature......:",ntc1_temp(),"C") + print(" ","TO-92 Temperature.....:",to92_temp(),"C") elif (degrees == "F"): - print " ","NTC1 Temperature......:",ntc1_temp(),"F" - print " ","TO-92 Temperature.....:",to92_temp(),"F" + print(" ","NTC1 Temperature......:",ntc1_temp(),"F") + print(" ","TO-92 Temperature.....:",to92_temp(),"F") else: - print " ","NTC1 Temperature......: please set your desired temperature symbol!" - print " ","TO-92 Temperature.....: please set your desired temperature symbol!" - -print " ","Extended Voltage......:",epr_read(),"V" -print " ","A/D2 Voltage..........:",ad2_read(),"V" -print " " -print " ","PIco FAN Mode.........:",fan_mode() -print " ","PIco FAN State........:",fan_state() -print " ","PIco FAN Speed........:",fan_speed(),"RPM" -print " " -print "***********************************" -print " Powered by PiCo " -print "***********************************" -print " " \ No newline at end of file + print(" ","NTC1 Temperature......: please set your desired temperature symbol!") + print(" ","TO-92 Temperature.....: please set your desired temperature symbol!") + +print(" ","Extended Voltage......:",epr_read(),"V") +print(" ","A/D2 Voltage..........:",ad2_read(),"V") +print(" ") +print(" ","PIco FAN Mode.........:",fan_mode()) +print(" ","PIco FAN State........:",fan_state()) +print(" ","PIco FAN Speed........:",fan_speed(),"%") +if (degrees == "C"): + print(" ","PIco FAN Auto On Temp.:",fan_auto_temp(),"C") +elif (degrees == "F"): + print(" ","PIco FAN Auto On Temp.:",fan_auto_temp(),"F") +print(" ") +print("***********************************") +print(" Powered by PiCo ") +print("***********************************") +print(" ")