EP-0247

From 52Pi Wiki
Jump to navigation Jump to search

UPS for Raspberry Pi Zero/Zero W/Zero 2 W

Descriptions

The Raspberry Pi Zero-sized power management module(AKA UPS for zero) is a compact and versatile device designed to provide efficient power supply management for Raspberry Pi Zero, Zero W, and Zero 2W devices. With its dedicated pogo pin connectors, this module ensures seamless integration and power management for the Raspberry Pi Zero series. Additionally, it is compatible with other popular single-board computers such as the NanoPi and OrangePi 5, thanks to its adaptable design.

Communication with the host device is facilitated through the I2C protocol, allowing for easy integration and data exchange. The module is equipped with three INA219 chips, enabling the monitoring of voltage and current across the USB-C charging port, battery, and the output to the Raspberry Pi, providing valuable insights into power consumption and efficiency.

Features

  • I2C Communication: Utilizes the I2C protocol for communication with the host device, ensuring compatibility and ease of integration.
  • Multiple INA219 Chips: Three INA219 chips on board for monitoring voltage and current at the USB-C port, battery, and output to the Raspberry Pi.
  • Power Monitoring: Provides real-time data on power consumption, including voltage, current, and power usage.
  • Compatibility: Designed with a Raspberry Pi Zero series-specific positioning hole but also compatible with other SBCs like NanoPi and OrangePi 5.
  • Configurable Settings: Offers various registers accessible via I2C for configuring the UPS power module to suit different application scenarios.
  • Extensive Information Access: Capable of reading WHO_AM_I, firmware version, output voltage, input voltage, battery voltage, MCU voltage, temperature, battery protection voltage, shutdown countdown, auto-start status, startup voltage settings, runtime, button status, OTA mode status, and a unique user ID serial number.

Specifications

  • Form Factor: Compact, designed to fit the size of a Raspberry Pi Zero.
  • Power Input: USB-C charging port.
  • Multifunctional Power switch: Short press: turn on UPS, Long press: Force turn off/Force turn on UPS, Press for 45s + entering to OTA Mode
  • Voltage Monitoring Points: USB-C, battery, and output to the Raspberry Pi.
  • Current Monitoring: Real-time monitoring of current flow at various points.
  • Communication Protocol: I2C.
  • Chipset: INA219 for power monitoring.
  • Compatible Devices: Raspberry Pi Zero, Zero W, Zero 2W, NanoPi, OrangePi 5, and other similar devices.
  • Control Registers: Multiple registers for accessing and configuring module settings.
  • Safety Features: Battery protection voltage and shutdown countdown settings.
  • Operational Modes: Supports auto-start on power recovery and OTA (Over-The-Air) updates.
  • Unique Identifier: Each module has a unique user ID for identification and tracking.

This power management module is an essential accessory for Raspberry Pi enthusiasts and developers looking to enhance their projects with reliable and intelligent power control solutions.

Device address and Register mapping information

  • Device address explainations
ID Device address Function
1 Ox17 Normal mode
2 Ox18 OTA mode
3 Ox40 USB-C Input Detection(INA219-1)
4 Ox44 Battery Detection(INA219-2)
5 Ox45 Output to Pi Detection(INA219-3)
Shunt_OHMS = 0.01 

Registers table

