Forum Replies Created
-
AuthorPosts
-
04/02/2016 at 16:45 in reply to: Simple 1 button GPIO on off switch: 1 switch, 2 wires, 10 lines of code #122217skizzParticipant
The I/O error only appeared when doing a sudo sh /home/pi/scripts/shutdown.sh command but as spaceinvader said the code would still work even with the error output so I’m not sure if it matters since echo I/O is a very vague error in linux apparently.
I think the big part was shorting the two pins longer than half a second. It must be the TTL logic firmware for the GPIO that needs longer than a certain pulse width to see a HIGH or LOW logic. Simply put, I was impatient haha.
I had to hold my momentary button at least a full second (1 mississippi) to get it to boot/poweroff.
Also if you guys want a to wire an external LED to show whether the Pi is on or off just wire the cathode (+) of a regular old LED with a resistor (500-1000 ohm is fine) to pin 8 (UART TXD) and then wire anode (-) to GND. That pin automatically pulls LOW when OFF and HIGH when ON so the LED will light accordingly and you don’t need to program or script anything (woot).
Thanks for the help and discussion.
04/01/2016 at 17:27 in reply to: Simple 1 button GPIO on off switch: 1 switch, 2 wires, 10 lines of code #122165skizzParticipantI got mine to work with both shutting down and booting up the the Pi so kiwijam777’s code works.
How are you shorting the two pins spaceinvader? I have a momentary button that I will solder on today but I used this to test last night at least.
Hopefully you can get it going
03/31/2016 at 21:39 in reply to: Simple 1 button GPIO on off switch: 1 switch, 2 wires, 10 lines of code #122119skizzParticipantI didn’t have a proper jumper last night to short the two pins but I do now so I’ll test tonight and let you know spaceinvader.
03/31/2016 at 02:00 in reply to: Simple 1 button GPIO on off switch: 1 switch, 2 wires, 10 lines of code #122044skizzParticipantI’d like to confirm what spaceinvader is seeing.
My scripts are copies of kiwijam777’s
I’ve done sudo apt-get update and sudo apt-get install rpi.gpio
Output is still:
sh: echo: I/O error
Are we all using the RPi 2 B+ and the latest RetroPie (3.6)?
I can’t imagine earlier versions would cause issues in something basic as writing a script in nano.
Is it a privilege issue? Your previous code had mkdir scripts without sudo in front so I don’t know if that caused an issue (I’m not a Linux expert so forgive me if the questions seem dumb).
I’m still searching for the issue but I just wanted to let others know that it doesn’t work on my RPi 2 w/ RetroPie 3.6
On a side note: Where is rc.local? I’m just looking through the pi’s directories with FileZilla so is it under etc/initd/rc.local? Or somewhere else?
It seems
skizzParticipantShutdown should safely stop all CPU processes.
Here’s the Linux link for shutdown commands
http://www.computerhope.com/unix/ushutdow.htm
I think two buttons is the only way to do a safe shutdown and completely power off the controller.
I might also put on some external LEDs so I can see the state of the Pi (booting, shutting down, off, on ) because my case covers the on board LEDs. It makes it a bit easier to visual see what’s going on but that requires a little more experimenting and some more components to solder
skizzParticipantI found this thread awhile back concerning a shutdown script, so I’m going to apply the same principles here but adjust for a soft power disconnect (i.e low power mode).
Here’s the link but I copied the text below as well
http://forum.arcadecontrols.com/index.php?topic=147052.0
—————————————–
Here is how to safely shutdown your RetroPie system via a switch wired to the GPIO pins:
List of items you will need:
raspberry pi running retropie (mine is running v3)
switch
two wires with connectors to plug into the pin header, long enough to reach your switchstart by wiring up your switch. (this script uses GPIO17 to trigger the event, if you want to use a different pin, you will have to adjust the script.) connect the two wires from your switch to pin GPIO17 and a ground. You do not need to add any resistors.
connect to your raspberry pi via ssh. I used putty in windows. (there are many tutorials on this, basically install putty, enter retropie for the host name and click Open. log in with username pi, password raspberry)
you will first need to run the following commands to Install rpi.gpio (this is the part most of the other tutorials leave out)
sudo apt-get update
sudo apt-get -y install python-rpi.gpioonce that is done, we will create the script.
sudo nano /home/pi/shutdown.py
Highlight and copy the text below (stuff between the <><><><>). right-click in your puty window to paste the text.
<><><><><><>
import RPi.GPIO as GPIO
import time
import osGPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down = GPIO.PUD_UP)
while True:
print GPIO.input(17)
if(GPIO.input(17) == False):
os.system(“sudo shutdown -h now”)
break
time.sleep(1)<><><><><><>
do a Ctrl X, press Y and then press Enter to save it.
then we have to tell the script to run but making an entry in crontab
sudo crontab -e
scroll to the bottom and add this line at the end:
@reboot sudo python /home/pi/shutdown.py
do a Ctrl X, press Y and then press Enter to save it.
now, launch your script manually to make sure it runs, enter the following command
sudo python /home/pi/shutdown.py
it should launch the script without any errors…then simply press your switch and it should send the shutdown command to your pi. let it shutdown and then power off the unit. now turn it back on, it should boot up to emulation station like normal, and when you press your switch, it should shut down.
If you followed those instructions, you should be set. i’ll try to help, but i’m really new to this stuff…so i don’t know how much help i will be.
—————————–
Again, this isn’t exactly the way you want, but it describes the action of scripting a button interrupt. I’ll test soon and see what I get out of it
skizzParticipant> Other thread
I’m new here. What do you mean by ‘other thread’?
skizzParticipantI know this weeks old but I have the same questions.
The best idea I can think of is to write a python script that recognizes a GPIO interrupt from a momentary button that safely quits emulationstation, then quits other processes in the background, and lastly halts the CPU processes. The Halt command essentially puts the controller in low power mode and then the same script can recognize the opposite GPIO interrupt and wake the controller and boot emulationstation.
The Pi will always be on, but at least it would be drawing less power. Unless you’re looking for a full power off solution then the safest way is to use the Powerblock.
I will be trying this in the next couple weeks so hopefully I have more information but I don’t see why this wouldn’t work.
-
AuthorPosts