From 6ae1edaaf2de5f47d8829d5d359679718affa349 Mon Sep 17 00:00:00 2001 From: Martin Boissonneault Date: Sat, 2 Feb 2019 01:38:59 -0500 Subject: [PATCH 1/9] Fix FAN mode 0x02 shown as ERROR --- pico_status/pico_status_hv3.0.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pico_status/pico_status_hv3.0.py b/pico_status/pico_status_hv3.0.py index 9e7be5d..4315dc7 100644 --- a/pico_status/pico_status_hv3.0.py +++ b/pico_status/pico_status_hv3.0.py @@ -138,6 +138,8 @@ def fan_mode(): return "ENABLED" elif (data == 0): return "DISABLED" + elif (data == 2): + return "AUTO" else: return "ERROR" @@ -215,4 +217,4 @@ def r232_state(): print "***********************************" print " Powered by PiCo " print "***********************************" -print " " \ No newline at end of file +print " " From 0c21802701a0b0e7fdbb072be287db416a05ebed Mon Sep 17 00:00:00 2001 From: Martin Boissonneault Date: Sat, 2 Feb 2019 17:39:23 -0500 Subject: [PATCH 2/9] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8d99dff..705c4ea 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ files.txt +pico_status/pico_status_0x30.zip From f5f9f6347aa1e34839779e7a294ec91c98650ae7 Mon Sep 17 00:00:00 2001 From: Martin Boissonneault Date: Sat, 2 Feb 2019 17:40:01 -0500 Subject: [PATCH 3/9] Add pico_status v6.0 from forum --- pico_status/pico_status.py | 315 +++++++++++++++++++++++++++++++++++++ 1 file changed, 315 insertions(+) create mode 100644 pico_status/pico_status.py diff --git a/pico_status/pico_status.py b/pico_status/pico_status.py new file mode 100644 index 0000000..4c3d98a --- /dev/null +++ b/pico_status/pico_status.py @@ -0,0 +1,315 @@ +#!/usr/bin/python + +##################################################################################### +# pico_status.py +# author : Kyriakos Naziris +# updated: 1-12-2017 +# Script to show you some statistics pulled from your UPS PIco HV3.0A + +# -*- coding: utf-8 -*- +# improved and completed by PiModules Version 1.0 29.08.2015 +# picoStatus-v3.py by KTB is based on upisStatus.py by Kyriakos Naziris +# Kyriakos Naziris / University of Portsmouth / kyriakos@naziris.co.uk +# +# As per 09-01-2017 +# Improved and modified for PiModules PIco HV3.0A Stack Plus / Plus / Top +# by Siewert Lameijer aka Siewert308SW +##################################################################################### + +# You can install psutil using: sudo pip install psutil +#import psutil + +##################################################################################### +# SETTINGS +##################################################################################### + +# Set your desired temperature symbol +# C = Celsius +# F = Fahrenheit +degrees = "F" + +# Do you have a PIco FAN kit installed? +# True or False +fankit = True + +# Do you have a to92 temp sensor installed? +# True or False +to92 = True + +# Do you have extended power? +# True or False +extpwr = False + +##################################################################################### +# It's not necessary to edit anything below, unless you're knowing what to do! +##################################################################################### + +import os +import smbus +import time +import datetime + +i2c = smbus.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 + +def pwr_mode(): + data = i2c.read_byte_data(0x69, 0x00) + data = data & ~(1 << 7) + if (data == 1): + return "RPi POWERED" + elif (data == 2): + return "BAT POWERED" + else: + return "ERROR" + +def bat_version(): + time.sleep(0.1) + data = i2c.read_byte_data(0x6b, 0x07) + if (data == 0x46): + return "LiFePO4 (ASCII : F)" + elif (data == 0x51): + return "LiFePO4 (ASCII : Q)" + elif (data == 0x53): + return "LiPO (ASCII: S)" + elif (data == 0x50): + return "LiPO (ASCII: P)" + else: + return "ERROR" + +def bat_runtime(): + time.sleep(0.1) + data = i2c.read_byte_data(0x6b, 0x01) + 1 + if (data == 0x100): + return "TIMER DISABLED" + elif (data == 0xff): + return "TIMER DISABLED" + else: + data = str(data)+ " MIN" + 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)"): + databatminus = datavolts-2.90 + datapercentage = ((databatminus/0.70))*100 + elif (databattery == "LiPO (ASCII: S)") or (databattery == "LiPO (ASCII: P)"): + databatminus = datavolts-3.4 + datapercentage = ((databatminus/0.899))*100 + return int (datapercentage) + + +def charger_state(): + time.sleep(0.1) + data = i2c.read_byte_data(0x69, 0x20) + battpercentage = bat_percentage() + powermode = pwr_mode() + databattery = bat_version() + if (databattery == "LiFePO4 (ASCII : F)") or (databattery == "LiFePO4 (ASCII : Q)"): + if (data == 0x00) and (powermode == "BAT POWERED"): + return "DISCHARGING" + if (data == 0x01) and (powermode == "RPi POWERED"): + return "CHARGING" + if (data == 0x00) and (powermode == "RPi POWERED"): + return "CHARGED" + if (databattery == "LiPO (ASCII: S)") or (databattery == "LiPO (ASCII: P)"): + if (data == 0x00) and (powermode == "BAT POWERED"): + return "DISCHARGING" + if (data == 0x00) and (powermode == "RPi POWERED"): + return "CHARGED" + if (data == 0x01) and (powermode == "RPi POWERED"): + return "CHARGING" + +def rpi_level(): + time.sleep(0.1) + data = i2c.read_word_data(0x69, 0x0a) + data = format(data,"02x") + powermode = pwr_mode() + if (powermode == "RPi POWERED"): + return (float(data) / 100) + else: + return "0.0" + +def rpi_cpu_temp(): + time.sleep(0.1) + data = os.popen('vcgencmd measure_temp').readline() + data = (data.replace("temp=","").replace("'C\n","")) + if (degrees == "C"): + return data + elif (degrees == "F"): + return (float(data) * 9 / 5) + 32 + +def ntc1_temp(): + time.sleep(0.1) + data = i2c.read_byte_data(0x69, 0x1b) + data = format(data,"02x") + if (degrees == "C"): + return data + elif (degrees == "F"): + 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"): + return data + elif (degrees == "F"): + return (float(data) * 9 / 5) + 32 + +def epr_read(): + time.sleep(0.1) + data = i2c.read_byte_data(0x69, 0x0c) + data = format(data,"02x") + return (float(data) / 100) + +def ad2_read(): + time.sleep(0.1) + data = i2c.read_byte_data(0x69, 0x07) + 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 == 2): + return "AUTOMATIC" + elif (data == 1): + return "ON" + elif (data == 0): + return "OFF" + else: + return "ERROR" + +def fan_speed(): + time.sleep(0.1) + data = i2c.read_byte_data(0x6b, 0x12) + data = format(data,"02x") + return int (float(data) * 100) + +def fan_threshold(): + time.sleep(0.1) + data = i2c.read_byte_data(0x6B, 0x14) + data = format(data,"02x") + if (degrees == "C"): + return data + elif (degrees == "F"): + return (float(data) * 9 / 5) + 32 + +def rs232_state(): + time.sleep(0.1) + data = i2c.read_byte_data(0x6b, 0x02) + if (data == 0x00): + return "OFF" + elif (data == 0xff): + return "OFF" + elif (data == 0x01): + return "ON @ 4800 pbs" + elif (data == 0x02): + return "ON @ 9600 pbs" + elif (data == 0x03): + return "ON @ 19200 pbs" + elif (data == 0x04): + return "ON @ 34600 pbs" + elif (data == 0x05): + return "ON @ 57600 pbs" + elif (data == 0x0f): + return "ON @ 115200 pbs" + else: + return "ERROR" + +print " " +print "**********************************************" +print "* UPS PIco HV3.0A Status *" +print "* Version 6.0 *" +print "**********************************************" +print " " +print " ","- PIco Firmware..........:",fw_version() +print " ","- PIco Bootloader........:",boot_version() +print " ","- PIco PCB Version.......:",pcb_version() +print " ","- PIco BAT Version.......:",bat_version() +print " ","- PIco BAT Runtime.......:",bat_runtime() +print " ","- PIco rs232 State.......:",rs232_state() +print " " +print " ","- Powering Mode..........:",pwr_mode() +print " ","- Charger State..........:",charger_state() +print " ","- Battery Percentage.....:",bat_percentage(),"%" +print " ","- Battery Voltage........:",bat_level(),"V" +print " ","- RPi Voltage............:",rpi_level(),"V" +print " " + +if (degrees == "C"): + print " ","- RPi CPU Temperature....:",rpi_cpu_temp(),"C" + print " ","- NTC1 Temperature.......:",ntc1_temp(),"C" +elif (degrees == "F"): + print " ","- RPi CPU Temperature....:",rpi_cpu_temp(),"F" + print " ","- NTC1 Temperature.......:",ntc1_temp(),"F" +else: + print " ","- RPi CPU Temperature....: please set temperature symbol in the script!" + print " ","- NTC1 Temperature.......: please set temperature symbol in the script!" + +if (to92 == True): + if (degrees == "C"): + print " ","- TO-92 Temperature......:",to92_temp(),"C" + elif (degrees == "F"): + print " ","- TO-92 Temperature......:",to92_temp(),"F" + else: + print " ","- TO-92 Temperature......: please set temperature symbol in the script!" + +if (extpwr == True): + print " ","- Extended Voltage.......:",epr_read(),"V" + print " ","- A/D2 Voltage...........:",ad2_read(),"V" + +if (fankit == True): + print " " +if (fan_mode() == "AUTOMATIC"): + print " ","- PIco FAN Mode..........:",fan_mode() + if (degrees == "C"): + print " ","- PIco FAN Temp Threshold:",fan_threshold(),"C" + elif (degrees == "F"): + print " ","- PIco FAN Temp Threshold:",fan_threshold(),"F" + else: + print " ","- PIco FAN Temp Threshold: please set temperature symbol in the script!" +else: + print " ","- PIco FAN Mode..........:",fan_mode() + if (fan_mode() == "ON"): + print " ","- PIco FAN Speed.........:",fan_speed(),"RPM" + else: + print " ","- PIco FAN Speed.........: 0 RPM" + + if (degrees == "C"): + print " ","- PIco FAN Temp Threshold:",fan_threshold(),"C" + elif (degrees == "F"): + print " ","- PIco FAN Temp Threshold:",fan_threshold(),"F" + else: + print " ","- PIco FAN Temp Threshold: please set temperature symbol in the script!" +print " " +print "**********************************************" +print "* Powered by PiModules *" +print "**********************************************" +print " " From 29c17b3b2c5eca2430db900e6250e32fd90aea3c Mon Sep 17 00:00:00 2001 From: Martin Boissonneault Date: Sat, 2 Feb 2019 17:41:41 -0500 Subject: [PATCH 4/9] Merge fan_state() from original --- pico_status/pico_status-mbt.py | 331 +++++++++++++++++++++++++++++++++ 1 file changed, 331 insertions(+) create mode 100644 pico_status/pico_status-mbt.py diff --git a/pico_status/pico_status-mbt.py b/pico_status/pico_status-mbt.py new file mode 100644 index 0000000..90ac492 --- /dev/null +++ b/pico_status/pico_status-mbt.py @@ -0,0 +1,331 @@ +#!/usr/bin/python + +##################################################################################### +# pico_status.py +# author : Kyriakos Naziris +# updated: 1-12-2017 +# Script to show you some statistics pulled from your UPS PIco HV3.0A + +# -*- coding: utf-8 -*- +# improved and completed by PiModules Version 1.0 29.08.2015 +# picoStatus-v3.py by KTB is based on upisStatus.py by Kyriakos Naziris +# Kyriakos Naziris / University of Portsmouth / kyriakos@naziris.co.uk +# +# As per 09-01-2017 +# Improved and modified for PiModules PIco HV3.0A Stack Plus / Plus / Top +# by Siewert Lameijer aka Siewert308SW +##################################################################################### + +# You can install psutil using: sudo pip install psutil +#import psutil + +##################################################################################### +# SETTINGS +##################################################################################### + +# Set your desired temperature symbol +# C = Celsius +# F = Fahrenheit +degrees = "C" + +# Do you have a PIco FAN kit installed? +# True or False +fankit = True + +# Do you have a to92 temp sensor installed? +# True or False +to92 = True + +# Do you have extended power? +# True or False +extpwr = False + +##################################################################################### +# It's not necessary to edit anything below, unless you're knowing what to do! +##################################################################################### + +import os +import smbus +import time +import datetime + +i2c = smbus.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 + +def pwr_mode(): + data = i2c.read_byte_data(0x69, 0x00) + data = data & ~(1 << 7) + if (data == 1): + return "RPi POWERED" + elif (data == 2): + return "BAT POWERED" + else: + return "ERROR" + +def bat_version(): + time.sleep(0.1) + data = i2c.read_byte_data(0x6b, 0x07) + if (data == 0x46): + return "LiFePO4 (ASCII : F)" + elif (data == 0x51): + return "LiFePO4 (ASCII : Q)" + elif (data == 0x53): + return "LiPO (ASCII: S)" + elif (data == 0x50): + return "LiPO (ASCII: P)" + else: + return "ERROR" + +def bat_runtime(): + time.sleep(0.1) + data = i2c.read_byte_data(0x6b, 0x01) + 1 + if (data == 0x100): + return "TIMER DISABLED" + elif (data == 0xff): + return "TIMER DISABLED" + else: + data = str(data)+ " MIN" + 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)"): + databatminus = datavolts-2.90 + datapercentage = ((databatminus/0.70))*100 + elif (databattery == "LiPO (ASCII: S)") or (databattery == "LiPO (ASCII: P)"): + databatminus = datavolts-3.4 + datapercentage = ((databatminus/0.899))*100 + return int (datapercentage) + + +def charger_state(): + time.sleep(0.1) + data = i2c.read_byte_data(0x69, 0x20) + battpercentage = bat_percentage() + powermode = pwr_mode() + databattery = bat_version() + if (databattery == "LiFePO4 (ASCII : F)") or (databattery == "LiFePO4 (ASCII : Q)"): + if (data == 0x00) and (powermode == "BAT POWERED"): + return "DISCHARGING" + if (data == 0x01) and (powermode == "RPi POWERED"): + return "CHARGING" + if (data == 0x00) and (powermode == "RPi POWERED"): + return "CHARGED" + if (databattery == "LiPO (ASCII: S)") or (databattery == "LiPO (ASCII: P)"): + if (data == 0x00) and (powermode == "BAT POWERED"): + return "DISCHARGING" + if (data == 0x00) and (powermode == "RPi POWERED"): + return "CHARGED" + if (data == 0x01) and (powermode == "RPi POWERED"): + return "CHARGING" + +def rpi_level(): + time.sleep(0.1) + data = i2c.read_word_data(0x69, 0x0a) + data = format(data,"02x") + powermode = pwr_mode() + if (powermode == "RPi POWERED"): + return (float(data) / 100) + else: + return "0.0" + +def rpi_cpu_temp(): + time.sleep(0.1) + data = os.popen('vcgencmd measure_temp').readline() + data = (data.replace("temp=","").replace("'C\n","")) + if (degrees == "C"): + return data + elif (degrees == "F"): + return (float(data) * 9 / 5) + 32 + +def ntc1_temp(): + time.sleep(0.1) + data = i2c.read_byte_data(0x69, 0x1b) + data = format(data,"02x") + if (degrees == "C"): + return data + elif (degrees == "F"): + 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"): + return data + elif (degrees == "F"): + 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 == 2): + return "AUTOMATIC" + elif (data == 1): + return "ON" + elif (data == 0): + return "OFF" + else: + return "ERROR" + +def fan_state(): + time.sleep(0.1) + data = i2c.read_byte_data(0x6b, 0x13) + data = data & ~(1 << 2) + if (data == 1): + return "ON" + elif (data == 0): + return "OFF" + else: + return "ERROR" + +def fan_speed(): + time.sleep(0.1) + data = i2c.read_byte_data(0x6b, 0x12) + data = format(data,"02x") + return int (float(data) * 100) + +def fan_threshold(): + time.sleep(0.1) + data = i2c.read_byte_data(0x6B, 0x14) + data = format(data,"02x") + if (degrees == "C"): + return data + elif (degrees == "F"): + return (float(data) * 9 / 5) + 32 + +def rs232_state(): + time.sleep(0.1) + data = i2c.read_byte_data(0x6b, 0x02) + if (data == 0x00): + return "OFF" + elif (data == 0xff): + return "OFF" + elif (data == 0x01): + return "ON @ 4800 pbs" + elif (data == 0x02): + return "ON @ 9600 pbs" + elif (data == 0x03): + return "ON @ 19200 pbs" + elif (data == 0x04): + return "ON @ 34600 pbs" + elif (data == 0x05): + return "ON @ 57600 pbs" + elif (data == 0x0f): + return "ON @ 115200 pbs" + else: + return "ERROR" + +print " " +print "**********************************************" +print "* UPS PIco HV3.0A Status *" +print "* Version 6.0-mbt *" +print "**********************************************" +print " " +print " ","- PIco Firmware..........:",fw_version() +print " ","- PIco Bootloader........:",boot_version() +print " ","- PIco PCB Version.......:",pcb_version() +print " ","- PIco BAT Version.......:",bat_version() +print " ","- PIco BAT Runtime.......:",bat_runtime() +print " ","- PIco rs232 State.......:",rs232_state() +print " " +print " ","- Powering Mode..........:",pwr_mode() +print " ","- Charger State..........:",charger_state() +print " ","- Battery Percentage.....:",bat_percentage(),"%" +print " ","- Battery Voltage........:",bat_level(),"V" +print " ","- RPi Voltage............:",rpi_level(),"V" +print " " + +if (degrees == "C"): + print " ","- RPi CPU Temperature....:",rpi_cpu_temp(),"C" + print " ","- NTC1 Temperature.......:",ntc1_temp(),"C" +elif (degrees == "F"): + print " ","- RPi CPU Temperature....:",rpi_cpu_temp(),"F" + print " ","- NTC1 Temperature.......:",ntc1_temp(),"F" +else: + print " ","- RPi CPU Temperature....: please set temperature symbol in the script!" + print " ","- NTC1 Temperature.......: please set temperature symbol in the script!" + +if (to92 == True): + if (degrees == "C"): + print " ","- TO-92 Temperature......:",to92_temp(),"C" + elif (degrees == "F"): + print " ","- TO-92 Temperature......:",to92_temp(),"F" + else: + print " ","- TO-92 Temperature......: please set temperature symbol in the script!" + +if (extpwr == True): + print " ","- Extended Voltage.......:",epr_read(),"V" + print " ","- A/D2 Voltage...........:",ad2_read(),"V" + +if (fankit == True): + print " " +if (fan_mode() == "AUTOMATIC"): + print " ","- PIco FAN Mode..........:",fan_mode() + print " ","- PIco FAN State.........:",fan_state() + if (fan_state() == "ON"): + print " ","- PIco FAN Speed.........:",fan_speed(),"RPM" + else: + print " ","- PIco FAN Speed.........: 0 RPM" + if (degrees == "C"): + print " ","- PIco FAN Temp Threshold:",fan_threshold(),"C" + elif (degrees == "F"): + print " ","- PIco FAN Temp Threshold:",fan_threshold(),"F" + else: + print " ","- PIco FAN Temp Threshold: please set temperature symbol in the script!" +else: + print " ","- PIco FAN Mode..........:",fan_mode() + if (fan_mode() == "ON"): + print " ","- PIco FAN Speed.........:",fan_speed(),"RPM" + else: + print " ","- PIco FAN Speed.........: 0 RPM" + + if (degrees == "C"): + print " ","- PIco FAN Temp Threshold:",fan_threshold(),"C" + elif (degrees == "F"): + print " ","- PIco FAN Temp Threshold:",fan_threshold(),"F" + else: + print " ","- PIco FAN Temp Threshold: please set temperature symbol in the script!" +print " " +print "**********************************************" +print "* Powered by PiModules *" +print "**********************************************" +print " " From 36e6125cf82f5b4b0d2397405132ab27bf74db1c Mon Sep 17 00:00:00 2001 From: Martin Boissonneault Date: Sat, 2 Feb 2019 18:12:21 -0500 Subject: [PATCH 5/9] Modify script to use rpi_cpu_temp --- temp_fan/pico_temp_fan-mbt.py | 78 +++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 temp_fan/pico_temp_fan-mbt.py diff --git a/temp_fan/pico_temp_fan-mbt.py b/temp_fan/pico_temp_fan-mbt.py new file mode 100644 index 0000000..f08b7cc --- /dev/null +++ b/temp_fan/pico_temp_fan-mbt.py @@ -0,0 +1,78 @@ +#!/usr/bin/python + +import os +import logging +import smbus +from time import sleep + +logging.basicConfig(filename='/home/pi/PiModules/temp_fan/error.log',level=logging.INFO) + +# Set your desired temperature symbol +# C = Celsius +# F = Fahrenheit +degrees = "C" + +pico = smbus.SMBus(1) + +# function to get temperature from TO92 sensor +def to92_temp(): + data = pico.read_byte_data(0x69, 0x1C) + data = format(data,"02x") + if (degrees == "C"): + return float(data) + elif (degrees == "F"): + return (float(data) * 9 / 5) + 32 + +def rpi_cpu_temp(): + time.sleep(0.1) + data = os.popen('vcgencmd measure_temp').readline() + data = (data.replace("temp=","").replace("'C\n","")) + if (degrees == "C"): + return float(data) + elif (degrees == "F"): + return (float(data) * 9 / 5) + 32 + +def ntc1_temp(): + time.sleep(0.1) + data = i2c.read_byte_data(0x69, 0x1b) + data = format(data,"02x") + if (degrees == "C"): + return float(data) + elif (degrees == "F"): + return (float(data) * 9 / 5) + 32 + +# function to set the fan speed +def set_fan_speed(speed): + logging.info("setting fan speed: %s",speed) + pico.write_byte_data(0x6b, 0x11, 0x00) # turn fan off + pico.write_byte_data(0x6b, 0x12, speed) # set speed + pico.write_byte_data(0x6b, 0x11, 0x01) # turn fan on + +prev_temp = 0 + +while True: + try: + logging.info("checking temp") + temp = rpi_cpu_temp() + #temp = to92_temp() + logging.info("current temperature: %s",temp) + if temp != prev_temp: # check if temp has changed, no need to make unnecessary i2c calls + prev_temp = temp # update prev_temp variable to current temp to compare next time + +# setup temperature thresholds to set the fan at different speeds + + if temp <= 30: + set_fan_speed(0) + if temp > 30: + set_fan_speed(25) + if temp > 60: + set_fan_speed(50) + if temp > 70: + set_fan_speed(75) + if temp > 80: + set_fan_speed(100) + except: + logging.exception("Exception message:") + sleep(900) # wait 15 minutes + + From ee07537dfa46098f9cf219a68e7a4a71f902d1ae Mon Sep 17 00:00:00 2001 From: Martin Boissonneault Date: Sat, 2 Feb 2019 18:23:21 -0500 Subject: [PATCH 6/9] Made to return float(data) where it was not uniform Some places would return as float for 'F', but not 'C'. Now returns float for 'C' too. --- pico_status/pico_status-mbt.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pico_status/pico_status-mbt.py b/pico_status/pico_status-mbt.py index 90ac492..0426597 100644 --- a/pico_status/pico_status-mbt.py +++ b/pico_status/pico_status-mbt.py @@ -159,7 +159,7 @@ def rpi_cpu_temp(): data = os.popen('vcgencmd measure_temp').readline() data = (data.replace("temp=","").replace("'C\n","")) if (degrees == "C"): - return data + return float(data) elif (degrees == "F"): return (float(data) * 9 / 5) + 32 @@ -168,7 +168,7 @@ def ntc1_temp(): data = i2c.read_byte_data(0x69, 0x1b) data = format(data,"02x") if (degrees == "C"): - return data + return float(data) elif (degrees == "F"): return (float(data) * 9 / 5) + 32 @@ -177,7 +177,7 @@ def to92_temp(): data = i2c.read_byte_data(0x69, 0x1C) data = format(data,"02x") if (degrees == "C"): - return data + return float(data) elif (degrees == "F"): return (float(data) * 9 / 5) + 32 From 80d232f9940367e049015917ebc278f269cb6f55 Mon Sep 17 00:00:00 2001 From: Martin Boissonneault Date: Sat, 2 Feb 2019 19:38:13 -0500 Subject: [PATCH 7/9] Reindent code --- pico_status/pico_status-mbt.py | 439 ++++++++++++++++----------------- 1 file changed, 219 insertions(+), 220 deletions(-) diff --git a/pico_status/pico_status-mbt.py b/pico_status/pico_status-mbt.py index 0426597..dfbbb63 100644 --- a/pico_status/pico_status-mbt.py +++ b/pico_status/pico_status-mbt.py @@ -52,212 +52,211 @@ i2c = smbus.SMBus(1) def fw_version(): - time.sleep(0.1) - data = i2c.read_byte_data(0x69, 0x26) - data = format(data,"02x") - return data - + 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 + 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 + time.sleep(0.1) + data = i2c.read_byte_data(0x69, 0x24) + data = format(data,"02x") + return data def pwr_mode(): - data = i2c.read_byte_data(0x69, 0x00) - data = data & ~(1 << 7) - if (data == 1): - return "RPi POWERED" - elif (data == 2): - return "BAT POWERED" - else: - return "ERROR" - + data = i2c.read_byte_data(0x69, 0x00) + data = data & ~(1 << 7) + if (data == 1): + return "RPi POWERED" + elif (data == 2): + return "BAT POWERED" + else: + return "ERROR" + def bat_version(): - time.sleep(0.1) - data = i2c.read_byte_data(0x6b, 0x07) - if (data == 0x46): - return "LiFePO4 (ASCII : F)" - elif (data == 0x51): - return "LiFePO4 (ASCII : Q)" - elif (data == 0x53): - return "LiPO (ASCII: S)" - elif (data == 0x50): - return "LiPO (ASCII: P)" - else: - return "ERROR" - + time.sleep(0.1) + data = i2c.read_byte_data(0x6b, 0x07) + if (data == 0x46): + return "LiFePO4 (ASCII : F)" + elif (data == 0x51): + return "LiFePO4 (ASCII : Q)" + elif (data == 0x53): + return "LiPO (ASCII: S)" + elif (data == 0x50): + return "LiPO (ASCII: P)" + else: + return "ERROR" + def bat_runtime(): - time.sleep(0.1) - data = i2c.read_byte_data(0x6b, 0x01) + 1 - if (data == 0x100): - return "TIMER DISABLED" - elif (data == 0xff): - return "TIMER DISABLED" - else: - data = str(data)+ " MIN" - return data - + time.sleep(0.1) + data = i2c.read_byte_data(0x6b, 0x01) + 1 + if (data == 0x100): + return "TIMER DISABLED" + elif (data == 0xff): + return "TIMER DISABLED" + else: + data = str(data)+ " MIN" + return data + def bat_level(): - time.sleep(0.1) - data = i2c.read_word_data(0x69, 0x08) - data = format(data,"02x") - return (float(data) / 100) - + 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)"): - databatminus = datavolts-2.90 - datapercentage = ((databatminus/0.70))*100 - elif (databattery == "LiPO (ASCII: S)") or (databattery == "LiPO (ASCII: P)"): - databatminus = datavolts-3.4 - datapercentage = ((databatminus/0.899))*100 - return int (datapercentage) - - + time.sleep(0.1) + datavolts = bat_level() + databattery = bat_version() + if (databattery == "LiFePO4 (ASCII : F)") or (databattery == "LiFePO4 (ASCII : Q)"): + databatminus = datavolts-2.90 + datapercentage = ((databatminus/0.70))*100 + elif (databattery == "LiPO (ASCII: S)") or (databattery == "LiPO (ASCII: P)"): + databatminus = datavolts-3.4 + datapercentage = ((databatminus/0.899))*100 + return int (datapercentage) + def charger_state(): - time.sleep(0.1) - data = i2c.read_byte_data(0x69, 0x20) - battpercentage = bat_percentage() - powermode = pwr_mode() - databattery = bat_version() - if (databattery == "LiFePO4 (ASCII : F)") or (databattery == "LiFePO4 (ASCII : Q)"): - if (data == 0x00) and (powermode == "BAT POWERED"): - return "DISCHARGING" - if (data == 0x01) and (powermode == "RPi POWERED"): - return "CHARGING" - if (data == 0x00) and (powermode == "RPi POWERED"): - return "CHARGED" - if (databattery == "LiPO (ASCII: S)") or (databattery == "LiPO (ASCII: P)"): - if (data == 0x00) and (powermode == "BAT POWERED"): - return "DISCHARGING" - if (data == 0x00) and (powermode == "RPi POWERED"): - return "CHARGED" - if (data == 0x01) and (powermode == "RPi POWERED"): - return "CHARGING" + time.sleep(0.1) + data = i2c.read_byte_data(0x69, 0x20) + battpercentage = bat_percentage() + powermode = pwr_mode() + databattery = bat_version() + if (databattery == "LiFePO4 (ASCII : F)") or (databattery == "LiFePO4 (ASCII : Q)"): + if (data == 0x00) and (powermode == "BAT POWERED"): + return "DISCHARGING" + if (data == 0x01) and (powermode == "RPi POWERED"): + return "CHARGING" + if (data == 0x00) and (powermode == "RPi POWERED"): + return "CHARGED" + if (databattery == "LiPO (ASCII: S)") or (databattery == "LiPO (ASCII: P)"): + if (data == 0x00) and (powermode == "BAT POWERED"): + return "DISCHARGING" + if (data == 0x00) and (powermode == "RPi POWERED"): + return "CHARGED" + if (data == 0x01) and (powermode == "RPi POWERED"): + return "CHARGING" def rpi_level(): - time.sleep(0.1) - data = i2c.read_word_data(0x69, 0x0a) - data = format(data,"02x") - powermode = pwr_mode() - if (powermode == "RPi POWERED"): - return (float(data) / 100) - else: - return "0.0" + time.sleep(0.1) + data = i2c.read_word_data(0x69, 0x0a) + data = format(data,"02x") + powermode = pwr_mode() + if (powermode == "RPi POWERED"): + return (float(data) / 100) + else: + return "0.0" def rpi_cpu_temp(): - time.sleep(0.1) - data = os.popen('vcgencmd measure_temp').readline() - data = (data.replace("temp=","").replace("'C\n","")) - if (degrees == "C"): - return float(data) - elif (degrees == "F"): - return (float(data) * 9 / 5) + 32 - + time.sleep(0.1) + data = os.popen('vcgencmd measure_temp').readline() + data = (data.replace("temp=","").replace("'C\n","")) + if (degrees == "C"): + return float(data) + elif (degrees == "F"): + return (float(data) * 9 / 5) + 32 + def ntc1_temp(): - time.sleep(0.1) - data = i2c.read_byte_data(0x69, 0x1b) - data = format(data,"02x") - if (degrees == "C"): - return float(data) - elif (degrees == "F"): - return (float(data) * 9 / 5) + 32 - + time.sleep(0.1) + data = i2c.read_byte_data(0x69, 0x1b) + data = format(data,"02x") + if (degrees == "C"): + return float(data) + elif (degrees == "F"): + 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"): - return float(data) - elif (degrees == "F"): - return (float(data) * 9 / 5) + 32 + time.sleep(0.1) + data = i2c.read_byte_data(0x69, 0x1C) + data = format(data,"02x") + if (degrees == "C"): + return float(data) + elif (degrees == "F"): + 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) + 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) - + 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 == 2): - return "AUTOMATIC" - elif (data == 1): - return "ON" - elif (data == 0): - return "OFF" - else: - return "ERROR" + time.sleep(0.1) + data = i2c.read_byte_data(0x6b, 0x11) + data = data & ~(1 << 2) + if (data == 2): + return "AUTOMATIC" + elif (data == 1): + return "ON" + elif (data == 0): + return "OFF" + else: + return "ERROR" def fan_state(): - time.sleep(0.1) - data = i2c.read_byte_data(0x6b, 0x13) - data = data & ~(1 << 2) - if (data == 1): - return "ON" - elif (data == 0): - return "OFF" - else: - return "ERROR" + time.sleep(0.1) + data = i2c.read_byte_data(0x6b, 0x13) + data = data & ~(1 << 2) + if (data == 1): + return "ON" + elif (data == 0): + return "OFF" + else: + return "ERROR" def fan_speed(): - time.sleep(0.1) - data = i2c.read_byte_data(0x6b, 0x12) - data = format(data,"02x") - return int (float(data) * 100) + time.sleep(0.1) + data = i2c.read_byte_data(0x6b, 0x12) + data = format(data,"02x") + return int (float(data) * 100) def fan_threshold(): - time.sleep(0.1) - data = i2c.read_byte_data(0x6B, 0x14) - data = format(data,"02x") - if (degrees == "C"): - return data - elif (degrees == "F"): - return (float(data) * 9 / 5) + 32 - + time.sleep(0.1) + data = i2c.read_byte_data(0x6B, 0x14) + data = format(data,"02x") + if (degrees == "C"): + return data + elif (degrees == "F"): + return (float(data) * 9 / 5) + 32 + def rs232_state(): - time.sleep(0.1) - data = i2c.read_byte_data(0x6b, 0x02) - if (data == 0x00): - return "OFF" - elif (data == 0xff): - return "OFF" - elif (data == 0x01): - return "ON @ 4800 pbs" - elif (data == 0x02): - return "ON @ 9600 pbs" - elif (data == 0x03): - return "ON @ 19200 pbs" - elif (data == 0x04): - return "ON @ 34600 pbs" - elif (data == 0x05): - return "ON @ 57600 pbs" - elif (data == 0x0f): - return "ON @ 115200 pbs" - else: - return "ERROR" - + time.sleep(0.1) + data = i2c.read_byte_data(0x6b, 0x02) + if (data == 0x00): + return "OFF" + elif (data == 0xff): + return "OFF" + elif (data == 0x01): + return "ON @ 4800 pbs" + elif (data == 0x02): + return "ON @ 9600 pbs" + elif (data == 0x03): + return "ON @ 19200 pbs" + elif (data == 0x04): + return "ON @ 34600 pbs" + elif (data == 0x05): + return "ON @ 57600 pbs" + elif (data == 0x0f): + return "ON @ 115200 pbs" + else: + return "ERROR" + print " " print "**********************************************" -print "* UPS PIco HV3.0A Status *" -print "* Version 6.0-mbt *" +print "* UPS PIco HV3.0A Status *" +print "* Version 6.0-mbt *" print "**********************************************" print " " print " ","- PIco Firmware..........:",fw_version() @@ -274,56 +273,56 @@ def rs232_state(): print " ","- RPi Voltage............:",rpi_level(),"V" print " " -if (degrees == "C"): - print " ","- RPi CPU Temperature....:",rpi_cpu_temp(),"C" - print " ","- NTC1 Temperature.......:",ntc1_temp(),"C" +if (degrees == "C"): + print " ","- RPi CPU Temperature....:",rpi_cpu_temp(),"C" + print " ","- NTC1 Temperature.......:",ntc1_temp(),"C" elif (degrees == "F"): - print " ","- RPi CPU Temperature....:",rpi_cpu_temp(),"F" - print " ","- NTC1 Temperature.......:",ntc1_temp(),"F" + print " ","- RPi CPU Temperature....:",rpi_cpu_temp(),"F" + print " ","- NTC1 Temperature.......:",ntc1_temp(),"F" else: - print " ","- RPi CPU Temperature....: please set temperature symbol in the script!" - print " ","- NTC1 Temperature.......: please set temperature symbol in the script!" + print " ","- RPi CPU Temperature....: please set temperature symbol in the script!" + print " ","- NTC1 Temperature.......: please set temperature symbol in the script!" if (to92 == True): - if (degrees == "C"): - print " ","- TO-92 Temperature......:",to92_temp(),"C" - elif (degrees == "F"): - print " ","- TO-92 Temperature......:",to92_temp(),"F" - else: - print " ","- TO-92 Temperature......: please set temperature symbol in the script!" - -if (extpwr == True): - print " ","- Extended Voltage.......:",epr_read(),"V" - print " ","- A/D2 Voltage...........:",ad2_read(),"V" - -if (fankit == True): - print " " + if (degrees == "C"): + print " ","- TO-92 Temperature......:",to92_temp(),"C" + elif (degrees == "F"): + print " ","- TO-92 Temperature......:",to92_temp(),"F" + else: + print " ","- TO-92 Temperature......: please set temperature symbol in the script!" + +if (extpwr == True): + print " ","- Extended Voltage.......:",epr_read(),"V" + print " ","- A/D2 Voltage...........:",ad2_read(),"V" + +if (fankit == True): + print " " if (fan_mode() == "AUTOMATIC"): - print " ","- PIco FAN Mode..........:",fan_mode() - print " ","- PIco FAN State.........:",fan_state() - if (fan_state() == "ON"): - print " ","- PIco FAN Speed.........:",fan_speed(),"RPM" - else: - print " ","- PIco FAN Speed.........: 0 RPM" - if (degrees == "C"): - print " ","- PIco FAN Temp Threshold:",fan_threshold(),"C" - elif (degrees == "F"): - print " ","- PIco FAN Temp Threshold:",fan_threshold(),"F" - else: - print " ","- PIco FAN Temp Threshold: please set temperature symbol in the script!" + print " ","- PIco FAN Mode..........:",fan_mode() + print " ","- PIco FAN State.........:",fan_state() + if (fan_state() == "ON"): + print " ","- PIco FAN Speed.........:",fan_speed(),"RPM" + else: + print " ","- PIco FAN Speed.........: 0 RPM" + if (degrees == "C"): + print " ","- PIco FAN Temp Threshold:",fan_threshold(),"C" + elif (degrees == "F"): + print " ","- PIco FAN Temp Threshold:",fan_threshold(),"F" + else: + print " ","- PIco FAN Temp Threshold: please set temperature symbol in the script!" else: - print " ","- PIco FAN Mode..........:",fan_mode() - if (fan_mode() == "ON"): - print " ","- PIco FAN Speed.........:",fan_speed(),"RPM" - else: - print " ","- PIco FAN Speed.........: 0 RPM" - - if (degrees == "C"): - print " ","- PIco FAN Temp Threshold:",fan_threshold(),"C" - elif (degrees == "F"): - print " ","- PIco FAN Temp Threshold:",fan_threshold(),"F" - else: - print " ","- PIco FAN Temp Threshold: please set temperature symbol in the script!" + print " ","- PIco FAN Mode..........:",fan_mode() + if (fan_mode() == "ON"): + print " ","- PIco FAN Speed.........:",fan_speed(),"RPM" + else: + print " ","- PIco FAN Speed.........: 0 RPM" + + if (degrees == "C"): + print " ","- PIco FAN Temp Threshold:",fan_threshold(),"C" + elif (degrees == "F"): + print " ","- PIco FAN Temp Threshold:",fan_threshold(),"F" + else: + print " ","- PIco FAN Temp Threshold: please set temperature symbol in the script!" print " " print "**********************************************" print "* Powered by PiModules *" From 02cd56641263f6f326c583f64e1895e65e597d05 Mon Sep 17 00:00:00 2001 From: Martin Boissonneault Date: Sat, 2 Feb 2019 19:39:54 -0500 Subject: [PATCH 8/9] Reindent, change temp thresholds, change log location --- temp_fan/pico_temp_fan-mbt.py | 42 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/temp_fan/pico_temp_fan-mbt.py b/temp_fan/pico_temp_fan-mbt.py index f08b7cc..dbd2b8b 100644 --- a/temp_fan/pico_temp_fan-mbt.py +++ b/temp_fan/pico_temp_fan-mbt.py @@ -5,7 +5,7 @@ import smbus from time import sleep -logging.basicConfig(filename='/home/pi/PiModules/temp_fan/error.log',level=logging.INFO) +logging.basicConfig(filename='/home/ve2mrx/fan_error.log',level=logging.INFO) # Set your desired temperature symbol # C = Celsius @@ -22,24 +22,22 @@ def to92_temp(): return float(data) elif (degrees == "F"): return (float(data) * 9 / 5) + 32 - + def rpi_cpu_temp(): - time.sleep(0.1) - data = os.popen('vcgencmd measure_temp').readline() - data = (data.replace("temp=","").replace("'C\n","")) - if (degrees == "C"): - return float(data) - elif (degrees == "F"): - return (float(data) * 9 / 5) + 32 - + data = os.popen('vcgencmd measure_temp').readline() + data = (data.replace("temp=","").replace("'C\n","")) + if (degrees == "C"): + return float(data) + elif (degrees == "F"): + return (float(data) * 9 / 5) + 32 + def ntc1_temp(): - time.sleep(0.1) - data = i2c.read_byte_data(0x69, 0x1b) - data = format(data,"02x") - if (degrees == "C"): - return float(data) - elif (degrees == "F"): - return (float(data) * 9 / 5) + 32 + data = i2c.read_byte_data(0x69, 0x1b) + data = format(data,"02x") + if (degrees == "C"): + return float(data) + elif (degrees == "F"): + return (float(data) * 9 / 5) + 32 # function to set the fan speed def set_fan_speed(speed): @@ -53,8 +51,8 @@ def set_fan_speed(speed): while True: try: logging.info("checking temp") - temp = rpi_cpu_temp() - #temp = to92_temp() + temp = rpi_cpu_temp() + # temp = to92_temp() logging.info("current temperature: %s",temp) if temp != prev_temp: # check if temp has changed, no need to make unnecessary i2c calls prev_temp = temp # update prev_temp variable to current temp to compare next time @@ -65,11 +63,11 @@ def set_fan_speed(speed): set_fan_speed(0) if temp > 30: set_fan_speed(25) - if temp > 60: + if temp > 40: set_fan_speed(50) - if temp > 70: + if temp > 50: set_fan_speed(75) - if temp > 80: + if temp > 60: set_fan_speed(100) except: logging.exception("Exception message:") From 48cea025200b3468710409b2469cc5004078e38f Mon Sep 17 00:00:00 2001 From: Martin Boissonneault Date: Mon, 4 Feb 2019 15:35:35 -0500 Subject: [PATCH 9/9] Fix whitespace --- pico_status/pico_status-mbt.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pico_status/pico_status-mbt.py b/pico_status/pico_status-mbt.py index dfbbb63..431c908 100644 --- a/pico_status/pico_status-mbt.py +++ b/pico_status/pico_status-mbt.py @@ -298,12 +298,13 @@ def rs232_state(): if (fankit == True): print " " if (fan_mode() == "AUTOMATIC"): - print " ","- PIco FAN Mode..........:",fan_mode() - print " ","- PIco FAN State.........:",fan_state() - if (fan_state() == "ON"): - print " ","- PIco FAN Speed.........:",fan_speed(),"RPM" - else: - print " ","- PIco FAN Speed.........: 0 RPM" + print " ","- PIco FAN Mode..........:",fan_mode()," (0x6b,0x11)" + print " ","- PIco FAN State.........:",fan_state()," (0x6b,0x13)" + #if (fan_state() == "ON"): + # + print " ","- PIco FAN Speed.........:",fan_speed(),"RPM" + #else: + # print " ","- PIco FAN Speed.........: 0 RPM" if (degrees == "C"): print " ","- PIco FAN Temp Threshold:",fan_threshold(),"C" elif (degrees == "F"):