ID Register Function Valid Value
1 0x00 WHO_AM_I Identification information Default:0xa5, Fixed, Read-only
2 0x01 Firmware Version information Fixed, Read-only
3 0x02 LOW 8bit of OUTPUT voltage NOTE:This register is 16-bit wide
4 0x03 HIGH 8bit of OUTPUT voltage
5 0x04 LOW 8bit of INPUT voltage NOTE:This register is 16-bit wide
6 0x05 HIGH 8bit of INPUT voltage
7 0x06 LOW 8bit of Battery's voltage NOTE:This register is 16-bit wide
8 0x07 HIGH 8bit of Battery's voltage
9 0x08 LOW 8bit of Onboard MCU's voltage NOTE:This register is 16-bit wide
10 0x09 HIGH 8bit of Onboard MCU's voltage
11 0x0A Temperature Junction Temperature on MCU
12 0x0B LOW 8bit of Battery Protection Voltage NOTE:This register is 16-bit wide
13 0x0C HIGH 8bit of Battery Protection Voltage
14 0x0D LOW 8bit of Shutdown Countdown NOTE:This register is 16-bit wide
15 0x0E HIGH 8bit of Shutdown Countdown
16 0x0F auto start mode Default:1, valid value: 0 - disabled, 1 - enabled
17 0x10 LOW 8bit of Auto start voltage 16-bit wide, It is threshold of auto start voltage, beyond this voltage will trigger UPS auto start if auto start mode has been setting to 1.
18 0x11 HIGH 8bit of Auto start voltage
19 0x12 LOW 8bit of runtime information 32bit wide
20 0x13 9-16bit of runtime information
21 0x14 17-24bit of runtime information 32bit wide
22 0x15 HIGH 8bit of runtime information
23 0x16 Switch button status 5V output status(0=OFF,1=ON)
24 0x17 Request upgrade status If this value is "0xAA" means entering into OTA MODE
25 0x18 LOW 8bit of UUID0 Universal Uniq Identifier(UUID0):32bit wide
26 0x19 9-16bit of UUID0
27 0x1A 17-24bit of UUID0
28 0x1B HIGH 8bit of UUID0
29 0x1C LOW 8bit of UUID1 Universal Uniq Identifier(UUID1):32bit wide
30 0x1D 9-16bit of UUID1
31 0x1E 17-24bit of UUID1
32 0x1F HIGH 8bit of UUID1
33 0x20 LOW 8bit of UUID2 Universal Uniq Identifier(UUID1):32bit wide
34 0x21 9-16bit of UUID2
35 0x22 17-24bit of UUID2
36 0x23 HIGH 8bit of UUID2

How to check if the UPS has been recognized by SBC?

  • It can be detected by using i2c-tools in most linux distributions, here we recommend you use Raspberry Pi OS, If you encounter error like: "Command not found", please execute following command to install it.
sudo apt update 
sudo apt upgrade -y 
sudo apt -y install i2c-tools
  • Make sure your have already enabled I2C function on your Raspberry Pi.
sudo raspi-config

Navigate to Interface Options -> I2C -> Enable -> YES -> Finish.

Check Device address

  • Using following command to show the device address
i2cdetect -y 1 
Ups devices address table.png


  • Explainations:

0x17: Current UPS under normal mode. When you connect the USB-C power supply, it will charge the battery and charging LED will blink at the same time.
0x40: INA219-1, it will help you to detect the voltage, current, power, shunt_voltage on USB-C port
0x44: INA219-2, it will help you to detect the voltage, current, power, shunt_voltage on Battery
0x45: INA219-3, it will help you to detect the voltage, current, power, shunt_voltage on OUTPUT to Pi (PogoPin)

How to check the register information by using command line?

How to get information of WHO_AM_I?

  • Execute following command in terminal:
i2cget -y 1 0x17 0x00 b 
UPS get whoami.png


How to get information of UPS's firmware verison?

  • Execute following command in terminal:
i2cget -y 1 0x17 0x01 b 
UPS get version.png


How to get output voltage value?

  • Execute following command in terminal:
i2cget -y 1 0x17 0x02 w 
Ups get output voltage.png


NOTE: The data in this 16-bit register is stored in little-endian order 

How to set battery protection voltage?

  • NOTE!!!
  • 1. When we set a battery protection voltage, the system will automatically shut down if the battery voltage falls below this protection level.
  • 2. If the battery voltage does not exceed the protection voltage, normal power-on will not activate the UPS, with the intention of preserving the battery.
  • 3. To force a start, press and hold the UPS switch for about 2-3 seconds, which will clear the battery voltage protection settings and force the UPS to start.
  • 4. If compiling with the C language, it is important to prevent the compiler from rearranging structures. Add the compilation argument: `gcc -fpack-struct=1 -O0 -o XXX main.c`.