Power Management HAT

From Waveshare Wiki
Jump to: navigation, search
Power Management HAT
Power Management HAT
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

Introduction

The Power Management HAT is a smart power bank designed for Raspberry Pi. With the embedded Arduino MCU and RTC, the HAT features auto power management function which allows the Pi to work more power-efficient and safely.

Features

  • Standard Raspberry Pi 40PIN GPIO extension header, supports Raspberry Pi series boards.
  • Onboard ATmega328P MCU, supports Arduino programming.
  • Onboard PCF8523 RTC chip, provides precise RTC information.
  • Onboard CP2102 UART converter, for UART communication or ATmega328P programming.
  • User-defined button, can be used for Raspberry Pi start-up, safe shutdown, or other customized functions.
  • Protection circuits such as power supply anti-reverse, counter-current proof, etc. ensure stable and safe operating.
  • Voltage/current monitoring circuit, monitors the Raspberry Pi operating voltage and current in real-time.
  • Comes with online development resources and manuals.

Specification

  • Communication interface: UART, GPIO (custom protocol)
  • Controller: ATmega328P-AU
  • Communication interface: UART + GPIO
  • Baud rate: default 115200bps (other baud rates can be programmed)
  • Power supply mode: USB interface or PH2.0 interface
  • USB power input: 5V
  • PH2.0 power input: DC 7~28V (regulated power supply or lithium battery)
  • Built-in circuit: power supply anti-reverse connection, counter-current proof, current detection, voltage detection
  • Dimensions: 56.5mm x 65mm
  • Mounting hole size: 3.0mm

Working principle

The ATmega328O connect to Raspberry Pi by 2 GPIO. These pins are defined by firmware.

Raspberry Pi side Arduino (ATmega328P) side
GPIO of Pi GPIO of Arduino Functions Description
GPIO20 PC3 Input: Raspberry Pi shutdown if the pin is High detected. You should set it to Low when working Output: If it is set to High, Raspberry Pi will shutdown. You should set it to Low when Raspberry Pi is on.
GPIO21 PD7 Output: If this Pin is high, it means that Raspberry Pi is working. It turns to Low if Raspberry Pi is shutdown. Input: If Raspberry Pi is working, it will be detected as High, and it will be detected to Low if Raspberry Pi is shutdown.
Raspberry Pi side
  • Power on: GPIO21 is set to High after powering on
  • Power off: Keep detecting the status of GPIO20, if it is high, Raspberry Pi shutdown and set GPIO21 to Low after shutdown.
Arduino (ATmega328P) side
  • Power on: Set PC3 to Low and power on Raspberry Pi. If PD7 is detected as High, it means that Raspberry Pi boots successfully.
  • Power off: Set PC3 to High, Raspberry Pi shutdown after detecting it. Keep detecting the status of PD7, if PD7 is Low, it means that Raspberry Pi has shut down and it can cut off the power of Raspberry Pi.

SAFETY CAUTIONS

  • Li-ion and Li-po batteries are quite unstable. They may cause fire, personal injury, or property damage, if they're not properly recharged or used.
  • Do not reversely connect the polarities when recharging or discharging the battery. Do not use inferior charger/charging panel to recharge the battery.
  • Do not mix use old batteries with new ones, avoid using batteries of different brands.
  • When buying Lithium battery, should always make sure the battery specification is compatible with the expansion board. Choose batteries from formal manufacturer, and ensure the batteries will work stably and safely by aging test.
  • Lithium batteries have limited cycle life, they will also deteriorate as time goes by. Should be replaced with new ones when the batteries reaching their max cycle life, or working over two years, whichever comes first.
  • Should be placed carefully and properly, keep it away from inflammables and explosives articles, away from children, avoid any safety accident caused by careless storage.

Preparation

The Software is divided into two parts. You need to first configure the Raspberry Pi. Then download the control codes (firmware) to the Power Management HAT by Arduino IDE. The different examples feature different function.

Software setup (Pi)

Shutdown Protocol Configuration

Open the terminal of Raspberry Pi and set the system-shutdown script.

  • Download the shell script
wget https://files.waveshare.com/upload/4/44/Power-Management-HAT.zip
unzip Power-Management-HAT.zip
cd Power-Management-HAT
  • Set the permission of the script.
sudo chmod a+x Power-Management-HAT-Setup.sh

Power-Management-HAT-manual-2.png

  • Run the script.
sudo ./Power-Management-HAT-Setup.sh

The result is shown below, when prompted "Would you like to reboot now? y/n", enter "y" to reboot the Raspberry Pi (you must reboot the Raspberry Pi for the operation to be effective if the Raspberry Pi is not rebooted, you must manually reboot the Raspberry Pi before it takes effect).
Power-Management-HAT-manual-3.png
Note: Attention must be paid to check whether there is an error reported after the execution of the above operation, there is an error reported according to the prompts to correct before continuing.

Software setup (PC)

  • Install Arduino IDE: Please install Arduino IDE to your Windows PC and remember the installation path.
  • Install Power Management HAT package.
The package can be downloaded from the Gihub download address, or you can also download it from the UTSOURCE website.

After downloading, copy the downloaded Power Management HAT folder (which also contains a subfolder Power Management HAT) to the hardware folder under the Arduino installation path. Copy it to the hardware folder under the Arduino installation path, as shown in the figure below, and then you can use the Arduino IDE to develop Power Management HAT.

Power-Management-HAT-manual-4.png

  • Setup Arduino IDE
Restart Arduino IDE.
Connect the USB interface of Power Management HAT to PC.
Select the correct port.
Power-Management-HAT-manual-5.png
Select Power Management HAT device.
Power-Management-HAT-manual-6.png
Finally, examples (firmware) can be found from File -> Examples -> PowerManagementHAT.
Power-Management-HAT-manual-7.png

Power Supply Preparation

  • Plug Power Management HAT into the Raspberry Pi pins.
  • The Power Management HAT will supply power to the Raspberry Pi and the Raspberry Pi will not need to be powered again.
  • The Power Management HAT is powered by one of the following methods, and if both are powered, USB power is automatically selected.
  • Power Management HAT is powered by USB.
  • The Power Management HAT is powered by the matching Li-ion battery pack or by an optional DC power supply (optional DC power supply voltage range is 7V-28V).

Examples

Several examples are provided, you need to download them to the Power Management HAT to feature the differnt contorl function.

ButtonBoot

How to set up
  • Connect the USB port of the PM HAT to the computer.
  • Open Arduino IDE software (PM HAT environment should be configured before).
  • Open the ButtonBoot demo, compile, and download it.
  • Turn DEBUG switch to the other end.
  • Configurable parameters are shown below:
Parameters Description Default value
SHUTDOWN_TIME_MS The software shutdown threshold: If you long press the PWR button for [threshold] ms, the Pi shutdown 2000
CUT_POWER_TIME_MS The cut-off threshold: if you long-press the PWR button for [threshold] ms, the power of Pi is cut-off 8000
CURRENT_CHECK Disbale/Enable the current checking, if you enable it, the board will detect the working status of Pi by the current. false
CURRENTTHRESHOLD_MA If the working current of Raspberry Pi is less than this threshold value, Raspberry Pi is determined as shutdown. Default disabled 350
Firmware function
  • If the Raspberry Pi is powered off:
    • Press the power button and the Raspberry Pi will power on.
  • If the Raspberry Pi is powered on:
    • Press and hold the power button for more than 2 seconds, but for less than 8 seconds, the Raspberry Pi will be software shut down first, and the software shutdown will cut off the Raspberry Pi's power.
    • Press and hold the power button for more than 8 seconds, the Raspberry Pi will be powered off directly.

MeasureCurrent

