Mini Raspberry Pi Server With Built In UPS

Today we’re going to be building a mini Raspberry Pi server with a built-in UPS and OLED stats display. A Raspberry Pi makes a great server for a NAS or for media streaming, home automation, or even a home security hub for your cameras. All of these projects would benefit from having a built-in UPS to ensure that the Pi is kept running in the event of a power interruption.

Pi Server With UPS

Here’s a video of the build and the UPS running, read on for the full write-up:

What You Need To Build Your Own Mini Server With UPS

Other Equipment Used:

Some of the above parts are affiliate links. By purchasing products through the above links, you’ll be supporting my projects, with no additional cost to you.

Unboxing The GeeekPi UPS Plus Module

The UPS we’re going to be using is this UPS Plus module that GeeekPi sent to me to share with you.

Pi UPS Plus

It looks like a relatively simple board, with a prominent battery holder on one side, but it actually has a number of great features, including power management circuits and I2C communication, enabling low voltage safe shutdown and automatic restarts.

Battery Holder

Power is supplied to the UPS through either USB C or a micro-USB port, with the board taking advantage of the USB 3.1 protocol to allow a higher input power through a higher charging voltage. 

The board also has three USB ports on the front, two full-size ports and one USB C port, that allow a combined output of up to 4A including the Pi’s consumption. There is also a battery monitor in the form of four blue LEDs that light up and/or flash to indicate the current battery level. And lastly, it has a function button on the side.

This is the most recent 5th revision of this board, which was completed in December of last year.

Screw on Brass Standoffs

The UPS is mounted onto the PI using some supplied brass standoffs and nuts. Unlike most Raspberry Pi hats, the UPS is designed to mount underneath the PI and has these little spring-loaded gold contacts that make contact with the underside of the header pins. This is a really nice feature as it keeps all of your GPIO pins available for other connections.

Gold Terminal Contacts

The board takes two 18650 cells that are connected in parallel, so the UPS boosts the voltage of the cells to the 5V required by the Pi. I’m going to be using some 2500mAh cells that I have left over from a previous project.

You may have also noticed in the video that the UPS turned on as soon as the first battery was inserted. You can then turn it on or off using the function button.

The UPS also includes an acrylic base plate to mount it onto. We’re not going to use this as we’re going to be building the Pi and UPS into a custom case.

PI UPS Plus On Stand

Building The Mini Raspberry Pi Server

To build the mini server, I’m going to use a low-profile Ice Tower to provide cooling to the Pi and I’m going to add an I2C OLED display to the front of the case to display some performance stats for the Pi as well as stats for the UPS.

Components, Ice Tower and Display

I used my previous Ice Tower Pi case as a starting point and then modified it to accommodate the UPS underneath the Pi. I had to move the OLED display up a bit to clear the top of the Pi’s USB ports. 

Designing The Server Case To House The UPS

Pi Server Case Tinkercad

Download the 3D print and laser cutting files.

I then 3D printed the case on my Creality Ender 3 V2 in grey PLA with a 15% infill.

3D Printed Case

I then also had to make some modifications to the clear acrylic side panels. I moved the Pi ports higher up and added the additional cutouts for the UPS underneath them. I also added a couple of vent holes along the bottom so that air would be forced around the Pi to cool the UPS and batteries.

Side Panel Design

With the case and side panels made up we can start installing the components into the case.

Assembling The Server With UPS

I started by screwing the longer brass standoffs into the base of the case. These are quite tight initially, but need to be so that they don’t move when plugging or unplugging peripherals into the Pi’s ports.

Screw In Brass Standoffs

I then put the batteries into the holder and mounted the UPS. You need to be careful from this point as there isn’t any way to physically isolate the batteries, so some parts of the UPS are powered and you risk shorting and potentially damaging the board if it touches the metal standoffs in any area it’s not supposed to.

Insert Batteries Into Holder

The smaller brass standoffs then hold the UPS in place and we can then mount the PI onto them, making sure that the terminals are properly seated on the GPIO pins.

Hold UPS In Place With Brass Standoffs

The Pi is then held in place with the standoffs from the Ice Tower. 

Pi Mounted Onto UPS

Before installing the Ice Tower, I’m going to install the OLED display.

This just pushes into the holder in the case and I’ll connect a ribbon cable to the pins on the back to plug it into the Raspberry Pi. These provide power to the display and connect to the Pi’s I2C pins.

The connections are typically:

  • GND to Pin14 Ground
  • VCC to Pin1 3.3V Power
  • SCL to Pin5 SCL (GPIO3)
  • SDA to Pin3 SDA (GPIO2)

Have a look at my detailed guide on Connecting an OLED Stats Display to your Pi for more information on this.

