EP-0250

From 52Pi Wiki
Jump to navigation Jump to search

UPS V6

Description

UPS v6 is the latest evolution of our UPS Plus series, designed to provide enhanced power management and flexibility for Raspberry Pi and Orange Pi devices. Built on the foundation of its predecessor, UPS v6 introduces significant improvements in battery configuration, power path management, and user customization options. The UPS v6 supports up to 4 channels of 8.4V lithium battery groups connected in, parallel allowing users to expand battery capacity for extended runtime. It also accommodates a single battery slot with two 3.7V 18650 lithium batteries connected in series, offering versatile power solutions. The device features intelligent power path management, prioritizing external power when available and seamlessly switching to battery power during outages. Equipped with I2C communication, UPS v6 enables real-time monitoring of battery voltage, temperature, capacity, and device version information. Users can leverage OTA (Over-The-Air) upgrade support to upload custom firmware, ensuring maximum flexibility and control. For DIY enthusiasts, UPS v6 offers programmable LED indicators and a Pikapython interface, allowing users to upload Python scripts for advanced device status monitoring and control. Additional features include auto-restart on power recovery with configurable voltage thresholds, safe shutdown countdown, and protection against low-battery loops. Whether you need reliable backup power, customizable monitoring, or advanced power management, UPS v6 delivers a powerful and versatile solution for your Raspberry Pi or Orange Pi projects.

Features

  • Enhanced Compatibility: Fully compatible with Raspberry Pi and Orange Pi series devices.
  • Flexible Battery Configuration: Supports up to 4 channels of 8.4V lithium battery groups connected in parallel to increase capacity. Compatible with a single battery slot using two 3.7V 18650 lithium batteries connected in series.
  • Advanced Power Path Management: Prioritizes external power supply when available. Seamlessly switches to battery power when external power is disconnected.
  • Comprehensive Battery Monitoring: Real-time monitoring of battery voltage, temperature, and capacity via I2C communication, Device version information retrieval.
  • OTA (Over-The-Air) Upgrade Support: Allows custom firmware uploads for enhanced flexibility and user control.
  • DIY Customization Options:: Programmable LED control for customizable status indicators; Pikapython interface for uploading Python scripts to read and control device status.
  • Smart Power Management:Auto-restart on power recovery with configurable voltage thresholds to prevent low-battery loops.
  • Safe shutdown countdown functionality.

Main Features Details

Feature 1: Auto Start Mode

  • Register: auto_start_mode
  • Function: Enables automatic power-on logic when written.
  • Conditions for Auto Start: when Battery voltage > auto_start_voltage and Valid external power source present
  • Protection Mechanism: Monitors battery voltage after auto-start; If voltage drops to battery_protection_voltage multiple times:
   Auto-start attempts will be abandoned
  • Manual Shutdown by Button
   Auto clears auto_start_mode functionality

Feature 2: Delayed Shutdown

  • Register: shutdown_countdown
  Initiates shutdown after specified seconds when written.
  • Important Notes
  Combined with active auto_start_mode: Functions as a reboot if conditions are met
  For complete shutdown: Must clear auto_start_mode setting

Feature 3: Runtime Tracking

  • Register: runtime
  • Unit: milliseconds (ms)
  • Functionality: Tracks continuous operation time since last power-on

Feature 4: Force OTA Mode

  • Register: ota_request
  • Write value: 0xA5A5
  • Behavior: Immediately forces device into OTA mode

Feature 5: Physical Button Control

  • Current Implementation

Single button operation Toggles power state immediately

Important Notice

  • Immediate shutdown risks: Potential data loss
  • Recommended method: Use shutdown_countdown for safe shutdown

Feature 6: L_FAST LED Indicators

LED State Meaning
Fast blinking Bootloader mode
Solid on Fast charging available
Slow blinking UPS Fault
Off No input power

Specifications

  • Device Compatibility: Supports Raspberry Pi and Orange Pi series devices.
  • Battery Configuration: Parallel Mode, Up to 4 channels of 8.4V lithium batteries.
  • Series Mode: Single battery slot with two 3.7V 18650 lithium batteries.
  • Power Management: External power prioritization with automatic failover to battery power.
  • Communication Interface: I2C protocol for battery and device status monitoring.
  • OTA Upgrade: Custom firmware upload support for user-defined configurations.
  • DIY Features: Programmable LED control via user-defined code.
  • Pikapython interface for Python script execution.
  • Power Recovery Settings: Configurable voltage thresholds for auto-restart.
  • Safe shutdown timer to prevent data loss.

Gallery

TBD.

Package List

TBD.

How to assemble it?

TBD.

User Manual

  •  Please read the user manual carefully before proceeding.

This documentation assumes you are using a Raspberry Pi for testing. You can also use Orange Pi devices, but you will need to adjust the I2C controller address based on your specific setup. The default I2C device address for Raspberry Pi is /dev/i2c-1, while Orange Pi may use /dev/i2c-3. Adjust these settings according to your hardware.

The testing environment for this documentation includes:

  • Raspberry Pi 5
  • 4 battery groups, each consisting of two fully charged 18650 lithium batteries connected in series to provide 8.4V.
  • A 100W USB-C PD protocol charger.
  • Raspberry Pi OS 64-bit Bookworm, updated to the latest version.

If you are using a different operating system, refer to its specific environment configuration. Note that we currently provide configuration guidance only for Raspberry Pi OS. For other systems, please resolve compatibility issues independently.

