PowerBlockExtended extends the PetRockBlock PowerBlock with updated ATtiny85 firmware and a Raspberry Pi service providing reliable power control and reboot handling.
- Power on via slide or momentary switch
- Graceful shutdown via switch
- Hard power off feature - use if the Pi is unresponsive
- Restore previous power state after unexpected power loss (EEPROM)
- Reboot without cutting power
- systemd-based Raspberry Pi service
- Automatic reboot detection across all reboot methods
| ATtiny pin | Port | Function |
|---|---|---|
| 5 | PB0 | Front button input |
| 6 | PB1 | LED |
| 7 | PB2 | Shutdown request → Pi (BCM18) |
| 2 | PB3 | Pi status / reboot intent ← Pi (BCM17) |
| 3 | PB4 | Power control |
| 1 | PB5 | Reset |
- Button while off → power on
- Button while running → graceful shutdown request
- Long press (longer than 5 seconds - momentary switch only) / On-off repeated 3 times in quick succession (slide and momentary) → hard power off
The last intended power state is stored in EEPROM:
| Value | Meaning |
|---|---|
0xA5 |
ON |
0x00 |
OFF |
Note: with slide switch if you turn the switch off before power is restored the rpi will remain powered off.
Reboot intent comes from the OS reboot (i.e. sudo reboot) not switch status and is detected via a low pulse on PB3 to the ATtiny:
- PB3 is normally HIGH
- A LOW pulse (180–600 ms) signals reboot intent
- The next Pi shutdown is treated as a reboot
- Power remains on
The service:
- monitors BCM18 for shutdown requests
- executes a shutdown script when requested
- maintains signal continuity across service restarts
A helper process maintains the BCM17 HIGH signal independently of the main service to prevent unintended power-off during service restarts.
Reboot intent is generated automatically during system shutdown using a systemd shutdown hook.
This ensures correct behaviour for:
rebootsystemctl rebootshutdown -r now- desktop / GUI reboot
Shutdown (poweroff) does not trigger reboot intent.
Supported:
- libgpiod v2
- libgpiod v1
- sysfs fallback
The installer selects the appropriate backend automatically.
Note: You must flash the PowerBlockExtended firmware to enable extended features such as reboot-without-power-cut and restore-after-power-loss.
If you install the Extended Raspberry Pi service without updating the firmware, the system will behave like a stock PowerBlock and these features will not be available.
Flash the ATtiny85 using Arduino IDE or an AVR programmer.
👉 See the firmware flashing guide: firmware/flashing.md
Typical Arduino settings:
- Board: ATtiny25/45/85
- Chip: ATtiny85
- Clock: 8 MHz internal
- Upload method: Upload Using Programmer
If you experience:
- unexpected power-off during reboot
- no restore after power loss
- inconsistent shutdown behaviour
verify that the ATtiny85 firmware has been updated to PowerBlockExtended.
The PowerBlockExtended Raspberry Pi service is required for reboot-without-power-cut.
Without the service, a reboot will be treated as a shutdown and power will be switched off.
👉 Install directly from this repository using:
wget -O - https://raw.githubusercontent.com/andyengria/PowerBlockExtended/main/install.sh | sudo bashOr locally:
git clone https://github.com/andyengria/PowerBlockExtended.git
cd PowerBlockExtended
sudo ./install.sh/usr/local/sbin/powerblockextended/usr/local/sbin/powerblockextended-hold/etc/systemd/system/powerblockextended.service/usr/lib/systemd/system-shutdown/powerblockextended-reboot-pulse
The service is enabled and started automatically.
Optional configuration file:
/etc/powerblockconfig.cfg
Example:
[powerblock]
activated=1
statuspin=17
shutdownpin=18
logging=1
shutdownscript=/etc/powerblockswitchoff.sh| Option | Description |
|---|---|
| activated | Enable (1) or disable (0) service |
| statuspin | BCM pin used for Pi status |
| shutdownpin | BCM pin used for shutdown request |
| logging | Enable logging |
| shutdownscript | Script executed on shutdown request |
The configured script is executed when a shutdown is requested.
Default:
#!/bin/bash
exec /sbin/shutdown -h now "PowerBlockExtended requested shutdown"Custom scripts can be used to perform additional actions before shutdown.
| Action | Result |
|---|---|
| Button press | Shutdown request |
| Long press | Hard power off |
shutdown -h now |
Power off |
reboot |
Power remains on |
Restarting the service does not interrupt power:
sudo systemctl restart powerblockextended.service👉 Uninstall directly from this repository using:
wget -O - https://raw.githubusercontent.com/andyengria/PowerBlockExtended/main/uninstall.sh | sudo bashOr locally:
cd PowerBlockExtended
sudo ./uninstall.shRemoves service, binaries, and reboot hook.
Configuration and user scripts are preserved.
PowerBlockExtended provides:
- reliable power control
- automatic reboot handling
- compatibility with modern Raspberry Pi systems
- simple configuration and deployment