OLED Display Connect To Pi

Now we can install the Ice Tower. I removed the fan from the heat sink as I’m going to move this onto the side panel to push air into the entire case. I’m going to use the RGB fan that was supplied with the Ice Tower as an alternative to the plain black one.

Screw the Ice Tower onto the Pi, again making sure that you don’t touch the metal bracket onto any of the components on the Pi or the GPIO pins. Although the Pi may look like it is still off, rather be cautious.

Ice Tower Intalled On Pi

Installing The Side Panels

I mounted the fan onto the side panel by pressing some M3 nuts into the pockets on the fan and then screwing the fan into place with some M3x8mm button head screws.

Side Panel Wont Fit, Fan To Deep

I then tried to fit the side panel. It was at this point that I saw that the Ice Tower is wider than the standard Ice Tower and clashed with the back of the fan. So I had to redesign the side panels to move the fan to the other side.

Moving Fan To Back Side Panel

I then mounted the fan onto the modified side panel, again using the M3x8mm button hex head screws.

Screwing Fan Onto New Panel

I screwed the two side panels onto the case using some more M3x8mm screws.

Screwing On Side Panel

The last thing to do was to put the SD card into the Pi and power it up. I’m using a fresh install of Raspberry Pi OS.

Programming The Raspberry Pi

With the mini server all assembled, we now need to program the Raspberry Pi so that the automatic shutdown works and to get the UPS stats to show up on the OLED display.

The Pi booted up as soon as the power cable was plugged in, so it looks like the UPS was working correctly so far.

Plugging In Power Cable

I’m going to go over to the UPS Plus Wiki to see how to install the script that allows automatic shutdown and see what other UPS information is available on the Pi. 

52Pi Pi UPS Plus Wiki

You can see all of the information that is available to be read by the Pi on the Register Mapping chart. It’s a pretty comprehensive list. All of these metrics can be accessed by the Pi through the I2C interface, we can then display the ones we’d like to on the OLED display.

Pi UPS Plus Register Mapping

It’s a pretty straightforward process to download the example script that allows you to make changes to the general settings and access the available data on the UPS.

First, ensure that I2C communication is enabled in your preferences menu. Then install the smbus2 library by entering the following command in a new terminal window:

pip install smbus2

You can then download the GitHub repository by entering:

git clone https://github.com/geeekpi/upsplus.git

Installing The UPS Automatic Shutdown Script

The install the automatic shutdown protection that signals the Pi to shutdown when the battery level becomes critically low, we just run a single line.

curl -Lso- https://raw.githubusercontent.com/geeekpi/upsplus/main/install.sh | bash
Automatic Shutdown Script Install

Displaying The UPS Stats On The OLED Display

Next, we’ll have a look at the example script and the script that I used previously to display the Pi’s performance stats and integrate the two to produce a second stats display for the UPS that will show us some key UPS information. I’ll also add some code to switch between the two display screens every few seconds.

If we run the example script in the GitHub repository that we downloaded earlier, we get a printout of almost all of the stats available on the UPS.

Pi UPS Example Script

The information I’m going to put on the UPS display is the Pi’s voltage and current being drawn, the battery voltage and capacity, and lastly the charging current and power and charging status. This will allow us to keep an eye on how much power the Pi is using, the state of the UPS battery, and whether we’re charging or discharging the battery.

You can download my script below. You’ll need to also download the font PixelOperator.ttf from https://www.dafont.com/pixel-operator.font and then unzip the contents of the download and paste the font into the same folder as the stats.py script.

Let’s try and run the script and see what we get on the display.

UPS Stats on I2C OLED Display

Next let’s test the UPS by pulling out the power cable and make sure that the Pi keeps running and that the display shows us the battery level and correct charging status.

Not Charging Status Shown

So it looks like that’s all working correctly.

Further Testing The UPS Plus Module

I was able to get just under an hour and a half of runtime from a fully charged set of batteries. This would obviously depend on the capacity of your batteries. For most people, this would be long enough to ride out a short power interruption and your Pi would be safely shut down if the interruption lasted longer than this.

I also wanted to see if I could plug the display’s power cable into the UPS as well, powering my whole setup from the UPS.

Display Running On UPS As Well

The display came on and it looked like the UPS had enough capacity to power the display as well, although this is pretty close to its 4A limit.

There were two issues that I found with the UPS through my testing. Both of them probably won’t affect you if you plan to run the UPS continuously, like most people do, but would also have a common and fairly simple solution.

The first is isolating the batteries. If I designed that case a bit better I’d be able to install the batteries after installing the UPS, but it would be nice to have a physical switch to isolate the batteries from the board when you didn’t want any power on the board. At the moment, when the batteries are in the UPS, you need to be careful not to touch any of the components or PCB traces or you might damage it.