Register Summary Table

Address Name Width Access Description Default Value
0x00 WHO_AM_I 8 R  Device identification register 0xA6
0x01 version 8 R Version number -
0x02 uuid0 32 R Unique ID (lower 32 bits) -
0x06 uuid1 32 R Unique ID (middle 32 bits) -
0x0A uuid2 32 R Unique ID (upper 32 bits) -
0x0E output_voltage 16 R Output voltage (unit: mV, 5V output) -
0x10 input_voltage 16 R Input voltage (unit: mV) -
0x12 battery_voltage 16 R Battery voltage (unit: mV) -
0x14 mcu_voltage 16 R MCU voltage (unit: mV) -
0x16 output_current 16 R Output current (unit: mA, 5V output) -
0x18 input_current 16 R Input current (unit: mA) -
0x1A battery_current 16 R Battery current (signed, unit: mA) -
0x1C temperature 8 R Temperature (two's complement, unit: °C) -
0x1D CR1 8 R/W Control Register 1 0x01
0x1E CR2 8 R/W Control Register 2 (Reserved) 0x00
0x1F SR1 8 R Status Register 1 -
0x20 SR2 8 R Status Register 2 -
0x21 battery_protection_voltage 16 R/W Battery protection voltage (unit: mV) 7400
0x23 shutdown_countdown 16 R/W Shutdown countdown (unit: seconds) -
0x25 auto_start_voltage 16 R/W Auto-start voltage threshold (unit: mV) 7400
0x27 pika_output_len 16 R/W Python output buffer content length -
0x29 ota_request 16 W Writing to 0xA5A5 will request OTA mode. -
0x2B runtime 64 R Cumulative runtime (unit: microseconds) -
0x33 charge_detect_interval_s 16 R/W Charge detection interval (unit: seconds) -
0x35 led_ctl 8 R/W LED control register 0x01

Control Register CR1 (Address: 0x1D)

Bit Name Access Description Default Value
BIT0 auto_start_mode R/W Auto-start mode (0=disabled, 1=enabled) 1
BIT1 python_load R/W Load Python code (write 1 to begin loading) 0
BIT2 python_exec R/W Execute Python code (write 1 to begin execution) 0
BIT3 python_read_return R/W Read Python output log (write 1 to begin reading) 0

Status Register SR1 (Address: 0x1F)

Bit Name Access Description Default Value
BIT0 sw_status R 5V output status (0=off, 1=on) -
BIT1 fast R Fast charging status (0=12V fast charging, 1=slow charging/no external power) -
BIT2 charge R Charge/discharge status (0=charging, 1=discharging) -
BIT3 input_low R Input voltage low (0=normal, 1=low) -
BIT4 output_low R 5V output low (0=normal, 1=low) -
BIT5 battery_low R Battery voltage low (0=normal, 1=low) -
BIT6 adc_mismatch R ADC mismatch (0=normal, 1=INA219 vs MCU sampling difference exceeded) -
BIT7 battery_fail R Battery failure (0=normal, 1=failure) -


Status Register SR2 (Address: 0x20)

Bit Name Access Description Default Value
BIT0 python_exec_toobig R Python code too large (0=normal, 1=code exceeds limit) -


LED Control Register (Address: 0x35)

Bit Name Access Description Default Value
BIT0 i2c_ack R/W LED on during I2C communication 1
BIT1 bat_charge R/W LED on during battery charging 0
BIT2 bat_discharge R/W LED on during battery discharging 0
BIT3 fault_report R/W LED on when fault detected 0
BIT4 ok_report R/W LED on during normal operation 0

Special Notes

  • Data Format:
  Voltage/current values are unsigned integers
  battery_current is signed (two's complement format)
  temperature is signed 8-bit integer (two's complement), range: -40°C to +85°C
  • Reserved Bits:
  All reserved bits default to 0
  Write operations to reserved bits are ignored (recommended to maintain default values)
  • The register definitions in the bootloader state are not fully compatible.

Getting Start

  • Assume that your Device Environment: Raspberry Pi 5, operating system: Raspberry Pi OS 64-bit (Bookworm).
  • Assume that your Raspberry Pi 5 can access internet including GitHub.
  • Assume that you have already assembled the UPS v6 with your Raspberry Pi 5 and booting up properly.
  • Please refer to the following steps for operation:

Install Dependencies package and libraries

  • Open a terminal and typing:
sudo apt update 
sudo apt upgrade -y 
sudo apt -y install build-essential cmake libi2c-dev libssl-dev gcc-arm-none-eabi git wget vim-* virtualenv i2c-tools

Build your own firmware

  • Download UPS v6 repository from Github:
git clone https://github.com/geeekpi/upsv6.git 
cd upsv6/app/
mkdir build 
cd build 
cmake ..
make -j4
ls firmware.* 
cp firmware.bin ../../scripts/

Encrypt firmware

cd upsv6/scripts/
./encrypt_tool firmware.bin firmware_encrypted.bin

Upload new firmware

  • Step 1. Enter into OTA mode
  • Step 2. Upload new firmware_encrypted.bin file
python enable_ota.py 

Check if the UPS v6 has been entered into OTA mode:

 
i2cdetect -y 1 

If the i2c device address is changed from 0x17 to 0x18 means UPSv6 is already in OTA mode.

./user_write_tool firmware_encrypted.bin 

Until you see following figure:

Flash complete.png