Langoor
Posts: 9
Joined: Thu May 29, 2014 2:27 pm

[GPIO]Using gpio pins as input device

Thu May 29, 2014 2:32 pm

Hello there!
I dont know if this is the right forum.
Is it possible to use the GPIO pins as input (Like attach arcade buttons to the pi and use them as input in retropie?

Greetings, Langoor

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12594
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: [GPIO]Using gpio pins as input device

Thu May 29, 2014 3:05 pm

GPIO means "General purpose Input and Output", so yes, it can act as a digital input pin as well as a digital output pin.

Langoor
Posts: 9
Joined: Thu May 29, 2014 2:27 pm

Re: [GPIO]Using gpio pins as input device

Thu May 29, 2014 3:16 pm

do you have some tutorial?

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: [GPIO]Using gpio pins as input device

Thu May 29, 2014 3:55 pm

http://www.raspberrypi.org/learning/scr ... jellybaby/

You don't need the jelly baby or the scream - it is a just a fun demo of how to detect a switch being closed.
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

Langoor
Posts: 9
Joined: Thu May 29, 2014 2:27 pm

Re: [GPIO]Using gpio pins as input device

Thu May 29, 2014 4:10 pm

Thanks, but i am completly new to the gpio stuff, do you have some tips?

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: [GPIO]Using gpio pins as input device

Thu May 29, 2014 4:12 pm

I don't think it comes much easier than the link I have provided. Which part do you need tips about?
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

Langoor
Posts: 9
Joined: Thu May 29, 2014 2:27 pm

Re: [GPIO]Using gpio pins as input device

Thu May 29, 2014 4:15 pm

Like what i want:

I plug a switch on the Raspberry Pi GPIO (Wich ports?)(How many switches can i connect? I want to connect 9 switches if possible)
Then i want something like this: I press switch 1 and then the pi does W and if i press switch 2 the pi does A.
Something like that. With this way i want to emulate a controller, which i can use with retropie

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: [GPIO]Using gpio pins as input device

Thu May 29, 2014 4:18 pm

Instead of looking for a complete solution, why not try connecting one switch as an experiment, and then build on what you have learnt?

(I haven't used RetroPie - I have no idea whether it is possible to use an external controller for it - that is the other part of the problem... Again, you can experiment for free.)
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

Langoor
Posts: 9
Joined: Thu May 29, 2014 2:27 pm

Re: [GPIO]Using gpio pins as input device

Thu May 29, 2014 6:09 pm

@DaaJay,
Thanks for tutorial! my one button project succeeded! but how can i use more buttons? My current script is:
Image

suicidal_orange
Posts: 217
Joined: Sun Mar 16, 2014 10:56 am

Re: [GPIO]Using gpio pins as input device

Thu May 29, 2014 8:47 pm

You actually have two switches set up on pins 3 and 5 :)

The method you have chosen only checks for a button once a second though, and that's not going to be enough for a controller - you need to use interrupts. There is a three part tutorial starting here which has everything you need except a list of all the pins - see here. In addition to the green pins you can use GPIO 0 and 1 (the blue ones) for switches so that's your 9 switches covered.

Langoor
Posts: 9
Joined: Thu May 29, 2014 2:27 pm

Re: [GPIO]Using gpio pins as input device

Fri May 30, 2014 1:20 pm

Image
Hello there, this code gives me a Syntax error on second Try: command

suicidal_orange
Posts: 217
Joined: Sun Mar 16, 2014 10:56 am

Re: [GPIO]Using gpio pins as input device

Fri May 30, 2014 8:21 pm

Looks like you've only read part one of the tutorial, the fun stuff (multiple buttons) happens in parts 2 and 3 :)

Return to “Advanced users”