Battery Holder Under Pi

The second is a physical means to turn off the UPS, which could be done with the same isolation switch. The board has a function button on the side, but I haven’t been able to find any information on what it is actually supposed to do.

The board does turn off or on if you push the button, but on two occasions I’ve turned the board off using this switch and come back after 10-15 minutes and the board has come back on again and powered the Pi up.

Function Button Switching UPS On and Off

If the UPS does startup accidentally while the batteries are low then there might be a situation where the Pi hasn’t finished booting up and the batteries die completely. This interruption during booting might result in corrupting the SD card. A physical switch would just provide that extra level of protection against an accidental startup.

Other than the isolation of the batteries this UPS is a really neat and compact solution to provide a reliable battery backup to your Pi with automatic safe shutdown and stats available.

Let me know what you think of it in the comments section below.

Fan Side of Server
Pi Server With UPS
Michael Klements
Hi, my name is Michael and I started this blog in 2016 to share my DIY journey with you. I love tinkering with electronics, making, fixing, and building - I'm always looking for new projects and exciting DIY ideas. If you do too, grab a cup of coffee and settle in, I'm happy to have you here.

30 COMMENTS

  1. Hi Michael, once again another great video… keep up the good work.!
    I have a question regarding 3d printing the case. I noticed you used supports to fill all the gaps in the case to get a clean print.
    What parameters did you use in Cura to crete these supports which can be pushed out after printing.
    Thanks

  2. Hi , would you be so kind to share the modified stats.py ?
    Also I was wondering, that if I let the display running 24/7, it will be worn out so fast and also burns in some steady image.
    Can you add a function, that will activate the display for a few seconds (15 or so) when a button is pressed. So whenever I want to know how about my server, just use the switch, have a readout on the screen and than it shuts off.
    I am not as good in python as I would like to be, but I really would like to use Your display method with this feature. Thanks in advance.

    • I’ve just added it to the post, you can download it under the code section.
      I haven’t had any trouble with burn-in on these OLED display, even ones that have displayed the same image for months. The display on these switches every 10 seconds or so, which probably helps too.

  3. Hi,

    Nice video and useful!

    I saw in your video that your CPU is displayed in %, I’m trying do it with your original code so the CPU is displayed in % (0-100) but it’s not working.

    Is it easy to changed it? have you an example?

    thanks!

    • Thanks Marc. I just multiplied the CPU load value (currently 0.55 for 55%) by 100 and then added the % sign to the String after the value. I’ve added the script to the page to download, so you can see what I’ve done in this version.

  4. I have similar setup but with out the UPS ,It seems to happen to me a lot over the years ,I build a great Pi setup ,and not long after come across a more advanced and better setup .. like this one , great work shame the parts list for the project goes to to many retailers to make it easy to obtain the parts, without spending way to much on shipping from all the different Sellers ,, thanks for a great project ,easy to follow 🙂

  5. Hello friend I would like to ask you a question, this server only works with the storage of 32 Gb of memory or you could put a hard disk and even how much capacity it supports.
    Thank you so much.

  6. A simple change for some safety and convenience – change the bottom-most standoffs from M/F to F/F. Have a recess in the case for screws to secure the standoffs from the outside of the bottom.

    This would let you assemble the entire stack, insert the batteries, and then mount it from the outside.

    • I like this idea, also. Another improvement would be to add a small passage at the top underside of the case to feed the ribbon cable through so it is secured well away from the fan. That would help, especially if a cable longer than 15cm is used. An alternative is to use a stick-on cable retainer.

  7. Hi Michael
    Just started building my own NAS, and found your project very interesting. So far everything is working as expected
    However I have noticed that when you shutdown the box ( i’m using a headless box, so sudo shutdown -h now), the display stays on
    So it seems:
    1) python script is preventing a physical shutown
    2) script seems to be running
    Have you had the same experience?

    • Hi Javier,
      The script isn’t still running and the Pi will have shut down properly, the OLED display just retains whatever information was last received. The information on the display should appear to be frozen and is not being updated.
      You can adapt this if you like by powering the OLED display through an optocoupler on one of the GPIO pins. You’ll then need to set the pin high on startup and set it low during shutdown and it’ll turn the display on or off as required.

  8. Is it possible that the UPS overloaded the OLED display. Finished this build yesterday. Everything was working well, except I couldn’t get the battery information to load to the OLED. I removed that config from the stats.py script and everything went back to working normally. Then I decided to do a full test of the UPS. I unplugged the Pi, allowed it to run on battery until the auto-shutdown kicked in, but after rebooting, the OLED display does not start after reboot or manually stopping/starting the script. sudo i2cdetect -y 1 now shows several other values.

    0 1 2 3 4 5 6 7 8 9 a b c d e f
    00: — — — — — — — — — — — — —
    10: — — — — — — — 17 — — — — — — — —
    20: — — — — — — — — — — — — — — — —
    30: — — — — — — — — — — — — 3c — — —
    40: 40 — — — — 45 — — — — — — — — — —
    50: — — — — — — — — — — — — — — — —
    60: — — — — — — — — 68 — — — — — — —
    70: — — — — — — — —

    • I think it’s unlikely that the UPS has overloaded the OLED display since it powers the display and Pi through the same pins. The Pi is more sensitive to overvoltage than the display would be, so if it had damaged the display then it probably would have damaged the Pi as well/first.
      I think you’ve probably got an issue with the script. You’ve perhaps removed something that is required for communicating with the display.
      The I2C detect looks correct. The 3c is the address of the OLED display, so it is responding to the Pi. The other addresses are the UPS, it has multiple communication channels depending on what information you’re getting from it.

      • Thank you! Let me re-enter the script and try again. I started with the original tutorial with only the Pi info displayed, and that worked great. When I switched to the script you uploaded, the Pi information displayed just fine, but the UPS info was gibberish, so I just commented out most of the UPS information, and as you suggested, possibly something critical for the whole script. I may have to just re-write the original script for the Pi info, as I’m too much of a noob to troubleshoot the code on the UPS info and why its all gibberish.

  9. Hi Michael, excellent setup and a neat design. I would like to ask you, if you can consider a good change, the 2 batteries with a good quality power bank. Can you suggest something with a powerbank? Thanks in advance.

    • A power bank is fundamentally different to a UPS. Power banks typically only support up to 2A supply, where a Pi 4b is suggested to be run on a 3A supply. A lot of them cause interruptions to the battery side when the charging cable is removed. If the batteries are dead then you likely wouldn’t be able to charge them and power the Pi at the same time as the current draw on the charger would then be around 3-4A. They also usually have very simple charging circuits. These issues are just often the case. There will obviously be ones without them, but I don’t think you’d get one for the $15 plus batteries that this dedicated UPS board costs.

  10. Thank You! You were correct, that I commented out something necessary in the script. I have completely replaced the script with your version in the tutorial and system and UPS info are displaying correctly. My only issue now is, after several minutes, the script stops running, as I find the screen frozen. I enabled the cron.log, and it seems the UPS commands are still running in the log, but without anything updating on the OLED (frozen on whatever info was last updated). I’m a noob on python/scripting, so apologies.

  11. Great project! But uhm, is the link to the 18650 batteries correct? The Ali-page and the wiki of this UPS board both say “4.2V 4.35V 4.4V 4.5V lithium battery”, the link goes to 3.7V batteries. Are those supported as well?

    And did you happen to measure the runtime? I’m curious how long a Pi can run till the batteries run out.

    • Hi Bart,
      18650 lithium cells have a nominal voltage of 3.7V and a fully charged voltage of 4.2V. It’s more common to refer to them as 3.7V cells, but some refer to them as being 4.2V. The ones linked are the same type that I used in my testing and they’re one of the most commonly available lithium-ion cells.
      I did test the runtime, I mention it in the video. I think it was just under an hour and a half if I recall correctly. This is dependant on the capacity of the batteries, you get a variety of capacities for 18650 cells.

  12. Excellent review, for which many thanks ….. So I bought what I thought was the same unit from geeekpi. It transpires to be a EP-0118 (and not a EP-0136), though physical appearance is almost identical (and very similar price). Disaster. The 0118 has only 1 INA219 and bizarrely this is used to measure current and voltage to the pi. So no data on state of charge of the batteries, so pretty much useless as a UPS.

    I mention all this simply so that others avoid this trap.

    • Hi John,
      Thanks for letting me know. Did you buy it directly from Geekpi or through a reseller? I’d be happy to ask them about it.

  13. Great stuff , I bought one same as this but with out the ups ,through the -diy-life ,I cant find any links to it anywhere ,wondering if you have links to that project

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest posts

Voxelab Proxima 6.0 SLA 3D Printer Unboxing and Review

Today I'm going to be unboxing and reviewing the Voxelab Proxima 6.0, which Voxelab sent to me to share with you. The Proxima 6.0 is...

Mini Raspberry Pi Server With Built In UPS

Today we're going to be building a mini Raspberry Pi server with a built-in UPS and OLED stats display. A Raspberry Pi makes a...

Make An Arduino Tic Tac Toe Game With An AI Opponent

Today we're going to be building a Tic Tac Toe or Noughts and Crosses shield for an Arduino. The game board is made up...

Related posts

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!