Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: Retropie SNES, GPIO reset switch how to.  (Read 26646 times)

0 Members and 1 Guest are viewing this topic.

severdhed

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2971
  • Last login:October 07, 2022, 04:45:32 pm
  • RIP Dinosaur Hippo
Retropie SNES, GPIO reset switch how to.
« on: August 27, 2015, 10:12:41 pm »
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
« Last Edit: November 09, 2017, 04:57:51 pm by severdhed »
Current Projects:      Zak-Man | TMNT Pedestal | SNES Pi | N64 Odroid
Former Projects:     4 Player Showcase | Donkey Kong | iCade

Slippyblade

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 3167
  • Last login:November 16, 2023, 11:39:51 am
  • And to the death god we say, "Not today!"
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #1 on: August 27, 2015, 11:00:16 pm »
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/
« Last Edit: August 27, 2015, 11:04:39 pm by Slippyblade »

severdhed

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2971
  • Last login:October 07, 2022, 04:45:32 pm
  • RIP Dinosaur Hippo
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #2 on: August 27, 2015, 11:14:44 pm »
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.

Current Projects:      Zak-Man | TMNT Pedestal | SNES Pi | N64 Odroid
Former Projects:     4 Player Showcase | Donkey Kong | iCade

Slippyblade

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 3167
  • Last login:November 16, 2023, 11:39:51 am
  • And to the death god we say, "Not today!"
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #3 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.

niftylifty

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 1
  • Last login:August 28, 2015, 03:53:17 pm
  • I want to build my own arcade controls!
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #4 on: August 28, 2015, 03:36:55 pm »
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.

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

Slippyblade

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 3167
  • Last login:November 16, 2023, 11:39:51 am
  • And to the death god we say, "Not today!"
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #5 on: August 28, 2015, 05:05:04 pm »
Welcome to the forum, Nifty.  Thanks for the good words on my build, I appreciate it.  Though, I seriously recommend looking at some of the other builds on here.  Mine is crap in comparison to some.


severdhed

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2971
  • Last login:October 07, 2022, 04:45:32 pm
  • RIP Dinosaur Hippo
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #6 on: August 28, 2015, 09:29:58 pm »
Thanks for the help so far guys, i didn't get to try this today, i was just too busy at work to get any time to mess with it.  here is my progress so far:

I started by gutting the dead snes in question.  It was severely discolored.  the top was very yellow, the bottom was yellow really bad on the front and right side.  I left the pieces sit in a mixture of hydrogen peroxide and oxy clean in a clear plastic container in the sun for about 3 days.  It did improve the color, but it didn't get rid of the yellowing completely. 






I'm most disapointed with the purple buttons.  When i got it, they were very dark and discolored.  by soaking them, they brightened up, but once they dried, they are cloudy and washed out looking.

here you can see the buttons, and the bottom side of the button, showing the original color.


here it is after soaking for 3 days.  perhaps if i had a stronger mixture of peroxide i could get it back to normal, but i couldn't find any locally.



it is hard to tell by that picture becuase the buttons are wet, but once they dried, they are splotchy and nasty looking.  i don't see any option but to paint this unit. 

i really like the original color of the purple buttons, and i found some rustoleum spray paint that bonds to plastic, that just happens to match almost perfectly.


i also got some Charcoal duplicolor vinyl dye to paint the main part of the console...i just like the darker color, more like the n64.  I'm not sure if I'm going to keep the eject button, or if im going to replace it with a piece of steel mesh painted a medium grey.



i'm hoping to get it painted this weekend. 

i did start working on the back panel for the connectors.  I don't want to put any extra holes in the case.  I removed the original back panel from the PCB and cut off the power jack.  I have an hdmi extension that fits pretty well into the original hole for the nintendo AV connector.   I made a spot for a USB extension in case i need to hook up a keyboard or something, and a USB type B jack that will be the power input, which will plug into a standard cell phone charger.  i just cut this jack off of a PCB from a non functional external hard drive enclosure.  the ground pin will connect to a cut off micro usb cable running to the raspberry pi, and the 5v pin will connect to the original snes power switch, and then to the micro cable.  This will allow me to cut power to the unit.  (I always shut down from the retropie menu before turning the power off...I just don't want to spend any extra money on this right now to get one of those mausberry things)

original panel after taking my pocket knife to it...the holes arent perfect, but they are close enough.


here it is with the connectors loosely fitted into place...once it is painted, they will be stuck in place with hot glue.


that's about all i have for now.
Current Projects:      Zak-Man | TMNT Pedestal | SNES Pi | N64 Odroid
Former Projects:     4 Player Showcase | Donkey Kong | iCade

Slippyblade

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 3167
  • Last login:November 16, 2023, 11:39:51 am
  • And to the death god we say, "Not today!"
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #7 on: August 29, 2015, 02:23:23 am »
Nice back panel!  I wanted to do something like that, but the parts I had just didn't allow it.

Locke141

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1690
  • Last login:February 03, 2024, 06:00:00 am
  • Never grow up.
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #8 on: August 29, 2015, 02:26:02 am »
I'm loving all the console emulators being built in the shells of dead classics consoles. I think this is like the 3rd recent one that uses a R-pi.

I was looking to do the same thing with a old dead SNES and read that you can get higher percentages peroxide from salons. I like the idea of painting as well, was thinking of using red with the switches in white like a Famicon.

severdhed

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2971
  • Last login:October 07, 2022, 04:45:32 pm
  • RIP Dinosaur Hippo
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #9 on: August 29, 2015, 09:18:58 pm »
I didn't get much done in the way of reset buttons and crap like that (there is always tomorrow) but the weather was nice and i had the time, so today i decided to paint the shell.  I was very nervous about this, because i know what things look like when i spray paint them...but i did it anyway. 

I didn't really want to paint the purple buttons, but they were just so crappy looking, i didn't have a choice.  I used some advice i found on another forum about taping down a piece of tape, sticky side up to hold small pieces in place when painting them...it worked very well. (better than the rolled up tape i used for the first coat.



Then i moved on to the main shell.  I started with a few of the smaller pieces, there is rolled up duct tape holding them in place.









 The lighting in these pictures (the sun) makes these look much lighter than they actually are.  This is where i was worried about the finish.   I have to say, that i couldn't be more impressed with the duplicolor vinyl and fabric color.  It is also called Vinyl dye because it soaks into the plastic instead of just building up on top....the results are spectacular.

Here are some pics of the assembled unit indoors..i couldn't be happier with it.







As you can see, i replaced the cartridge slot flap and eject buttons with a piece of steel mesh i cut from an old PC case.  I cut it out with tin snips and folded the edges to stiffen it, then painted it a medium gray.  The color very closely matches the original eject button color. 

The pictures just don't do it justice. the buttons are obviously painted, but the main shell looks like it came from the factory that color.  i can't believe how awesome that viny dye is. 

Now I just need to finish the internal wiring and then break out the hot glue gun and start putting it together.  i'm hoping to have it finished tomorrow.
Current Projects:      Zak-Man | TMNT Pedestal | SNES Pi | N64 Odroid
Former Projects:     4 Player Showcase | Donkey Kong | iCade

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #10 on: August 29, 2015, 11:36:20 pm »
Good work!

severdhed

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2971
  • Last login:October 07, 2022, 04:45:32 pm
  • RIP Dinosaur Hippo
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #11 on: August 29, 2015, 11:51:09 pm »
Good work!

thanks. 

I did manage to solder the original controller ports to the PCB of the mayflash usb adapter that I had.  I didn't get to test it yet with the raspberry pi since attaching the other ports, but both ports work just fine under windows, so it should be fine.



now i just have to:

1. Figure out how i'm mounting a switch for the reset switch.  i have a pretty good idea of the way i want to do it, but somehow this evening, i've misplaced the little spring the makes the reset switch return to its original position.  (i had it stuck to a powerful hard drive magnet with all the screws, but i'm pretty sure either my youngest son (almost 2) or one of my cats found it.

2. Locate my missing hot glue gun so I can mount the rear panel jacks and various other pieces.

3. look at that link that was posted earlier about setting up a script to exit the game when the reset switch is pressed. (this will probably be the last thing i do)

4. play some games with my kids.

i want to get this project finished, but at the same time, i'm having a lot of fun doing it...i'm sure that once it is done, it will probably just sit there on a shelf by my tv and never get played.  It is just way more fun building these things than it is playing them.

after i get this one done, i am going to finish up my n64 version. (assuming i can get the n64 emulation running well enough on the pi 2)

Current Projects:      Zak-Man | TMNT Pedestal | SNES Pi | N64 Odroid
Former Projects:     4 Player Showcase | Donkey Kong | iCade

Locke141

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1690
  • Last login:February 03, 2024, 06:00:00 am
  • Never grow up.
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #12 on: August 30, 2015, 12:20:36 pm »
That could not look any better. The case that is the buttons are ok.

I'm going to do one next summer
« Last Edit: August 30, 2015, 01:48:57 pm by Locke141 »

severdhed

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2971
  • Last login:October 07, 2022, 04:45:32 pm
  • RIP Dinosaur Hippo
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #13 on: August 30, 2015, 04:41:43 pm »
Thanks.

I've pretty much finished it up, now it is time to figure out the scripts. 

here you can see how i mounted my reset switch.  i used a regular arcade microswitch screwed into one of the original mounting posts in the shell. beceause of it's position, the switch is pressed by default, so I  wired up to the normally closed terminal.  when i slide the purple button, the switch is no longer depressed and the circuit is closed.  the kids and or cats lost my spring last night, so i had to improvise...i used one of my daughter's stretchy hair ties to replace the spring...it worked well..



here is my power circuit.  a USB type B jack that i cut from a dead external hard drive pcb.  the ground wire connects directly to the micro usb cable for the pi, the 5v runs through the original snes power switch.



here is an ethernet jack extension i made so i can plug into the lan if i need to.



i didn't have any room on the back panel for the ethernet jack, and i figured i wouldn't need it much once it is setup, so i mounted it (with hot glue) behind the little expansion door on the bottom. 



and here it is assembled...







here is it beside my non-modified original childhood snes.



« Last Edit: August 30, 2015, 04:44:29 pm by severdhed »
Current Projects:      Zak-Man | TMNT Pedestal | SNES Pi | N64 Odroid
Former Projects:     4 Player Showcase | Donkey Kong | iCade

pbj

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 10867
  • Last login:Yesterday at 11:09:19 pm
  • Obey.
    • The Chris Burke Band
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #14 on: August 30, 2015, 04:49:00 pm »
I'm watching how you solve the software issue with interest.  Retro Pie is a TERRIBLE front end. 

 :dizzy:

Slippyblade

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 3167
  • Last login:November 16, 2023, 11:39:51 am
  • And to the death god we say, "Not today!"
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #15 on: August 30, 2015, 04:55:05 pm »
Just curious PBJ, without going all ranty, what do you not like about RetroPie?  You say it is a terrible front end - are you referring to EmulationStation?  Or are you referring to RetroArch?

I'll admit, EmulationStation is not my front end of choice, I've developed a serious liking for AttractMode lately, but I don't think it's terrible by any means.

yotsuya

  • Trade Count: (+21)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 19955
  • Last login:March 17, 2024, 12:41:11 am
  • 2014 UCA Winner, 2014, 2015, 2016 ZapCon Winner
    • forum.arcadecontrols.com/index.php/topic,137636.msg1420628.html
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #16 on: August 30, 2015, 05:09:36 pm »
RetroPie looks like ass. EmuStation looks better, but too much like a HTC front end. 
***Build what you dig, bro. Build what you dig.***

Slippyblade

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 3167
  • Last login:November 16, 2023, 11:39:51 am
  • And to the death god we say, "Not today!"
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #17 on: August 30, 2015, 05:19:13 pm »
But...  I guess I'm missing something here.  The RetroPie distro uses EmulationStation as the front end.  If you are using RetroPie, unless you've gone in and manually changed it out, you are using EmulationStation.

Literally all RetroPie is is a prebuilt Raspbian with EmulationStation as the front end and RetroArch (LibRetro) as the emulation back end.

yotsuya

  • Trade Count: (+21)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 19955
  • Last login:March 17, 2024, 12:41:11 am
  • 2014 UCA Winner, 2014, 2015, 2016 ZapCon Winner
    • forum.arcadecontrols.com/index.php/topic,137636.msg1420628.html
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #18 on: August 30, 2015, 05:38:36 pm »
But...  I guess I'm missing something here.  The RetroPie distro uses EmulationStation as the front end.  If you are using RetroPie, unless you've gone in and manually changed it out, you are using EmulationStation.

Literally all RetroPie is is a prebuilt Raspbian with EmulationStation as the front end and RetroArch (LibRetro) as the emulation back end.

I'm confusing RetroPie with PiPlay. But still, RetroPie doesn't look very arcade-like.
***Build what you dig, bro. Build what you dig.***

Slippyblade

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 3167
  • Last login:November 16, 2023, 11:39:51 am
  • And to the death god we say, "Not today!"
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #19 on: August 30, 2015, 05:43:10 pm »
Oh, I agree.  I think you nailed it when you said it very media center-ish.

severdhed

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2971
  • Last login:October 07, 2022, 04:45:32 pm
  • RIP Dinosaur Hippo
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #20 on: August 30, 2015, 09:49:55 pm »
i don't mind the emulation station front end...i wish pressing left/right when in a specific emulator wouldn't change to the next one, and i wish the retropie config didn't show up as another system in the list, but other than that, it works fairly well.


So i looked the link about creating these scripts, but some of it is vague..can any of you help?

1st of all, it wants me to create two files: escape.sh and escape.py and add a line to something called cron.

how do I create these files and where do I put them? my original plan was just make them in notepad, then copy them over via smb share, but when i connect to the unit via smb, i only see the roms, bios, and configs filders.    I did manage to get connected to the unit via ssh using putty, but i just don't know what to do from there.

also, when it comes to wiring up the switch, how do I know how to wire it up?    upon inspection of that file, it seems to possibly reference pin 17.  according to a diagram i found it appears as if the 6th pin down on the left column is pin17, and the one right above it is a ground.  logically i would think you would just wire the switch to these two pins, but there is a diagram on that page with a picture of the pie with a large plastic thing with a bunch of holes, several wires, a switch and what i believe is a resisitor...is that crap all necessary?

i'm trying to find a better example, but so far i'm coming up short...if you can shine some light on this , i'd appreciate it.
Current Projects:      Zak-Man | TMNT Pedestal | SNES Pi | N64 Odroid
Former Projects:     4 Player Showcase | Donkey Kong | iCade

pbj

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 10867
  • Last login:Yesterday at 11:09:19 pm
  • Obey.
    • The Chris Burke Band
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #21 on: August 30, 2015, 10:10:29 pm »
Ok, I'm apparently referring to Emulation Station.  Obviously designed by an engineer of some sort.


Locke141

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1690
  • Last login:February 03, 2024, 06:00:00 am
  • Never grow up.
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #22 on: August 31, 2015, 05:03:44 am »
I think for a console emu station is fine but Atract mode is a much better looking FE and has more of an arcade feel.

What OS build  are you using? Raspbian or some cut down versions of it is most likely.

.sh refers to shell and .py refers to Python.

I'm far from a LINUX power user, but if you share the like's where you are getting the guides from I'll be happy to take a look and try to help.

This may help:
https://www.rascronpberrypi.org/documentation/linux/usage/cron.md

http://cagewebdev.com/index.php/raspberry-pi-excuting-shell-scripts/
« Last Edit: August 31, 2015, 05:38:12 am by Locke141 »

severdhed

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2971
  • Last login:October 07, 2022, 04:45:32 pm
  • RIP Dinosaur Hippo
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #23 on: August 31, 2015, 09:21:16 am »
ok...I'm not sure which OS build it is, i downloaded the retropie v3 sd card image.

i am following the post in this link...

https://www.reddit.com/r/raspberry_pi/comments/2yw4fn/finally_set_up_retropie_complete_with_a_gpio/

that slippyblade pointed me to in the second post of this thread.


about 3/4ths of the way down the page, there is a post by b4ux1t3 that lists the instructions.  it contains:

escape.py
from time import sleep
import os
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

def exitEmulator(channel):
    print('exitEmulator')
    pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]

    for pid in pids:
        try:
            commandpath = open(os.path.join('/proc', pid, 'cmdline'), 'rb').read()
            if commandpath[0:24] == '/opt/retropie/emulators/':
                os.system('kill -QUIT %s' % pid)
                print('kill -QUIT %s' % pid)
        except IOError:
            continue
GPIO.add_event_detect(17, GPIO.RISING, callback=exitEmulator, bouncetime=500)

while True:
    sleep(10)


escape.sh
#!/bin/sh

cd /
cd /home/pi
sudo python escape.py
cd /


Add this to cron (sudo crontab -e)
@reboot sh /home/pi/escape.sh



but there were no instructions on how to do this.  I eventually figured out how to create the files and here is what i did:

connected to pi via SSH using putty
cd /home
cd pi

nano escape.py

entered the contents listed in the link

saved it

nano escape.sh

entered the contents listed in the link

saved it

sudo crontab -e

entered the line listed in the link

saved it

rebooted

according to this GPIO pinout diagram, the 5th pin on the left column is a ground, and the 6th pin is GPIO17.  so i connected a standard arcade microswitch to these two pins. (i used pin 17, because from what I can tell, that is the pin referenced in the script, if I am understanding it correctly)

I then launch a game and press the reset button on the console, but nothing happens.

so, what am I doing wrong?  do i need to wire the switch up differently?  i looked around and i see various information, some people say you need a circuit with a pull up resistor (no idea what that is).

i created an account on the site where that was originally posted and sent the original poster a message last evening....perhaps they will be able to shed some light on it.  any help would be appreciated. 

it isn't a huge deal breaker, i can exit the games using the start+select buttons on the gamepad, but it feels stupid to have that switch there and not serve a purpose.

Current Projects:      Zak-Man | TMNT Pedestal | SNES Pi | N64 Odroid
Former Projects:     4 Player Showcase | Donkey Kong | iCade

Locke141

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1690
  • Last login:February 03, 2024, 06:00:00 am
  • Never grow up.
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #24 on: August 31, 2015, 01:41:53 pm »
Here's a clear explanation on how to make a pull up/down resister and an explanations on why you need one.

https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/buttons_and_switches/

Quote
When a GPIO pin is set as an input it is “floating” and has no defined voltage level. For us to be able to reliably detect whether the input is high or low we need to tie it so that it is always connected and either reads high or low.

To tie the pin we connect either a Pull Up or Pull Down resistor. A Pull down resistor connects the pin to ground through a large resistor, this means that when the switch is open there is a path to ground and so it will read low. When the switch is pressed (with the other side connected to 3.3V) there is a lower resistance path to high and so the pin will read high. The large (10kΩ) resistor ensures that only a little current is drawn when the switch is pressed.

Setting up a circuit like this means that we will be able to take reliable readings from a switch, however we could still damage the pins if they are accidentally set to an output. If we drive it low the output is connected directly to ground. Pushing the button will then create a short circuit between 3.3V and ground! To make this safer we put in a current limiting resistor (1kΩ will do) to make sure the Pi can handle the current drawn.
- https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/buttons_and_switches/

« Last Edit: August 31, 2015, 01:58:07 pm by Locke141 »

severdhed

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2971
  • Last login:October 07, 2022, 04:45:32 pm
  • RIP Dinosaur Hippo
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #25 on: August 31, 2015, 04:56:11 pm »
clear explanation...maybe to someone who does a ton of electronics work.   :dunno

here is how i have it wired now...it does not work:



i looked at that page, and they are using things like breadboards and breakout boards...things that I do not have and prefer not to spend money on.  i probably have some resistors lying around from years ago when doing some LED projects. 

i guess i just don't fully understand how to physically hook this up to the pi.

i found this diagram on that linked page,



If i understand this correctly, (which i probably dont) this looks as if the 3v line goes to the switch, and then it comes out from the other side of the switch and splits to pin 17 and to a resistor then to ground...is that correct?

Current Projects:      Zak-Man | TMNT Pedestal | SNES Pi | N64 Odroid
Former Projects:     4 Player Showcase | Donkey Kong | iCade

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #26 on: August 31, 2015, 05:12:36 pm »
Im not real sure what you are doing here, but yes, 3rd drawing is electrically the same as the second drawing.

The way you are using it, with the switch open, pin 17 will be pulled down to ground (also called sinking), through the resistor.
With the switch closed, pin 17 will be pulled up (also called sourcing) to positive.
So switch open, pin 17 low, switch closed pin 17 high.

EDIT: You dont need one of those perforated development (bread) boards, they are for testing circuits before building them.
You may want to get one to play and learn with, but you dont need it for this project.
« Last Edit: August 31, 2015, 05:16:48 pm by DaOld Man »

severdhed

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2971
  • Last login:October 07, 2022, 04:45:32 pm
  • RIP Dinosaur Hippo
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #27 on: August 31, 2015, 05:26:32 pm »
thank you

this whole project is so much more challenging than the arcade cabinets i've built because i just don't have much experience with linux or electronic circuits.  I'm very comfortable with an ipac and a windows pc, but weird command line linux scripting and electronic circuit building are just beyond the current scope of my understanding.   That's why i'm so thankful for this board.  You guys rock. 

i'm going to check to see if i can find some resistors when i get home and try to get this finished up. 
Current Projects:      Zak-Man | TMNT Pedestal | SNES Pi | N64 Odroid
Former Projects:     4 Player Showcase | Donkey Kong | iCade

severdhed

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2971
  • Last login:October 07, 2022, 04:45:32 pm
  • RIP Dinosaur Hippo
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #28 on: September 01, 2015, 05:11:27 pm »
Ok, so I wired it up like the 3rd pic in my last post, but nothing happens when I press the switch. Any suggestions?

Sent from my SM-G900V using Tapatalk

Current Projects:      Zak-Man | TMNT Pedestal | SNES Pi | N64 Odroid
Former Projects:     4 Player Showcase | Donkey Kong | iCade

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #29 on: September 01, 2015, 05:31:52 pm »
Ok, so I wired it up like the 3rd pic in my last post, but nothing happens when I press the switch. Any suggestions?

Sent from my SM-G900V using Tapatalk

Im new to the Pi too, but Im pretty sure you will have to load some script that does something when that pin goes high.
Did you check out the link that Slippy posted a few posts back?

severdhed

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2971
  • Last login:October 07, 2022, 04:45:32 pm
  • RIP Dinosaur Hippo
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #30 on: September 01, 2015, 10:14:45 pm »
ok...I'm not sure which OS build it is, i downloaded the retropie v3 sd card image.

i am following the post in this link...

https://www.reddit.com/r/raspberry_pi/comments/2yw4fn/finally_set_up_retropie_complete_with_a_gpio/

that slippyblade pointed me to in the second post of this thread.


about 3/4ths of the way down the page, there is a post by b4ux1t3 that lists the instructions.  it contains:

escape.py
from time import sleep
import os
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

def exitEmulator(channel):
    print('exitEmulator')
    pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]

    for pid in pids:
        try:
            commandpath = open(os.path.join('/proc', pid, 'cmdline'), 'rb').read()
            if commandpath[0:24] == '/opt/retropie/emulators/':
                os.system('kill -QUIT %s' % pid)
                print('kill -QUIT %s' % pid)
        except IOError:
            continue
