Giter Club home page Giter Club logo

raspberry_pi_ups's Introduction

UPS for Raspberry Pi

UPS Image

Description

An uninterruptible power supply for Raspberry Pi that can provide more than an hour of backup power and can shutdown the Pi safely. This UPS can be used to power any 5V device with up to 3A continuous current. It is based on Texas Instruments BQ25895 power management IC and TPS61236P boost converter IC.

This UPS can power a Raspberry Pi through the GPIO header by using it as a hat. When used as a hat, the GPIO pins 2, 3 and 4 will be utilized for I2C and interrupt signals.

Note:

  • Do not connect two input sources together!

  • The device does not have reverse polarity protection, be sure to observe the polarity marked in the battery holder while inserting the battery.

  • UPS script was tested on a Raspberry Pi 3B+ running Raspbian Buster.

Specifications

  • Input: 4.5V - 14V DC, 2A - 5A

  • Input Ports: Screw Terminal, micro USB

  • Output: 5V, up to 3A

  • Output Ports: Screw Terminal, USB A, 40 pin GPIO header for Raspberry Pi

  • Battery: Not included (Samsung INR18650-29E recommended, other 18650 size li-Ion batteries can be used)

  • Communication: I2C

Status LEDs

  • IN: Input connected or not

  • STATUS: ON- Charging, OFF- Charging done, Blinking- Error

  • OUT: Output on or off

Setting up Power Pi for use with a Raspberry Pi

1. Connect Power Pi to 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 of the Power Pi following the correct polarity.

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

  • 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 can be connected to Power Pi's input.)

Setup

2. Set up Raspberry Pi to communicate with Power Pi

Enable I2C and install smbus

Update the system (optional):

sudo apt update && sudo apt upgrade -y

Enable I2C:

sudo raspi-config

Choose Interfacing Options, then I2C and then select enable to enable I2C in the Raspberry Pi.

Install smbus by running the following command:

sudo apt-get install -y python-smbus

For more information, checkout the link

3. Install the ups service

Clone the Power Pi repository:

cd ~
git clone https://github.com/tjohn327/raspberry_pi_ups.git
cd raspberry_pi_ups/src/

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.

chmod +x install.sh
./install.sh

This creates a service named ups.service that will run on startup. If there are no errors, you will see this as the output:

Checking Python
Python found
Initializing Power Pi
INFO:root:UPS initialized
Creating ups service
Enabling ups service to run on startup
ups service enabled
Power Pi configured successfully

Don't panic - since the Power is not connected to Power Pi this message will appear.

Broadcast message from user@raspberry (somewhere) (Sat Aug 15 18:40:10 2020):

Power Disconnected, system will shutdown in 72 minutes!

Now turn off the Raspberry Pi and remove the power cable form it. Connect the power cable to Power Pi and turn the switch to ON position. This will power up the Raspberry Pi through Power Pi.

PowerPi

When the Pi is powered back up, check the status of the ups service by running:

sudo systemctl status ups.service

If everything is running correctly, you will see a status similar to this:

● ups.service - UPS Service
   Loaded: loaded (/lib/systemd/system/ups.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2020-06-09 06:44:15 UTC; 34s ago
 Main PID: 542 (python)
    Tasks: 2 (limit: 2200)
   Memory: 6.9M
   CGroup: /system.slice/ups.service
           └─542 /usr/bin/python /home/pi/code/raspberry_pi_ups/src/ups.py

Jun 09 06:44:15 raspberrypi systemd[1]: Started UPS Service.
Jun 09 06:44:17 raspberrypi python[542]: INFO:root:UPS initialized

Your Power Pi is now ready.

The ups service will now run on startup and send the status of the UPS to UDP Port 40001 every 2 seconds. You can see the status of the UPS by listening to that port.

To test if the UPS status is being read correctly, run the following command:

nc -lvu  40001

4. Setup Node-Red dashboard for visualization (optional)

Dashboard

If you are new to Node-Red, please checkout their Essentials video series.

Follow the instructions given in the link and install Node-Red on the Raspberry Pi.

It may take a while to install. After the installation is done, copy the ups_flow.json file to Node-Red's directory.

cp ups_flow.json ~/.node-red/lib/flows/ups_flow.json

Install the Dashboard extension for Node-Red.

cd ~/.node-red/
npm i node-red-dashboard

Enable Node-Red to run on startup and start the Node-Red service:

sudo systemctl enable nodered.service
sudo systemctl start nodered.service

Open the Node-Red link in a browser. The link is usually:

http://[IP of Raspberry Pi]:1880/

Import the ups flow into the Node-Red environment.

Import

Edit one of the UI nodes (e.g BAT) by double clicking on it. In its setup menu click on the edit button next to "Group' and select 'Home' in the Tab drop down. Click Update and then Done.

Deploy the flow by clicking the Deploy button and open the dashboard link of Node-Red to see the status of the UPS.

http://[IP of Raspberry Pi]:1880/ui

More info about importing flows and setting up dashboards.

Using Power Pi with Raspberry Pi

When powering the Raspberry Pi through Power Pi, always connect the power cable to the input of the Power Pi. Use the switch of Power Pi to turn the devices ON and OFF.

raspberry_pi_ups's People

Contributors

andylittle avatar doliana avatar tjohn327 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

raspberry_pi_ups's Issues

integrate into other monitoring systems

I would like to monitor the Power Pi via OpenHab instead of node red. Could you provide some guidance on how monitoring of the Power Pi can be achieved so that it can be integrated into other systems like OpenHab?

On\Off oscillation on low battery

hi
first of all - great job!

I was replicating the schematic and it working properly,
other than when the battery is low - then the system starts to oscillate.

I didn't change anything in the settings other than the battery capacity (2600ma).

I'm not using GPIO4 - maybe it's related?

thank you,
Coby.

[question] Why VSYS with boost converter and not PMID

What was VSYS with a boost converter chosen over using the PMID output of the BQ25895? I haven't played with the chip yet and I'm trying to figure out why this might be the case. The only reason I can come up with is that block diagram for the chip makes it look like PMID is only powered when there is power on VBUS. Where as VSYS can get power from VBUS or VBAT. However, there is contradicting verbiage (to the block diagram) in the datasheet that indicates that PMID can be power from VBAT.

"8.2.5 Boost Mode Operation from Battery
The device supports boost converter operation to deliver power from the battery to other portable devices
through PMID pin."

I realize that this is probably a better question for Ti but I learned of this chip through this design so I thought the designers of the board might have some insight. It appears that this design was lifted from the PMP4451 eval board which doesn't use the PMID pin of the BQ25895 as well.

Thanks in advance,

Jacob

Not charging

Hi I received the PowerPi, all configured, as per instructions and it runs the Pi when the power is disconnected, however it isn't charging the battery.

Running nc -lvu 40001

Listening on [0.0.0.0] (family 2, port 40001)
Connection from localhost 46547 received!
{
"BatteryPercentage": 30,
"BatteryVoltage": 3.504,
"ChargeCurrent": 0,
"ChargeStatus": "Not Charging",
"InputVoltage": 2.6,
"PowerInputStatus": "Not Connected",
"TimeRemaining": 26
}

Thanks in advance.

Error : systemctl status

sudo systemctl status ups.service
● ups.service - UPS Service
Loaded: loaded (/lib/systemd/system/ups.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-09-03 13:43:59 EEST; 43s ago
Main PID: 800 (python)
Tasks: 2 (limit: 2200)
Memory: 3.1M
CGroup: /system.slice/ups.service
└─800 /usr/bin/python /home/pi/raspberry_pi_ups/src/ups.py

Σεπ 03 13:44:23 homecontrol python[800]: ERROR:root:a bytes-like object is required, not 'str'

So nothing happened at port 40001.
Bastiaan

[question] Will there be another production run?

Hi. I sadly missed the first production run of the Power Pi. Will there be another one? I don't have much hardware experience, is it possible/not-that-hard to build it myself with the help of some PCB service that would print less than 5 PCBs?

Device and service failed to run

Hi,
I'm trying to setup the powerpi on a Banana PI PRO and, aside that the board is not supported, I'm facing 2 issues:

  • Powering the Banana from the PowerPi doesn't work, I've checked the power requirements and the Banana is in the range 5 V @ 2 A

  • The installation went ok, the Banana see the PowerPi and give the "Power Pi configured successfully" message, but the service fail to start. Checking the service status I've this error:

ups.service - UPS Service
Loaded: loaded (/lib/systemd/system/ups.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2020-08-12 19:43:42 UTC; 16s ago
Process: 1660 ExecStart=/usr/bin/python /home/banano/raspberry_pi_ups/src/ups.py (code=exited, status=1/FAILURE)
Main PID: 1660 (code=exited, status=1/FAILURE)
Aug 12 19:43:41 bananapipro systemd[1]: ups.service: Unit entered failed state.
Aug 12 19:43:41 bananapipro systemd[1]: ups.service: Failed with result 'exit-code'.
Aug 12 19:43:42 bananapipro systemd[1]: ups.service: Service hold-off time over, scheduling restart.
Aug 12 19:43:42 bananapipro systemd[1]: Stopped UPS Service.
Aug 12 19:43:42 bananapipro systemd[1]: ups.service: Start request repeated too quickly.
Aug 12 19:43:42 bananapipro systemd[1]: Failed to start UPS Service.
Aug 12 19:43:42 bananapipro systemd[1]: ups.service: Unit entered failed state.
Aug 12 19:43:42 bananapipro systemd[1]: ups.service: Failed with result 'exit-code'.

Anyhow the shipping was perfect and I've received the board without any problems.
Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.