Skip to content

Commit

Permalink
Added info about GPIO4 and 1-Wire
Browse files Browse the repository at this point in the history
  • Loading branch information
tjohn327 committed Jun 9, 2020
1 parent 7104938 commit efa0984
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ Note:

### 1. Connect Power Pi to Raspberry pi

* Make sure the switch of Power Pi is turned off and power input is plugged into the Raspberry Pi.
* Make sure the switch of the Power Pi is turned off and no power input is connected to the Power Pi.

* Insert the battery into the battery holder following the correct polarity.
* Insert the battery into the battery holder of the Power Pi following the correct polarity.

* Connect Power Pi to Raspberry Pi by inserting it into the GPIO pins.

* Connect power to the Raspberry Pi's USB input to turn it on. (After the setup this power will be connected to Power Pi)
* Connect a USB power cable into the Raspberry Pi's USB input as usual to turn the Pi on. (This is to set up Power Pi. After the setup, power cable should be connected to Power Pi's input.)

### 2. Set up Raspberry Pi for use with Power Pi

Expand Down Expand Up @@ -102,6 +102,8 @@ git checkout R3_1

Edit the file powerpi.py between lines 16 and 24 if you are not using Samsung INR18650-29E battery. It is recommended to keep the VBAT_LOW at 3.2V for Li-Ion batteries.

*Power PI uses GPIO4 for interrupts from the Power Management IC. 1-Wire interface uses the same pin. If you are not using 1-Wire interface, disable it before proceeding. Power Pi can still function fully without the interrupt. So if you want to use 1-Wire interface it is advised to remove the resistor R12 from Power Pi, otherwise it will cause interference with 1-Wire interface.*

Run the install.sh script to install a service for the ups.

```shell
Expand Down
14 changes: 10 additions & 4 deletions src/ups.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

logging.basicConfig(level=logging.INFO)

USE_1WIRE = False
ENABLE_UDP = True
UDP_PORT = 40001
serverAddressPort = ("127.0.0.1", UDP_PORT)
Expand Down Expand Up @@ -56,10 +57,15 @@ def main():
if ppi.initialize():
sys.exit(1)

GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(4, GPIO.FALLING, callback=interrupt_handler, bouncetime=200)

if not USE_1WIRE:
try:
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(4, GPIO.FALLING, callback=interrupt_handler, bouncetime=200)
except Exception as ex:
logging.error("Error attaching interrupt to GPIO4")
logging.error(ex)

while (True):
read_status()

Expand Down

0 comments on commit efa0984

Please sign in to comment.