GPIO.add_event_detect(17, GPIO.RISING, callback=exitEmulator, bouncetime=500)

while True:
    sleep(10)


escape.sh
#!/bin/sh

cd /
cd /home/pi
sudo python escape.py
cd /


Add this to cron (sudo crontab -e)
@reboot sh /home/pi/escape.sh



but there were no instructions on how to do this.  I eventually figured out how to create the files and here is what i did:

connected to pi via SSH using putty
cd /home
cd pi

nano escape.py

entered the contents listed in the link

saved it

nano escape.sh

entered the contents listed in the link

saved it

sudo crontab -e

entered the line listed in the link

saved it

rebooted

according to this GPIO pinout diagram, the 5th pin on the left column is a ground, and the 6th pin is GPIO17.  so i connected a standard arcade microswitch to these two pins. (i used pin 17, because from what I can tell, that is the pin referenced in the script, if I am understanding it correctly)

I then launch a game and press the reset button on the console, but nothing happens.

so, what am I doing wrong?  do i need to wire the switch up differently?  i looked around and i see various information, some people say you need a circuit with a pull up resistor (no idea what that is).

i created an account on the site where that was originally posted and sent the original poster a message last evening....perhaps they will be able to shed some light on it.  any help would be appreciated. 

it isn't a huge deal breaker, i can exit the games using the start+select buttons on the gamepad, but it feels stupid to have that switch there and not serve a purpose.



