diff --git a/Instructions for UPS-Lite V1.2.pdf b/Instructions for UPS-Lite V1.2.pdf new file mode 100644 index 0000000..11eb9c4 Binary files /dev/null and b/Instructions for UPS-Lite V1.2.pdf differ diff --git a/MAX17040.pdf b/MAX17040.pdf deleted file mode 100644 index ce0fa9e..0000000 Binary files a/MAX17040.pdf and /dev/null differ diff --git a/README.md b/README.md deleted file mode 100644 index 6acc58a..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# UPS-Lite \ No newline at end of file diff --git "a/UPS-Lite V1.2 \344\275\277\347\224\250\350\257\264\346\230\216.pdf" "b/UPS-Lite V1.2 \344\275\277\347\224\250\350\257\264\346\230\216.pdf" new file mode 100644 index 0000000..1e4d419 Binary files /dev/null and "b/UPS-Lite V1.2 \344\275\277\347\224\250\350\257\264\346\230\216.pdf" differ diff --git "a/UPS-Lite\344\275\277\347\224\250\350\257\264\346\230\216.pdf" "b/UPS-Lite\344\275\277\347\224\250\350\257\264\346\230\216.pdf" deleted file mode 100644 index 7dd28ce..0000000 Binary files "a/UPS-Lite\344\275\277\347\224\250\350\257\264\346\230\216.pdf" and /dev/null differ diff --git a/UPS_Lite.py b/UPS_Lite_org.py similarity index 56% rename from UPS_Lite.py rename to UPS_Lite_org.py index fe536ec..ee31668 100644 --- a/UPS_Lite.py +++ b/UPS_Lite_org.py @@ -1,16 +1,17 @@ - #!/usr/bin/env python import struct import smbus import sys import time +import RPi.GPIO as GPIO + def readVoltage(bus): "This function returns as float the voltage from the Raspi UPS Hat via the provided SMBus object" address = 0x36 - read = bus.read_word_data(address, 2) + read = bus.read_word_data(address, 0X02) swapped = struct.unpack("H", read))[0] voltage = swapped * 1.25 /1000/16 return voltage @@ -19,27 +20,66 @@ def readVoltage(bus): def readCapacity(bus): "This function returns as a float the remaining capacity of the battery connected to the Raspi UPS Hat via the provided SMBus object" address = 0x36 - read = bus.read_word_data(address, 4) + read = bus.read_word_data(address, 0X04) swapped = struct.unpack("H", read))[0] capacity = swapped/256 return capacity +def QuickStart(bus): + address = 0x36 + bus.write_word_data(address, 0x06,0x4000) + + +def PowerOnReset(bus): + address = 0x36 + bus.write_word_data(address, 0xfe,0x0054) + + + + +GPIO.setmode(GPIO.BCM) +GPIO.setwarnings(False) +GPIO.setup(4,GPIO.IN) + bus = smbus.SMBus(1) # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1) +PowerOnReset(bus) +QuickStart(bus) + + +print " " +print "Initialize the MAX17040 ......" + + while True: print "++++++++++++++++++++" print "Voltage:%5.2fV" % readVoltage(bus) print "Battery:%5i%%" % readCapacity(bus) - + + if readCapacity(bus) == 100: print "Battery FULL" - if readCapacity(bus) < 20: + if readCapacity(bus) < 5: print "Battery LOW" + + + + + + if (GPIO.input(4) == GPIO.HIGH): + + print "Power Adapter Plug In " + + if (GPIO.input(4) == GPIO.LOW): + + print "Power Adapter Unplug" + + print "++++++++++++++++++++" time.sleep(2)