I'm using a Raspberry pi to log GPS tracks in my car, so it's headless and has no network.
What is the simplest way to add a pushbutton to receive an input that will enable me to:
- stop the GPS daemon
- initiate a shutdown
I'm from a CS (Computer Science) background, so looking for the simplest circuit and the way to read the switch state via something like a cron job.
Bonus points for adding an LED I can turn off to confirm shutdown :)
-
What is CS background?Piotr Kula– Piotr Kula2013年06月05日 11:58:54 +00:00Commented Jun 5, 2013 at 11:58
-
@ppumkin "Computer Science"? might be as well "Counter Strike", but I suspect the former, not the latter.lenik– lenik2013年06月05日 23:46:01 +00:00Commented Jun 5, 2013 at 23:46
1 Answer 1
Here's the simplest circuit:
button schematics
you need to connect to the GPIO pin (choose one you like), +5V or +3V and GROUND. when you push the button, the state of GPIO pin should change. you may read it from the program or command file and do whatever you want to do.
If you want to control the LED, it's even easier. Connect GPIO pin to the 470ohm resistor to the LED to the ground. That's it. When GPIO pin is high, LED will be on, otherwise -- off.
-
1Are you sure that using a pullup to 5V, won't damage the gpio pins that only accept 3.3v?Gerben– Gerben2013年06月08日 20:51:02 +00:00Commented Jun 8, 2013 at 20:51
-
The Broadcom chip has build in pull-up resistors. You could use that instead of the resistor above. For safety I personally add a 2k resister between the button and the GPIO. This is in case I screw up and accidentally set the pin to output and high. As that would create a short between the GPIO's 3.3 volt and ground, frying the GPIO pin and maybe even the entire pi.Gerben– Gerben2013年06月08日 20:51:53 +00:00Commented Jun 8, 2013 at 20:51