yes, i did create these scripts, but it is like they arent running or something
Current Projects:      Zak-Man | TMNT Pedestal | SNES Pi | N64 Odroid
Former Projects:     4 Player Showcase | Donkey Kong | iCade

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #31 on: September 01, 2015, 10:52:29 pm »
According to the script, it looks like the Pi has internal programmable pull up/pull down resistors.

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

Ive seen other processors that have this ability, didnt know if Pi did or not.
Try taking the  1k resistor to ground out of the circuit and see what happens. It could be keeping the input pulled low, not real sure, but its worth a try.

Im not real sure about what I just said. Someone with more experience with the Pi needs to chime in.
Maybe the script is saying the pin needs to go low, which would mean connect to ground.
You can try connecting the switch to pin 17 and ground, and the resistor in pull up mode connected to pin 17 and +
That would reverse what you currently have, switch open pin= 17 high, switch closed= pin 17 low

Looks like I might be right about the pull up/pull down.
Some research found this:

What’s all this about internal ones then?
In our button circuit, we used resistors to pull down the voltage. This was to demonstrate the idea.
But, in fact, the Raspberry Pi has built-in pull-up and pull-down resistors which can be enabled in software. This means we can eliminate our pull-down resistors for the button – as long as we enable the internal ones.
How do you do that? RPi.GPIO to the rescue.
You enable these internal pull-ups/pull-downs at the time of setting up the port for input or output, by adding an extra, optional, argument to the GPIO.setup() function call.
We’re using pull-down, so it’s pull_up_down=GPIO.PUD_DOWN. If you want/need pull-up you can change the PUD_DOWN for PUD_UP. (It depends on how you’ve wired your circuit.)
GPIO.setup(port_or_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

More I learn about this little computer, more I like it.

« Last Edit: September 02, 2015, 07:42:53 am by DaOld Man »

severdhed

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2971
  • Last login:October 07, 2022, 04:45:32 pm
  • RIP Dinosaur Hippo
Re: Retropie snes project, need help with exiting games with reset switch
« Reply #32 on: September 03, 2015, 04:07:25 pm »
I finally got this working!!!  The problem was with the scripting the entire time, and my basic lack of understanding of what was going on.  Since this wasn't working, i ended up re-evaluating what i wished to accomplish. Instead of having the reset switch exit the emulator like i originally had planned, i decided it would be better served to send a safe shutdown command instead.  that way i can still exit the games via the gamepad, but before i turn the power switch off, i simply press the reset switch and wait for it to shutdown gracefully.  to do that, i needed a different script, which i found. but even that wouldn't work.  things really started coming together when i tried running the script manually via the ssh terminal.  that is when i started seeing errors...specifically,after the line: import RPi.GPIO   i would get     ImportError: No module named GPIO


as it turns out, i needed to install this as a separate component.  once that was done, i ran the new shutdown script manually and got it to successfully shut down.  this script was quite basic, it sets pin 17 as pull up, which means i can wire a standard switch to pins 17 and ground, with no resistors, and it just works.    The big problem i had was getting the script to run, without messing up emulation station.  The original article told me to make an entry calling the script in the /etc/rc.local  file, which i did. the problem is, when i booted it up, i'd get the emulation station splash screen, then it would just go to a console window with a bunch of 1s repeating down the screen.  so i had to remove that entry.  on another forum, they suggested adding it in something called crontab....calling my python script directly there caused everything to work.  here is the script i used:



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)