How to set up
  • Connect the USB port of the PM HAT to the computer.
  • Open Arduino IDE software (PM HAT environment should be configured before).
  • Open the MeasureCurrent demo, compile, and download it.
  • Turn DEBUG switch to the other end.
  • Configurable parameters are shown below:
Parameters Description Default value
SHUTDOWN_TIME_MS The threshold of (press time) software shutdown 2000
CUT_POWER_TIME_MS The threshold of (press time) power cut off 8000
Firmware function
  • If the Raspberry Pi is turned off: Press the power button and the Raspberry Pi will power on.
  • If the Raspberry Pi has been powered on:
    • Press and hold the power button for more than 2 seconds, but for less than 8 seconds, the Raspberry Pi will first software shutdown, software shutdown will cut off the Raspberry Pi's power.
    • Press and hold the power button for more than 8 seconds, and the Raspberry Pi will directly cut off the Raspberry Pi power.
  • Open the serial terminal, and you can view the Raspberry Pi power on and off state of the operating current.
    • If you plug the jumper cap into A, open the serial monitor of the IDE to check the current situation.
    • If you plug the jumper cap into B, use the minicom plug-in on the Raspberry Pi to check the current situation.

MeasureVoltage_ShutdownInLowVoltage

How to set up
  • Connect the USB port of the PM HAT to the computer.
  • Open Arduino IDE software (PM HAT environment should be configured before).
  • Open the MeasureVoltage_ShutdownInLowVoltage demo, compile, and download it.
  • Turn DEBUG switch to the other end.
  • Configurable parameters are shown below:
Parameters Description Default value
SHUTDOWN_TIME_MS The threshold of (press time) software shutdown 2000
CUT_POWER_TIME_MS The threshold of (press time) power cut off 8000
ON_VOLTAGE_VOLT The min voltage to start Raspberry Pi 6.6
OFF_VOLTAGE_VOLT The threshold of Low-voltage shutdown 6.3
FORCE_OFF_VOLAGE_VOLT threshold of emergency shutdown 5.8
LOW_VOLTAGE_TIME_MS Waiting time of low-voltage shutdown 30000
OVERRIDE_TIME_MS The delay time of low-voltage continuation 3600000

【Note】:

When the voltage of batteries is less than the OFF_VOLTAGE, if you press the Power button in 30000ms (LOW_Voltage_TIME_IN_MS), Raspberry can keep working for 3600000ms (OVERRIDE_TIME_MS). During this time, once the voltage is less than 5.8V (FORCE_OFF_VOLTAGE_VOLT), Management HAT will cut off Raspberry Pi immediately; Once the voltage reaches On_VOLTAGE, the Raspberry Pi will be powered again.
The voltage of a single lithium battery is around 3.0V~4.2V, the battery power can be roughly estimated by the lithium battery voltage, 4.2V lithium battery means it is full, and 3.0V lithium battery means the power is very low, the lithium battery works at 3.7V most of the time; if the voltage of a single lithium battery is lower than 3.0V, the lithium battery may be permanently destroyed. If the Power Management HAT is powered by an external lithium battery, at least two lithium batteries (packs) need to be connected in series to provide a power supply of 5V or more, at this time, please set the corresponding voltage data according to the specific number of batteries in series, which can be referred to the data provided in the table below (if the Power Management HAT is powered by a matching Li-ion battery pack is used to power the Power Management HAT, then please select the parameters of 2S):
1S (DO NOT Support) 2S (1S*2) 3S(1S*3) 4S(1S*4)
ON_VOLTAGE_VOLT 3.3 6.6 9.9 13.2
OFF_VOLTAGE_VOLT 3.15 6.3 9.45 12.6
FORCE_OFF_VOLTAGE_VOLT 2.0 5.8 8.7 11.6
Firmware Function
  • If the Raspberry Pi is powered off:
    • Press the power button, and the Raspberry Pi will power on.
  • If the Raspberry Pi has been powered on:
    • Press and hold the power button for more than 2 seconds, but for less than 8 seconds, the Raspberry Pi will be software shut down first, and the Raspberry Pi will be powered off after the software shutdown.
    • Press and hold the power button for more than 8 seconds, and the Raspberry Pi will be powered off directly.
  • If the voltage is lower than the set threshold, it will shut down automatically.

