vrijdag 27 september 2013

A soft reset button for a raspberri pi

scenario

i have a raspberry pi that i want to be able to reboot cleanly without ssh-ing into it


sollution

we're going to use a GPIO pin with a button wired up like this

picture from adafruit's website
3.3 volt is pin 1 (the pin nearest to the port where you plug in the power addaptorGND  is pin 6 (2 down and one over from pin 1)
and i'll be using gpi 23 .. that's pin 16 (nr 8 on the same line as pin 6)

My buton is actually a different setup from the on in this picture (mine breaks contacet when pressed



next we make a script
$ sudo nano /etc/softresetbutton.py




#!/usr/bin/env python
from time import sleep
import os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)
while True:
        if ( GPIO.input(23)== True ):
             # tue or false here depends on your button type
             # when in doubt replace 'reboot &' in the following line with 'echo "pushed" &'
                os.system('reboot &')
        sleep(0.1);



next we make this script executable
$sudo chmod +x /etc/softresetbutton.py

and test-run it
$sudo /etc/softresetbutton.py

push the button to test it
works ok ??
now we need to make it run at startup

$sudo nano /etc/rc.local

and add the line
/etc/softresetbutton.py &
just above the " exit 0 "


reboot and you'll have a soft-rest button

if you would prefer a "clean halt" button .. replace the reboot command in the script with  halt

Geen opmerkingen: