This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

2
pi zero reboot and shutdown buttons
Post Body

I have a pi zero that is in a cabinet and want to install buttons for power and reboot

I have the power connected using 5 6 and use this script

#!/usr/bin/python

import RPi.GPIO as GPIO

import time

import subprocess

GPIO.setmode(GPIO.BOARD)

GPIO.setup(5, GPIO.IN)

oldButtonState1 = True

while True:

#grab the current button state

buttonState1 = GPIO.input(5)

# check to see if button has been pushed

if buttonState1 != oldButtonState1 and buttonState1 == False:

# shutdown

subprocess.call("shutdown -h now", shell=True,

stdout=subprocess.PIPE, stderr=subprocess.PIPE)

oldButtonState1 = buttonState1

time.sleep(.5)

this works fine

what I am having trouble with is a script for rebooting or adding code to the first script

I have tried 21 and gnd and changed shutdown -h now to reboot now

but nothing happens when button is pressed

any ideas what I am doing wrong please ?

thanks in advance

Author
Account Strength
50%
Account Age
2 years
Verified Email
Yes
Verified Flair
No
Total Karma
272
Link Karma
163
Comment Karma
109
Profile updated: 4 days ago
Posts updated: 14 hours ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
1 year ago