PowerOnInAPeriodTime

How to set up
  • Connect the USB port of the PM HAT to the computer.
  • Open Arduino IDE software (PM HAT environment should be configured before).
  • Open the PowerOnInAPeriodTime demo, compile, and download it.
  • Turn DEBUG switch to the other end.
  • Configurable parameters are shown below:
Parameters Description Default value
WAKE_UP_START_HOUR Start time-hour 8
WAKE_UP_START_MINUTE Start time-minute 30
SLEEP_START_HOUR Shutdown time-hour 18
SLEEP_START_MINUTE Shutdown time-minute 30

PowerOnPeriodicallyOnTimer

How to set up
  • Connect the USB port of the PM HAT to the computer.
  • Open Arduino IDE software (PM HAT environment should be configured before).
  • Open the PowerOnPeriodicallyOnTimer demo or PowerOnPeriodicallyOnAlarm demo, compile, and download it.
  • Turn DEBUG switch to the other end.
  • Parameters differences and configurable parameters are shown below:
Difference between two examples
Examples PowerOnPeriodicallyOnTimer PowerOnPeriodicallyOnAlarm
Difference Periodly power on Raspberry Pi by timer Periodly power on Raspberry Pi by RTC alarm
Advantage Simple High precision (compare with timer)
PowerOnPeriodicallyOnTimer
Parameters Description Default value
PERIODIC_TIMER_TIMEBASE Unit of periodic eTB_MINUTE
PERIODIC_TIMER_VALUE Periodic value 10
RPI_STAY_AWAKE_TIME_MS Working time 60000
PowerOnPeriodicallyOnAlarm
Parameters Description Default value
RPI_WAKE_UP_CYCLE _MINUTE Periodic value 10
RPI_STAY_AWAKE_TIME _MS Working time 60000
CURRENT_THRESHOLD_MA Threshold of current (if the working current is less than this value, Raspberry Pi is determined to be in shutdown status) 110
Firmware Function
  • Raspberry PI will be turned on periodically for a specified period of time.

PowerOnPeriodicallyOnTimerInAPeriodTime

How to set up
  • Connect the USB port of the PM HAT to the computer.
  • Open Arduino IDE software (PM HAT environment should be configured before).
  • Open the PowerOnPeriodicallyOnTimerInAPeriodTime demo, compile, and download it.
  • Turn DEBUG switch to the other end.
  • Configurable parameters are shown below:
Parameters Description Default value
PERIODIC_TIMER_TIMEBASE Periodic unit eTB_MINUTE
PERIODIC_TIMER_VALUE Periodic value 5
RPI_STAY_AWAKE_TIME _MS Working time 60000
WAKE_UP_START_HOUR Start time-hour 8
WAKE_UP_START_MINUTE Start time-minute 30
SLEEP_START_HOUR Shutdwon time-hour 18
SLEEP_START_MINUTE Shutdown time 30
Firmware Function
  • Raspberry PI will be turned on periodically for a specified period of time.

Resources

Documents

Demo codes

Software

Datasheet

FAQ

 Answer:
In fact, due to battery limitations, the maximum output current can only reach about 1.8A.

{{{5}}}


 Answer:
It depends on the battery capacity, and the board with the load of the overall power consumption, such as the battery if 1000mAH, if the average battery discharge current is 500mA received from the board, it is about 2h supporting the total battery power about 1000mAH, normal use is generally about 2h.

{{{5}}}


Support



Technical Support

If you need technical support or have any feedback/review, please click the Submit Now button to submit a ticket, Our support team will check and reply to you within 1 to 2 working days. Please be patient as we make every effort to help you to resolve the issue.
Working Time: 9 AM - 6 AM GMT+8 (Monday to Friday)