Main > Raspberry Pi & Dev Board

Retropie SNES, GPIO reset switch how to.

(1/7) > >>

severdhed:
This post has been edited to include the instructions on how i got it working, the rest of the original thread continues below:

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


Below is the original threat content.



I have a raspberry pi model b setup with retropie v3.   It is currently mounted in a modified linksys wap shell.  I recently acquired a dead SNES and i am in the process of transplanting everything to the snes shell.  I already have the retropie system up and running, using a mayflash dual snes to usb adapter..everything works well, and i can exit the games using the start+select buttons on the controller.  I already have the power switch wired up to cut power to the unit (i always shut it off from the retropie menu before killing power)  but i don't know how to deal with the reset switch.  i was thinking it would be nice to be able to use the reset switch on the console to exit the game and go back to the menu.  i figured this would be relatively easy to accomplish by simply connected a microswitch to the gpio header on the raspberry pi, but i have no idea how to set this up to actually do what i want. 


I've been an IT guy for 15 years, i know my way around the hardware and I know windows inside and out, but linux is something i just haven't spent much time with.   I am fully capable of following instructions to run commands and crap like that, but i just don't know how to do this.   I guess i would need it to send a keystroke or something when the switch is pressed....is this easy to accomplish? I've looked around but can't seem to find anyone who has done this.  i'd like to keep it so that I can still exit the game with the gamepad, but also with the reset switch.  if this can't be done, then i don't know what to do with the reset switch.....please help

I'm going to start posting pics tomorrow...

I also have an n64 shell setup and ready to go once i pick up a raspberry pi 2....i'll need to do the reset switch on this one as well, but that will be another project

Slippyblade:
If you were gonna use it as a normal reset switch, you'd need to solder on a 2 pin header to the board; there's a spot for it on all the boards except the Rev 1 versions.

To do what you are wanting is easy enough, but you'll need a script.  I'm not knowledgeable enough to write the script though, sorry.  I've seen a couple projects where it was done this way so I know it can be done.  I'll dig a little deeper and see if I can find something for ya.

[update]
Found this thread.  About 3/4 way down is a set of instructions and scripts for doing what you need.
https://www.reddit.com/r/raspberry_pi/comments/2yw4fn/finally_set_up_retropie_complete_with_a_gpio/

severdhed:
thanks, i'll give that a shot tomorrow and see if i can get it working.  I thought about making it a reset button, but i don't know if that is something i'd really use.  I've also considered mounting a switch under the eject button to make that exit the emulator. 

Now, if i create these scripts, will they interfere with the ability to exit a game via the gamepad?  i'd like to have both options.

Slippyblade:
Wiring a switch to the eject is what I'm planning on doing with mine.  I've got my power and reset switch wired into a Mausberry power circuit already.

niftylifty:

--- Quote from: Slippyblade on August 28, 2015, 12:00:07 am ---Wiring a switch to the eject is what I'm planning on doing with mine.  I've got my power and reset switch wired into a Mausberry power circuit already.

--- End quote ---

Hey guys, just signed up! I'm very new to all of this but have a Pi2 set up running retropie v3 and very happy. I've picked up an old SNES (PAL version) and plan on gutting it and installing my Pi. I plan on using a Mausberry circuit for power/reset and have one on order.

Please could you tell me how to go about wiring my switches?, I've not soldered in years and have little experience but I'm excited to try  :) Is there any advice you can give? or things to watch out for when building my SNES project?

Oh, also I just wanted to say that Slippyblade your Bartop Neo-Geo is an inspiration and would love to move up to bigger project like those in the future, but first my SNES!!  ;D

Navigation

[0] Message Index

[#] Next page

Go to full version