Pi Guides
Establishing your Pi
- Part 1: Getting a Pi
- Part 2: Setting the Scene
- Part 3: Establishing Your Pi
- Part 4: Safely Turning Off Your Pi
I have gotten increasingly into small tech over the years, and in March 2026 I finally took the plunge into the world of the Raspberry Pi.
The Raspberry Pi is a Single-Board Computer (SBC) released in 2012 by the Raspberry Pi Foundation. As of writing it is the best-selling British computer, surpassing the ZX Spectrum only three years after its launch.
The Pi was originally designed to teach computer science, but has since become a metaphorical zen garden for all manner of tech projects. As it is compact in size and consumes little energy, this makes it an ideal choice for 24/7 operations such as webservers and chatrooms. Its operating system, the Raspberry Pi OS, is a Linux-based OS. As a result, Pi-work is designed with tech enthusiasts in mind and is not a tool for casual users. To use a Pi, you have to be comfortable using a terminal and with the prospect of learning some degree of Linux.
Given the low-power nature of my services, I made the more conservative choice of the Pi 4B. I purchased this from The Pi Hut, which is the most popular UK vendor for Raspberry Pis. The delivery on Pi Hut is honestly one of the fastest I have ever had from an e-vendor, even if I had to click for Royal Mail rather than have the poor thing chucked about by Evri (formerly Hermes).White micro-HDMI to HDMI cable. Because I did not realise my black USB cable was not a micro HDMI one. This is for establishing a display on your spare desktop monitor, which you will need for navigating the Pi setup.
Raspberry Pi 4 Model B. I purchased the 2GB option, but you can buy Pis available with up to 8GB of RAM.
Official 32GB SD card (pre-loaded with 64-bit Raspberry Pi OS). This one was pre-loaded with the Pi OS, thus saving me from having to flash it to the card manually. The latter process is not covered in this guide.
Official Raspberry Pi power supply (white UK plug). Always use the official Raspberry Pi power supplies. Using anything else can underpower your Pi.
A black USB cable. This cable came as a bonus, but was ultimately left unused during my setup. It is still good to keep around as a spare.
Official black/grey case, complete with an embossed Pi logo. This protects the Pi's circuit board from dust, static, and physical damage. You can probably put a few little stickers on it.
Spare monitor. An Acer was used for this initial setup.Starting a Pi cannot be done from your main device. You need extra hardware, as you are temporarily making a miniature desktop setup. If you are low on supplies, you can unplug things from your main setup. Expect the main setup to fall asleep if it has been left on. Putting a mouse or keyboard back in will not automatically wake it up.
Spare keyboard. A spare Dell keyboard from a late Christmas gift worked nicely here.
Spare mouse. A Razer mouse was used, as there were no spare mice on hand.
Before proceeding, make sure you have all of the following:
Once you have all of these, you are ready to assemble your Pi.
Be sure to keep a clean workspace and a non-metal platform for your Pi to sit on.
Slot the Pi into the bottom half of its case. Press on the flat circuit board parts of the Pi until it makes a nice snapping sound. Do not be shy, it can handle this even if it looks like it cannot.
The SD card slot is located on the underside of the Pi board, on the other side of the USB ports. With your Pi in one hand and your Micro SD in the other, slot it gently into the Pi. The gold contacts have to face up towards you and the board it is entering, while the label side faces underneath. If the card keeps entering at an angle, you are likely trying to insert the wrong side.
Push gently until it clicks. It should not be at an angle or stick out past the edge of the bottom case.
Slot the top case onto the Pi.
You have now loaded your Raspberry Pi. The SD card is crucial to doing anything with the Pi and it must always be handled carefully.
Spare keyboard into any USB port on the Pi.
Mouse into any USB port on the Pi.
White HDMI cable: the small micro-HDMI end goes into the Pi. Use the port closest to the power port. The normal HDMI end goes into the spare monitor.
Make sure the spare monitor is plugged in and turned on.
Plug the power supply into the Pi's USB-C port last.
When you plug in the power, the Pi will turn on and your spare monitor should start doing things.
Let the Pi boot up. It should start with a black screen, then a rainbow gradient, and finally the Raspberry Pi welcome screen. This is light-mode only so do not do this in the dark.
You are now in the Raspberry Pi Setup Wizard. Like other Setup Wizards, this will walk you through the installation and help you create an account for your Pi.
Set your language, region and timezone.
User Account: the username must be lowercase letters, digits, and hyphens only. Make sure it is easy enough to type comfortably. Write everything down somewhere safe as you go, your username, your password, and later your IP address. Nothing appears on screen when typing your password. This is normal.
Network: connect to WiFi, or skip if you are using ethernet.
Reboot: accept any reboot requests.
Secure Shell Protocol lets you control the Pi from your main computer without needing the extra desktop setup. This is known as a headless setup, and is common practice amongst Pi users.
Click the terminal icon, the black monitor icon in the top toolbar.
Type: sudo raspi-config and press Enter.
It will ask for the password you set up in the wizard. If you cannot see it while typing, this is normal and common in terminals.
A blue menu should appear. Use your keyboard's arrow keys to go to 3 Interface Options and press Enter.
Navigate to the option for SSH and select it. Select Yes when asked if you would like the SSH server to be enabled.
Press Tab to highlight Finish and press Enter to select.
To check your SSH is working, type: sudo systemctl status ssh. You should see "active (running)" in the output.
Press Q to exit. Your SSH is now established.
You are almost done with the setup, but if you stop here you will not be able to access your Pi remotely. The last thing you need is your Pi's IP address, which you enter every time you want to access it.
In the terminal, type: hostname -I
Note the number it shows. This is your Pi's IP address, and tends to differ slightly from your main computer's.
You now have your Pi's IP address.
IP addresses can sometimes change for a variety of reasons. If you cannot SSH into your Pi, you will need to repeat this process.
Now that you have established your brand new Pi and written down its information, you are free to stop from here. However, you have probably noticed that your Pi lacks the conventional means of shut-down.
DO NOT, UNDER ANY CIRCUMSTANCES, pull the power cable or turn it off at the switch. This can corrupt the SD card and render it unusable.
Every time you want to shut down your Pi, enter this command in the terminal: sudo shutdown now
Press Enter to execute the shutdown command. You should see a series of text in the terminal announcing the shutdown.
Like other computers, the Pi does not shut down instantly. Here is how you can tell when it is safe to turn it off at the wall or remove the plug.
Your monitor screen turns off completely. The Acer I used showed a "No Signal" message.
The LED is no longer green, leaving a red light behind. This means the Pi is powered but not fully on.
Congratulations, you have just set up a Raspberry Pi. Pat yourself on the back, give your Pi a pat on its back, and revel in the freedom of self-hosted tech.
You can stop reading if this is all you needed. Alternatively, you can find other guides on what to do with your brand new Pi friend.
One of the risks of running a Pi 24/7 is a sudden loss of power, a tripped socket, a power cut, or someone accidentally kicking the cable. Without warning, this can corrupt your SD card, which as you know by now is catastrophic. The solution is a UPS HAT (Uninterruptible Power Supply Hardware Attached on Top).
This guide covers the Waveshare UPS HAT (B), which piggybacks onto your Pi via its GPIO pins and provides backup power from two 18650 lithium cells. Beyond just keeping the lights on briefly, we will set up a background service that monitors battery level and triggers a clean, safe shutdown before the power runs out entirely.
Once everything is in place, the service runs silently in the background at all times. It checks battery level every 60 seconds, warns you when it drops below 15%, gives you 60 seconds to plug in the charger, and if you do not, shuts the Pi down safely on its own.
Waveshare UPS HAT (B). The HAT itself. Note that the 18650 batteries are not included and must be sourced separately. Use official Waveshare batteries if possible, and do not mix old and new batteries or cells from different manufacturers.
2× 18650 Lithium batteries. These slot into the HAT and provide the backup power. Handle with care, as lithium batteries can be dangerous if mishandled. Mind the polarity markings (+ and −).
Barrel jack power adapter (5V recommended). The HAT is powered through a barrel jack rather than USB-C. This usually comes with the HAT.
Small Phillips screwdriver. For the mounting screws that keep the HAT attached to the Pi.
The monitor script. Download ups_monitor.py. You will install this in Step 4.
The HAT connects to your Pi via pogo pins, small spring-loaded gold contacts that press against the Pi's GPIO pads. They look intimidating but are tougher than they appear and are designed for repeated connection and disconnection. Important: do this before your Pi is in its case. The case needs to come off entirely for the HAT to attach, learned this one the hard way.
Insert the batteries first, before touching the Pi. Check the polarity markings on the HAT and slide both cells in flush.
Remove the Pi from its case. If it will not budge, check the SD card is fully seated, as a partially inserted card can jam things up.
Attach the HAT. Place it flat on your workspace, blue side up. Lower the Pi down onto it, lining up the GPIO header with the pogo pins. Press down firmly and steadily, think "firm handshake," not "crushing grip." Hold it steady while you screw down the mounting screws.
Make sure the HAT's power switch is OFF, then plug in the barrel jack and flip it to ON. A red LED means the batteries are charging. Green means fully charged.
I2C is the communication protocol that lets the Pi talk to the HAT's sensor (an INA219 chip). It is disabled by default and must be switched on before any monitoring software will work.
SSH into your Pi as normal, then run:
sudo raspi-config
Navigate to 3 Interface Options → I5 I2C, select Yes, and reboot when prompted.
After rebooting, verify the HAT is being detected:
sudo i2cdetect -y 1
You should see a grid with 42 appearing at row 40, column 2. That is the HAT's I2C address (0x42). If you see it, you are good to go.
While you are at it, make sure the Python smbus library is installed:
sudo apt updatesudo apt install -y python3-smbus
Waveshare provides a basic monitoring script that is useful for confirming everything is working before you set up the full service. You can skip this if you are confident, but it is a good sanity check.
sudo apt-get install p7zip
wget https://files.waveshare.com/upload/4/4a/UPS_HAT_B.7z
7zr x UPS_HAT_B.7z -r -o./
cd UPS_HAT_B
python3 INA219.py
You should see readings like:
Load Voltage: 7.776 V
Current: 1.076000 A
Power: 2.416 W
Percent: 74.0%
Load Voltage is what the Pi is receiving from the HAT, a healthy range is 7.5–8.4V. Current will be positive if the batteries are charging and negative if they are actively supplying power. Press Ctrl+C to stop. Do not run this script and the monitor service simultaneously, as they both read the same sensor.
Download ups_monitor.py and transfer it to your Pi. The easiest way is with scp from your main machine:
scp ups_monitor.py yourname@your.pi.ip.address:~/ups_monitor.py
The three settings you are most likely to want to adjust are near the top of the file: CHECK_INTERVAL, LOW_BATTERY_PERCENT, and SHUTDOWN_DELAY. There is also a path inside the notify_users() function that writes a notice file to your home directory. Open the script and find the line containing your home directory path, it will look something like /home/yourusername/ups_notice.txt, and replace yourusername with whatever username you set during the Pi wizard.
CHECK_INTERVAL = 60, how often in seconds to read the battery sensor.
LOW_BATTERY_PERCENT = 15, the percentage at which the warning fires and the countdown begins.
SHUTDOWN_DELAY = 60, how many seconds you have to plug the charger back in before the Pi shuts itself down.
Copy the script into place and set up the systemd service that will run it automatically on every boot.
Create the directory and move the script into it: sudo mkdir -p /opt/ups_monitor, then sudo cp ~/ups_monitor.py /opt/ups_monitor/ups_monitor.py
Set the correct permissions: sudo chmod 755 /opt/ups_monitor/ups_monitor.py
Create the log file: sudo touch /var/log/ups_monitor.log, then sudo chmod 644 /var/log/ups_monitor.log
Run the script manually once to confirm it reads the sensor correctly: sudo python3 /opt/ups_monitor/ups_monitor.py. You should see output like Battery: 83.5% | Voltage: 8.00V. Press Ctrl+C once satisfied.
The service file is embedded in the script's header comments. Follow those instructions to install it, then run: sudo systemctl enable ups-monitor.service, followed by sudo systemctl start ups-monitor.service
Verify with sudo systemctl status ups-monitor.service and look for active (running). Your SD card is now protected.
Since the Pi runs headless, warnings come through two ways. If you are logged in via SSH, a broadcast message will appear directly in your terminal. If you are not, the script writes to ~/ups_notice.txt, which you can check any time with cat ~/ups_notice.txt. If nobody is logged in at all, the Pi will still shut itself down safely before the power runs out, which is the whole point.
HAT not detected / "Cannot reach INA219": check I2C is enabled and run sudo i2cdetect -y 1 to see if 42 appears. Make sure the HAT is firmly seated. If the pogo pins are still not making contact, unscrew the HAT, realign it slightly, and press down more firmly before screwing back.
Service won't start: check logs with journalctl -u ups-monitor.service -n 50 and verify smbus is installed: python3 -c "import smbus; print('OK')"
Watch the log live: tail -f /var/log/ups_monitor.log