What we are working on?
This has been tested with a rev. 2 Raspberry Pi, whose GPIO pins numbering differ from the rev. 1 ones, running Raspbian.
What do we need?
You will only need a hard disk pin jumper like one of these.
Note that the large ones are much easier to manipulate
Let's get to work
The final purpose is to have a watchdog which will read permanently the state of the selected GPIO pin to check if it, the watchdog, has to shutdown the machine. But first of all, we will test if everything works as desired by running this script with root privileges (https://github.com/g0to/misc_scripts/bl ... actions.sh)*. The script will check every 60 seconds if GPIO3 reading returns a 0 value (which means that it's connected to ground) and, if so, it'll command the machine to halt.
With the script running, it's time to insert the jumper into GPIO3 and ground, the pins with the red dots in the following image:
Note that you can safely connect the two pins together since GPIO2 and GPIO3 provide a 1k8 pull up resistor.
In less than a minute the computer should shut down orderly and that proves we can go ahead with the automation.
The last step is to add a new line to the system-wide crontab (/etc/crontab) for running the above script every time the machine boots up:
Code: Select all
@reboot root /home/user/scripts/gpio_actions.sh
- - Raspberry Pi GPIO description, pin numbering and code examples (http://elinux.org/RPi_Low-level_peripherals)
- - GPIO pin layout label, ready to print for attaching inside your RasPi case (http://i.imgur.com/bSHVtpj.png)
- - You can leave the jumper permanently attached to your GPIO by connecting it to only one pin, GPIO3 for example, and cover with it GPIO3 and the GND pin only when you want to manually turn off your Raspberry Pi. Here is an ilustrative picture where you can see the jumper attached to only one of the pins, ready to use.
- - You could use the other GPIO provided with a pull up resistor (GPIO2 in rev.2 boards) for other manual configuration purposes like, for example, obtain an IP address inside a LAN using the DHCP protocol (dhclient) for a RasPi initially configured with static network parameters. Useful for a headless machine that you move from LAN to LAN without previous network settings adjustments.