Page 1 of 1

[GPIO]Using gpio pins as input device

Posted: Thu May 29, 2014 2:32 pm
by Langoor
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

Re: [GPIO]Using gpio pins as input device

Posted: Thu May 29, 2014 3:05 pm
by mahjongg
GPIO means "General purpose Input and Output", so yes, it can act as a digital input pin as well as a digital output pin.

Re: [GPIO]Using gpio pins as input device

Posted: Thu May 29, 2014 3:16 pm
by Langoor
do you have some tutorial?

Re: [GPIO]Using gpio pins as input device

Posted: Thu May 29, 2014 3:55 pm
by DeeJay
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.

Re: [GPIO]Using gpio pins as input device

Posted: Thu May 29, 2014 4:10 pm
by Langoor
Thanks, but i am completly new to the gpio stuff, do you have some tips?

Re: [GPIO]Using gpio pins as input device

Posted: Thu May 29, 2014 4:12 pm
by DeeJay
I don't think it comes much easier than the link I have provided. Which part do you need tips about?

Re: [GPIO]Using gpio pins as input device

Posted: Thu May 29, 2014 4:15 pm
by Langoor
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

Re: [GPIO]Using gpio pins as input device

Posted: Thu May 29, 2014 4:18 pm
by DeeJay
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.)

Re: [GPIO]Using gpio pins as input device

Posted: Thu May 29, 2014 6:09 pm
by Langoor
@DaaJay,
Thanks for tutorial! my one button project succeeded! but how can i use more buttons? My current script is:
Image

Re: [GPIO]Using gpio pins as input device

Posted: Thu May 29, 2014 8:47 pm
by suicidal_orange
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.

Re: [GPIO]Using gpio pins as input device

Posted: Fri May 30, 2014 1:20 pm
by Langoor
Image
Hello there, this code gives me a Syntax error on second Try: command

Re: [GPIO]Using gpio pins as input device

Posted: Fri May 30, 2014 8:21 pm
by suicidal_orange
Looks like you've only read part one of the tutorial, the fun stuff (multiple buttons) happens in parts 2 and 3 :)