Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

How to Use UPS HAT (D): Examples, Pinouts, and Specs

Image of UPS HAT (D)Design with UPS HAT (D) in Cirkit Designer

Introduction

The UPS HAT (D) by Waveshare is an add-on board designed for Raspberry Pi devices to provide uninterruptible power supply functionality. It ensures continuous operation during power outages by utilizing a rechargeable lithium battery. This HAT is particularly useful for applications requiring high reliability, such as IoT devices, servers, or remote monitoring systems.

Explore Projects Built with UPS HAT (D)

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of USB-Powered DC Gear Motor with LED Indicator: A project utilizing UPS HAT (D) in a practical application
USB-Powered DC Gear Motor with LED Indicator

This circuit appears to be a power supply unit with a bridge rectifier connected to a DC gear motor, indicating it is designed to convert AC to DC power for the motor. An electrolytic capacitor is used for smoothing the DC output, and a 7805 voltage regulator is included to provide a stable 5V output. Additionally, there is an LED with a series resistor, likely serving as a power indicator light.

Open Project in Cirkit Designer

Common Applications and Use Cases

Technical Specifications

The UPS HAT (D) is equipped with advanced features to ensure reliable power delivery and monitoring. Below are the key technical details:

Key Technical Details

Parameter Specification
Input Voltage 5V (via micro-USB or GPIO header)
Output Voltage 5V (regulated)
Battery Type Lithium-ion or Lithium-polymer
Battery Capacity Supports batteries up to 5000mAh
Charging Current 1A (max)
Communication Interface I2C
Dimensions 65mm × 56mm
Weight ~30g (excluding battery)

Pin Configuration and Descriptions

The UPS HAT (D) connects to the Raspberry Pi via the GPIO header. Below is the pin configuration:

Pin Name Description
1 3.3V Power supply for I2C communication
3 SDA I2C data line
5 SCL I2C clock line
6 GND Ground
2, 4 5V Power output to Raspberry Pi
7 INT Interrupt pin for battery status alerts

Usage Instructions

The UPS HAT (D) is easy to integrate with Raspberry Pi. Follow the steps below to set it up and use it effectively:

Step 1: Hardware Setup

  1. Attach the HAT: Align the UPS HAT (D) with the Raspberry Pi GPIO header and gently press it into place.
  2. Connect the Battery: Attach a compatible lithium battery to the JST connector on the HAT.
  3. Power Input: Optionally, connect a 5V power source to the micro-USB port or GPIO header.

Step 2: Software Setup

  1. Enable I2C: On your Raspberry Pi, enable I2C communication using raspi-config:
    sudo raspi-config
    
    Navigate to Interfacing Options > I2C and enable it.
  2. Install Required Libraries: Install the Python smbus library for I2C communication:
    sudo apt-get update
    sudo apt-get install python3-smbus i2c-tools
    
  3. Verify I2C Connection: Check if the UPS HAT (D) is detected on the I2C bus:
    i2cdetect -y 1
    
    You should see the device address (e.g., 0x36) in the output.

Step 3: Example Code

The following Python code demonstrates how to read the battery voltage and percentage from the UPS HAT (D):

import smbus
import time

# Initialize I2C bus
bus = smbus.SMBus(1)  # Use I2C bus 1 on Raspberry Pi
DEVICE_ADDRESS = 0x36  # Default I2C address of UPS HAT (D)

def read_voltage():
    # Read raw voltage data (2 bytes)
    raw = bus.read_word_data(DEVICE_ADDRESS, 0x02)
    # Swap byte order and convert to voltage
    voltage = ((raw & 0xFF) << 8 | (raw >> 8)) * 1.25 / 1000
    return voltage

def read_capacity():
    # Read raw capacity data (2 bytes)
    raw = bus.read_word_data(DEVICE_ADDRESS, 0x04)
    # Swap byte order and convert to percentage
    capacity = ((raw & 0xFF) << 8 | (raw >> 8)) / 256
    return capacity

while True:
    voltage = read_voltage()
    capacity = read_capacity()
    print(f"Battery Voltage: {voltage:.2f}V")
    print(f"Battery Capacity: {capacity:.2f}%")
    time.sleep(5)  # Wait 5 seconds before the next reading

Important Considerations and Best Practices

Troubleshooting and FAQs

Common Issues and Solutions

  1. HAT Not Detected on I2C Bus:

    • Ensure I2C is enabled in raspi-config.
    • Verify the HAT is properly seated on the GPIO header.
    • Check the I2C address using i2cdetect -y 1.
  2. Battery Not Charging:

    • Confirm the battery is connected securely to the JST connector.
    • Ensure the input power supply provides sufficient current (at least 1A).
  3. Raspberry Pi Shuts Down Unexpectedly:

    • Check the battery capacity and charge level.
    • Verify the HAT is supplying 5V to the Raspberry Pi.
  4. Incorrect Voltage or Capacity Readings:

    • Ensure the Python script is using the correct I2C address.
    • Verify the battery is functioning properly.

FAQs

Q: Can I use the UPS HAT (D) with other single-board computers?
A: While designed for Raspberry Pi, the UPS HAT (D) can be used with other devices that support 5V input and I2C communication. However, software compatibility may vary.

Q: What is the maximum runtime on battery power?
A: The runtime depends on the battery capacity and the power consumption of your Raspberry Pi. For example, a 3000mAh battery can power a Raspberry Pi 4 (idle) for approximately 2-3 hours.

Q: Is it safe to leave the HAT connected to power continuously?
A: Yes, the UPS HAT (D) includes overcharge protection to ensure safe operation during continuous use.

Q: Can I monitor the battery status programmatically?
A: Yes, the HAT provides battery voltage and capacity data via I2C, which can be accessed using the example Python code provided above.