One Button Restart of a Stalled Raspberry Pi Zero W

Story

When I went down to the factory, I said, “Hey, you got any job for me?” They said, “Son, the days of the workin' man Are dead and gone.” They said, “Computer now does everything But there does happen to be one opening For the man who'll turn the damn thing off and on.” — SHEL SILVERSTEIN

one button restart of a stalled raspberry pi zero w

Caveat

Please be aware that I am running the Arduino ProMicro at 3.3V and 5V is recommended. I have not had any issues with the ProMicro 16MHz working properly but please understand that if your ProMicro must be run at 5V to function, then you will absolutely be required to implement voltage level conversion for the Arduino Tx serial output. See this article (a Google search will get numerous results, too.)

convert-5-volts-to-3.3

Alternately, you could use the 3.3V ProMicro which runs at 8MHz but you will need to lower your default BAUD rate for the RPI Zero W to a lower speed – some testing required.

I have been practicing the black-art of C++ programming

Needless to say, I have managed to cause some rather nasty situations whereby I have lost control of the RPi over SSH or VNC and even on an occasion managed to hose up the GUI session running on an HDMI monitor. What I found during my investigations is the Raspbian OS was still running and the hardware was still alive but I had managed to trash a few threads and crash an interface or two! What I needed was a way to avoid corrupting the SD card: likely if I issued a hard-reboot and likely if unplugging the wall wart.

I did some light research with Google and found a few creative connectivity implementations that have been previously published.

Representative published solutions:

  • SSH – Secure Shell
  • VNC – Virtual Network Computing
  • Physical Keyboard / PC + USB-Serial

Another creative shutdown via button.

Unfortunately, most solutions assume that the RPi is running properly and that SSH or VNC is available for use or that Python is available. My implementation takes the console login and tosses the PC and the USB-serial hardware: I use an Arduino to monitor a button state and then send the required commands from the Arduino to the RPi over the console interface, GPIO15/UART0-Rx.

I tried a barebones Arduino (just the atmega328P-PU) running at 8MHz from the internal RC oscillator – failure for a number of reasons, but the default BAUD of the RPi is 115200 and I did not want to change the default to work with a slower clocked AVR.

My second attempt was with an atmega328P-PU barebones running at 16MHz using a high-quality crystal. This worked but required an AVR programmer to install the code and is not very convenient for changes. Still, it is the way to go for low-cost and minimum parts count.

I moved to an Arduino Mini, a cheap clone from China that is sold typically under $2. This worked, too, but required a FTDI (or clone) USB-serial adapter and just seemed a bit clumsy. I finally settled on a better Arduino, the Arduino Micro. Based on the atmega32U4, this clone board is just a $1 more than when ordered from China and has a nice USB-micro connector on the board. Now all I need is a USB cable to program the device should I wish to experiment more – and I do want to play more!

The simple idea of having the Arduino log into the RPi Zero W to perform my bidding is intriguing. The Arduino has analog inputs, digital inputs, and will be directly connected to serial console and capable of logging in as any user. Consider the possibilities:

  • Log in and post analog values
  • Monitor external sensors, perform logic, login and post values
  • Use multiple push buttons to perform system administration
  • Use multiple push buttons to kick-off RPi scripts or program code

schematic one button restart of a stalled raspberry pi zero w

So, when everything is distilled, we have a very powerful concept that is wide-open in possibilities. My thinking is to mount the Arduino and a lithium battery in a small plastic box for portability – connection would only require Gnd and the Arduino Tx which would connect to GPIO15. I am thinking about using a rotary encoder to map numeric to commands and having a nice repertoire of emergency commands available at the push of a button.

For more detail: One Button Restart of a Stalled Raspberry Pi Zero W

 


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top