Lora SDR data

Top of home page - Back to Builds section of Home Page where this page is listed

UPS Pi 5 rnode

This build uses an uninterruptible power supply (UPS) to run a Raspberry Pi 5 and a RAK rnode. The batteries of the UPS seem to run the Pi 5 and RAK rnode for at least 24 hours. The purpose of the build is to provide a modular unit that can be used alone or charged/powered using 9-18 V and up to 3A, and that can be used in a car or perhaps as part of a solar setup. In a car, and in solar setups, the external power provided is intermittent with daily repeated external power loss. The UPS provides power when the car is off, or perhaps when the sun is not shining, to keep the rnode running as much as possible. The core aim of this project is to demonstrate at least one solution for making a rnode be able to switch off when battery power is exhausted, and on again, when power is restored: and to be able to do this an arbitrary number of times, indefinitely, without causing a Raspberry Pi OS corruption, nor the rnode to need a reset or other intervention. I tried using a Waveshare E UPS with a Raspberry Pi 4, but that failed becase the UPS' i2c interface was not detected. This project uses the parts shown below.

The UPS rnode build

Parts list:

  1. UPS: Geekworm X1206 4-Cell 21700 5.1V 6A UPS HAT for Raspberry Pi 5 Series
  2. Four unprotected 21700 Li ion batteries. (Unprotected because else they are too long for the battery holder.) I try, for safety reasons, not to compromise on batteries, and used Keeppower INR21700 - 5000mAh, 3,6V - 3,7V KP-50S Li-ion Akku High Drain (Samsung 50S) 45A article number 12100.
  3. Case: Geekworm X1206-C1 Metal Case for Raspberry Pi 5 X1206 UPS Shield
  4. Raspberry Pi 5, available from many suppliers.
  5. Heat sinks for Raspberry Pi, small enough not to prevent the radio from being fixed inside the case, for example these copper heat sinks are small enough.
  6. Battery for Pi real time clock (RTC). This is optional and intended to make the Pi and MeshChat program show the right time, which is practically important when messaging.
  7. The same radio rnode and antenna is used as shown in the solar build in points 2 to 5. The antenna does not need to be attached to the case directly. In the car, one can use a cable to the antenna.
  8. Pack of 320 Brass Spacers Hex, M2 Spacer Thread Spacer Brass Hex Nuts Spacer Bolts
  9. Short USB-A to USB-C cable, preferably 90 degrees bend in USB-A and USB-C to make it compact, making sure the USB-A is the right way up so as not to block the access to the other USB-A ports.

Tools needed:

Connecting the Pi and UPS:

  • The Pi and UPS are attached and connected as described in the Geekworm wiki.

    Software setup:

    1. The rnode will be run headless. But for setting things up, best use a screen, keyboard and mouse.
    2. Setting up the software.
    3. The rnode is flashed, the Raspberry Pi set up with Reticulum Meshchat, and the Raspberry Pi is set up to have its own wifi hotspot, as shown in these instructions.
    4. If you want a real time clock for keeping the correct time, plug in the battery for the real time clock. Set up the real time clock to charge the installed RTC battery as described in the Raspberry Pi documentation by doing the following. At the command prompt run sudo nano /boot/firmware/config.txt and in the editor edit the file by adding, after [all], the following text: dtparam=rtc_bbat_vchg=3000000
    5. The UPS software is setup up as shown in the Geekworm wiki. (I did not manage to make qtx120x.py work more than once, and it throws errors normally.)
    6. The rudimentary Python program bat.py mentioned in the above Geekworm wiki performs a shutdown when the UPS's batteries are low. To make this program start again when the UPS starts up the Pi, I performed the following steps which seem to have the desired effect.
    7. Run the following in the command line to make a service you are calling "ups":

      
          sudo nano /etc/systemd/system/ups.service
          

    8. Paste the following into the editor to make the .service file, replacing the username "adingbatponder" with the name you use:

      
          [Unit]
          Description=ups
          After=network.target
          StartLimitIntervalSec=0
      
          [Service]
          Type=simple
          Restart=always
          RestartSec=1
          User=adingbatponder
          Group=adingbatponder
          Environment=DISPLAY=:0
          WorkingDirectory=/home/adingbatponder/x120x
          ExecStart= sudo python3 bat.py 
          [Install]
          WantedBy=multi-user.target
      
          

      and save by using ctrl+x and answering y.

    9. Now at the terminal run the following commands one after the other.

          
          sudo systemctl daemon-reload
          sudo systemctl start ups.service
          sudo systemctl enable ups.service
          sudo systemctl status ups.service
          
          
    10. That the bat.py code works is a bit of a fluke. The batteries, when their voltage drops as the Pi runs, are once measured to have a voltage less than the threshold set in the program. Then the Pi is shut down. When power is restored, by power from a power supply cable, the Pi starts up and again the program will test the voltage levels. It so happens that when restarting, the batteries fortuitously are at or above the threshold and the Pi does not immediately shut down again, and so it charges the batteries and the next level measured does not again fall below the threshold by the time the next measurement is made. This is fortuitous because it can happen, if the batteries are depleted by a larger amount initially, that the bat.py program shuts the Pi down immediately after boot as it detects a too low a battery level. Then the external power supply will in fact keep charging the batteries but the Pi will be off; and in this mode the device will not re-start without a manual button press (which is exactly what I do not want). The Geekworm wiki does have other code examples, and to make a shutdown decision take account of whether the batteries are in the process of gaining charge and/or an power cable is connected, would require a more sophisitcated program based on the examples on the site. For now I use the simple program as it seems to work well enough for now for my purpose.

    Mechanical build steps:

    1. Drill a hole for the antenna mount in the case. Mount the antenna.
    2. Attach the antenna to the RAK rnode. Attach the RAK to the case using the brass hex spacers and screws. Positoin it so that the USB cable can fit into the RAK's USB C port. If you want a heat sink on the Pi, check the positioning and length of spacers.
    3. The lid of the Geekworm case.
    4. Insert the Pi and UPS into the case as per the Geekworm wiki.
    5. Attach the heat sinks. The real time clock battery should have been attached in the steps above.
    6. The pi and UPS with RTC battery.
    7. Place the lid onto the case. Attach the USB-A plug of the USB cable an USB-A port of the Pi.
    The UPS rnode build from one side. The UPS rnode build from one side. The UPS rnode build from one side.

    Using the rnode: