"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects." (Robert A. Heinlein)

Sunday, 3 June 2018

Simple hardware interface for the Raspberry Pi Zero


I spent some hours, last weekend, working to another little step into my Raspberry Zero camera project. After experimenting remote software interface possibilities I started building some minimal bare hardware interface in order to, at least, safely turn on and off the Raspberry Pi.



A bare minimum interface
The bare minimum hardware interface for a Raspberry project is made of a power push-button and a status LED telling if the device is still active or it can be safely removed from power.
Plenty of tutorials are available on the Internet, I mostly followed instructions from here and here.
The power status information is directly provided from the UART pin without the need of writing additional software. UART must be enabled in ‘/boot/config.txt’ configuration file


enable_uart=1

Then I just connected a LED diode between UART pin and ground (trough a current limiting resistor of course).
Also the wake-up functionality is implemented by briefly connecting GPIO pin 6 to ground trough a normally-open push button.
The power-off functionality, at last, need writing a simple Python script listening for power button press then calling the shutdown command.

I then copied the script in ‘usrl/local/bin’ folder and made it executable

sudo mv listen-4-shutdown.py /usr/local/bin/sudo chmod +x /usr/local/bin/listen-4-shutdown.py

The script must run as root, in order to have shutdown privilege, and must start as the Raspberry is powered on. This can be achieved by writing a start-up shell script that allow the python program to be executed as a service.
This shell script can be then installed by moving it in “/etc/unit.d/” folder and activated with the following command
sudo mv listen-4-shutdown.sh /etc/init.d/
sudo chmod +x /etc/init.d/listen-4-shutdown.sh
sudo update-rc.d listen-for-shutdown.sh defaults


What’s next ...

A simple point-and-click camera needs at least one more push-button to take shots and one more, software controlled, status LED to inform user camera is working. So next step will be a more complex Python script to handle multiple buttons and LED.