Example Code for Arduino-Charging Limit Adjustment

A comprehensive guide on adjusting charging limits for LattePanda using Arduino. It includes hardware setup, software preparation, and example code for setting the maximum charging voltage to ensure optimal battery usage and safety. Readers will learn how to correctly install the hardware, prepare the software environment, and modify code to set the desired charging voltage, ensuring the battery pack functions efficiently without exceeding safe voltage limits.

Hardware Preparation

  • LattePanda UPS Hat * 1
  • 18650 3.7V lithium-ion batteries * 3
  • Compatible LattePanda * 1
    • LattePanda Alpha
    • LattePanda Delta
    • LattePanda 3 Delta

Software Preparation

Arduino Library Installation Tutorial

Wiring Diagram

  1. Do not install the lithium battery before the UPS Hat is in place

  2. Align the UPS power interface side with the LattePanda TypeC/RJ45/HDMI interface side
    LattePanda UPS Hardware Installation 1

  3. Insert the UPS Hat into the LattePanda
    LattePanda UPS Hardware Installation 2

  4. Check that the pins are fully inserted in order, without any floating or bent pins.
    To reserve space for heat dissipation and ventilation, the UPS Hat pins are longer. The figure shows the appearance after the installation is in place.
    LattePanda UPS Hardware Installation 3

  5. After checking the installation, install the 18650 lithium battery, paying attention to the positive and negative directions.
    LattePanda UPS Hardware Installation 4

After the UPS Hat is installed, please use the USB-C or DC 5.5x2.1mm interface on the UPS Hat to power the LattePanda. Using the LattePanda's own interface for power will not allow the UPS function to work properly.

Other Preparation Work

Ensure the hardware is installed correctly as per the Wiring Diagram section and the initial example program is uploaded as per the Example Code for Arduino-UPS Recognition section.

Sample Code

  1. Launch the Arduino IDE and open "File -> Examples -> DFRobot_LPUPS -> LPUPS".

  2. Find uint16_t maxChargeVoltage = 12600; to set the maximum charging voltage.

  3. The unit of uint16_t maxChargeVoltage is mV, which sets the charging voltage for a 3-cell lithium battery pack. 12600 means the charging voltage is limited to 12.6V, with a maximum voltage of 12.6V÷3=4.2V per cell.

  4. Modify it to uint16_t maxChargeVoltage = 12000;, and re-upload the Arduino program. The charging will automatically stop when the total voltage of the battery pack reaches 12V.

The allowed range for maxChargeVoltage is 11100 ~ 12600, and settings beyond this range will not take effect.

Result

Charging will automatically stop when the total voltage of the battery pack reaches the set maximum charging voltage (e.g., 12V when set to 12000 mV).

Was this article helpful?

TOP