I am going to edit the first post of this thread with accurate, step by step instructions on how i got this working, in case anyone else needs it down the road.

Thank you all for your help with this project.
Current Projects:      Zak-Man | TMNT Pedestal | SNES Pi | N64 Odroid
Former Projects:     4 Player Showcase | Donkey Kong | iCade

Slippyblade

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 3167
  • Last login:November 16, 2023, 11:39:51 am
  • And to the death god we say, "Not today!"
Re: Retropie SNES, GPIO reset switch how to.
« Reply #33 on: September 03, 2015, 05:32:44 pm »


DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Retropie SNES, GPIO reset switch how to.
« Reply #34 on: September 03, 2015, 07:34:49 pm »
I havent checked out Slippys link yet, so it might have already been answered, but I think the reason you were seeing the ones is because of the:

print GPIO.input(17)

in the script.
This prints the state of the pin to the screen, which since you are pulling it up, is 1.
Although handy for trouble shooting, this line should be deleted or commented out before regular use.

Good work severdhed, I am learning a lot from your work. I think if we can figure how to turn on and shutdown with the power switch we wont need to buy that mausberry switch circuit, but the mausberry does make it a lot easier, especially for beginners like me.

EDit: just watch the video Slippy linked. Did not shed light on the 1s being displayed, but did give me a warm fuzzy feeling. LOL
« Last Edit: September 03, 2015, 07:36:36 pm by DaOld Man »