The UPS HAT (E) is an advanced add-on board designed to provide uninterruptible power supply functionality for single-board computers, such as the Raspberry Pi. This HAT ensures continuous operation during power outages by seamlessly switching to battery power when the primary power source is interrupted. It also includes power management features, such as battery monitoring and safe shutdown capabilities, to protect your device and data.
The UPS HAT (E) connects to the Raspberry Pi via the GPIO header. Below is the pin configuration:
Pin | Name | Description |
---|---|---|
1 | 3.3V | Power supply for the HAT's logic circuitry. |
2 | 5V | Main power input/output for the Raspberry Pi and peripherals. |
3 | SDA (I2C) | Data line for I2C communication (used for battery status monitoring). |
5 | SCL (I2C) | Clock line for I2C communication. |
6 | GND | Ground connection. |
7 | Power Key | Optional pin to trigger a safe shutdown or wake-up signal. |
8 | Battery+ | Positive terminal for the external battery connection. |
9 | Battery- | Negative terminal for the external battery connection. |
Battery+
and Battery-
terminals.Below is an example Python script to monitor the battery status using the I2C interface:
import smbus
import time
bus = smbus.SMBus(1) # Use I2C bus 1 on Raspberry Pi
UPS_HAT_I2C_ADDRESS = 0x36
def read_battery_voltage(): # Read two bytes of data from the voltage register (0x02) data = bus.read_word_data(UPS_HAT_I2C_ADDRESS, 0x02) # Convert the data to voltage (in millivolts) voltage = ((data & 0xFF) << 8 | (data >> 8)) * 1.25 / 1000 return voltage
def read_battery_percentage(): # Read two bytes of data from the percentage register (0x04) data = bus.read_word_data(UPS_HAT_I2C_ADDRESS, 0x04) # Convert the data to percentage percentage = (data & 0xFF) << 8 | (data >> 8) return percentage / 256
try: while True: voltage = read_battery_voltage() percentage = read_battery_percentage() print(f"Battery Voltage: {voltage:.2f}V") print(f"Battery Percentage: {percentage:.2f}%") time.sleep(5) # Wait for 5 seconds before the next reading except KeyboardInterrupt: print("Exiting program.")
smbus
library using sudo apt-get install python3-smbus
if not already installed.0x36
) with the correct address if your UPS HAT uses a different one.HAT Not Powering the Raspberry Pi
Battery+
and Battery-
terminals.I2C Communication Fails
raspi-config
tool.Overheating During Operation
Battery Not Charging
Can I use the UPS HAT (E) with other single-board computers?
What happens when the battery is fully discharged?
Can I monitor the battery status without using I2C?
Is the UPS HAT (E) hot-swappable?