Digging Into the RetroFlag NESPi Case for Ubuntu
If you just want to get it running, run this command in your terminal:
curl -sSL https://github.com/volodymyr-sokur/it-digger.net-assets/blob/main/04-digging-into-the-retroflag-nespi-case-for-ubuntu/install.sh | sudo bash
The Blueprint: How the Case Works
The NESPi case communicates with the Raspberry Pi via specific GPIO pins.
- Pin 3 (BCM): Sends a signal when the Power button is pressed.
- Pin 2 (BCM): Sends a signal when the Reset button is pressed.
- Pin 14 (TX): The case “listens” to the UART signal here to keep the LED lit.
Step 1: The “Secret” Internal Switch
Before touching a single line of code, ensure the physical Safe Shutdown switch on the internal PCB is set to ON. If this is off, the hardware will cut the power instantly, regardless of what the software says.
Step 2: Preparing Ubuntu
First, we need to give Ubuntu the “ears” to hear the GPIO signals:
sudo apt update
sudo apt install -y python3-pip python3-rpi.gpio
Step 3: The Listener Script
We need a Python script that stays alive in the background. Create the directory and the script:
sudo mkdir -p /opt/RetroFlag && sudo nano /opt/RetroFlag/SafeShutdown.py
Paste the logic that monitors Pin 3 and Pin 2. The key here is the while True loop with a small time.sleep to keep CPU usage at near zero while remaining responsive.
Step 4: Making it a Service
To ensure this starts every time you boot, we create a systemd unit file. This treats our shutdown script like a professional system service.
sudo nano /etc/systemd/system/retroflag-shutdown.service
Step 5: Bringing the LED to Life
By default, the NESPi LED turns off because Ubuntu disables UART. To fix this, edit your config:
sudo nano /boot/firmware/config.txt
And add: enable_uart=1
The Result
After a quick sudo reboot, your NESPi case is no longer just a “dumb” plastic shell. It’s a fully integrated Ubuntu machine. When you hit that Power button, the script catches the signal, tells Ubuntu to gracefully close all files and databases, and only then tells the case to cut the juice.
Safe hardware, clean OS, cool case.