Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #117424
    josephchrzempiec
    Participant

    Hello I’m in need of some help I’m not really a Linux guy and i been having a great time Running Retropie. But i need some help I’m trying to add a Shutdown Button for my Pi. It is a A+ board. In Retropie menu If hit the enter brings up a whole popup menu and in there will be a way to shut down the Retropie or the pi it’s self. I’m trying to do the same way but with a Push Button Can someone please help me out?

    Joseph

    #120780
    skizz
    Participant

    I 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.

    #120804
    zigurana
    Participant
    #120807
    josephchrzempiec
    Participant

    Hello SKizz. What I’m doing now is that I’m making a Soft Power to disconnect the Power from the Pi. But before that happens I need to safely shutdown the Pi meaning to Halt the process i guess to end all task as you say to make everything safe to disconnect the Power from the Pi without hurting it. So in this case there will be a Push button on a GPIO pin to do this. But from what you are saying what would be the best way of doing this?

    #120810
    skizz
    Participant

    I 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 switch

    start 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.gpio

    once 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 os

    GPIO.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

    #120819
    josephchrzempiec
    Participant

    Hello Skizz Thank you so much I’m also new to all this. I love the retropie i play all my old games i haven’t played in years and miss this give me a chance to do it all in one system So i love it. I will try this and see what happens. The shutdown it’s self only shuts down the Processor correct? Not the Power down completely the board right? So then i will need to remove power from the board which is okay i can do that easy with another switch on power. So one for shut down and one for main power. then in order to bring it back up. I just need to reapply power to the main power switch by turning it back on.

    #120822
    skizz
    Participant

    Shutdown 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

    #120843
    josephchrzempiec
    Participant

    Hello SKizz i will try this out over the weekend. I became sick a little some kind of flu like bug going around here most of my family is sick. But the good thing is i gave it to my wife LOL. And thank you for the information.

    Joseph

Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘GPIO Adapter, ControlBlock etc.’ is closed to new topics and replies.