As a difference to the first project I wanted to use the GPIO ports for connecting the control panel items using a little program the guys at adafruit are providing. See https://learn.adafruit.com/retro-gaming-with-raspberry-pi/buttons for the instructions.
I already connected the ports and did some testing with buttons and "daisy chained" Ground and it works well. Lets see it it works perfectly as well when things come in action !!
Here my HowTo in terms of the wiring approach:
Needed:
- some Unix skills (editor, navigating - nothing complex)
- Read the instructions on https://learn.adafruit.com/retro-gaming-with-raspberry-pi/buttons.
- download the SW package from adafruit mentioned in the instructions to your raspberry.
- obtain female jumper cables to connect to the GPIO ports
As shown in the picture above, I have build a connector bench in order to connect all the cables to the GPIO in-directly. I also wrote the actual GPIO number on the wood so that I know during wiring which one I am connecting a button to.
Next step is to note down the mappings you want for the GPIO ports. In my case this looks like this:
|
GPIO
|
Assigned
|
Button/CPO
|
|
2
|
Left
|
Left
|
|
3
|
Right
|
Right
|
|
4
|
Up
|
Up
|
|
17
|
Down
|
Down
|
|
18
|
1
|
Player One
|
|
27
|
2
|
Player Two
|
|
22
|
C
|
Coin
|
|
23
|
P
|
Pause
|
|
24
|
L
|
Left Flipper
|
|
10
|
R
|
Right Flipper
|
|
9
|
A
|
Button 1 (Fire)
|
|
25
|
B
|
Button 2 (Jump)
|
|
11
|
D
|
Button 3
|
|
8
|
E
|
Button 4
|
|
7
|
F
|
Button 5
|
How to read this table: "when moving the joystick to the left, a "LEFT" Keystroke will be send to the Raspberry. This action is bound to GPIO port "2".
Another example: When pressing the "Coin Button", a "C" Keystroke will be actioned and this is bound to GPIO Port/cable 22.
Now we make the necessary little changes to the c-program obtained from adafruit (please refer to the instructions coming with the package for exact steps).
To make the mapping of my wanted settings above working, edit the retrogame.c program and replace the lines in ioStandard section (do not touch the settings in ioTFT section) with
ioStandard[] = {
// This pin/key table is used when the PiTFT isn't found
// (using HDMI or composite instead), as with our original
// retro gaming guide.
// Input Output (from /usr/include/linux/input.h)
{ 2, KEY_LEFT }, // Joystick (4 pins)
{ 3, KEY_RIGHT },
{ 4, KEY_UP },
{ 17, KEY_DOWN },
{ 18, KEY_1 }, // Start 1P
{ 27, KEY_2 }, // Start 2P
{ 22, KEY_C }, // Coin
{ 23, KEY_P }, // Pause
{ 24, KEY_L }, // Left Flipper
{ 10, KEY_R }, // Right Flipper
{ 9, KEY_A }, // Button 1 (Fire)
{ 25, KEY_B }, // Button 2 (Jump)
{ 11, KEY_D }, // Button 3
{ 8, KEY_E }, // Button 4
{ 7, KEY_F }, // Button 5
{ -1, -1 } }; // END OF LIST, DO NOT CHANGE
Now, compile the program with the command "make retrogame" and make sure you followed the instrutions from adafruit to have the program being started in background on raspberry boot sequence.
When this is done, shutdown and connect just one button including the GND cable to the GPIO (any of the GND GPIO Ports is fine). Connect as shown here - GND to the lower connector, action to the connector next to GND.
After boot open a Terminal window and press the button you connected. It should now display the associated Letter on your screen just as if you pressed the letter on your keyboard. For example, it would display a "c" letter every time you Press the Coin button.
When this worked out, you can do the real wiring, daisy chain all the GND's and connect to one GPIO GND port and connect all action buttons/Joystick to associated Pins.
That's it.
