0

I have this gamepad PCB from Adafruit: https://www.adafruit.com/products/3015

In their guide it's supposed to work with the file they give you but that image only works on raspberry pi 2 and I'm using a raspberry pi 3 so I can't use that image on my sd card. How do I figure out which GPIO pins the buttons are on? and then set those up to work on my raspberry pi 3?

UPDATE: Here's the image of the Adafruit PiGRRL Gamepad PCB @MohammadAli added in the comments to help

Adafruit Gamepad PCB

20

1 Answer 1

2
  1. We start our adventure by installing an os onto our pi, this will require a minimum 4gb micro sd card. Click the download link that says "Raspberry Pi 2/3" Now after the image has downloaded, burn it to an sd card. If you do not know how, please google it their are a lot of tutorials on it and seeing that you were able to burn an img file before I'm not going to go over it.
  2. connect your raspberry pi to an HDMI or composite display and plug in a usb keyboard and mouse. Be sure to disconnect everything from your gpio pins before booting as the pi is only capable of driving a single display.
  3. boot the pi
  4. On first boot the system will ask you to configure an input device. it really doesn't matter which keys you use here as long as you remember them.

  5. press f4 on your keyboard to exit Emulationstation and to enter the command line.

  6. Now we will preform some basic system optimization/configuration. Enter sudo rasps-configinto your terminal then press enter.
  7. in the prompt use your keyboard arrow keys to go to Advanced options then press enter.
  8. Inside Advanced options Set the following:
    1. Enable SPI(Serial Peripheral Interface) 2.Disable Overscan(because your tft display does not have an overscan)
    2. Enable Device Tree 4.Force 3.5mm headphone jack for audio(because hdmi will be disconnected when you are using your tft display)
  9. Reboot your pi using sudo shutdown to shutdown completely. Only remove the power after all green led activity has ceased.
  10. First we’ll install fbcp (a live framebuffer mirroring tool) using directions from HERE

    sudo apt-get install cmake
    git clone https://github.com/tasanakorn/rpi-fbcp
    cd rpi-fbcp/
    mkdir build
    cd build/
    cmake ..
    make
    sudo install fbcp /usr/local/bin/fbcp
    

    (You do not need to actually use the link or read any of it because all of the install code is above)

  11. Now we will edit the boot file to allow fbcp to launch on boot the boot file is located at /etc/rc.local you may edit it by using sudo nano /etc/rc.local Before the last line that says exit 0 you want to insert the following /usr/local/bin/fbcp & which will launch fbcp on boot. Now save the changes and exit by using the keyboard shortcut control x

  12. Now edit the file /boot/config.txt and add the following 4 lines.

    hdmi_force_hotplug=1 #Pretends HDMI hotplug signal is asserted so it appears a HDMI display is attached
    hdmi_group=1 #defines the HDMI type as DMT
    hdmi_mode=87 #defines screen resolution in CEA or DMT format 87 being custom
    hdmi_cvt=320 240 60 1 0 0 0 # sets the following in the following order: hdmi_cvt=<width> <height> <framerate> <aspect> <margins> <interlace> <rb>
    
  13. with the file still open you will need to add one of the following lines to the end of the file depending on wether your display touchscreen is resistive or capacitive.

    For capacitative touchscreen use:

    dtoverlay=pitft28-capacitive-overlay,rotate=90,speed=80000000,fps=60
    

    For resistive touch screens use:

    dtoverlay=pitft28-resistive-overlay,rotate=90,speed=80000000,fps=60
    

    For tft displays that do not support touch either line will work.

    Note: that dtoverlay is a Device Tree function that is used to enable the SPI driver.

  14. Now when you save and reboot HDMI will probably not work on all monitors, and it is recommended that you disconnect the HDMI display before attempting to use the tft one.

  15. If you don’t already have the PiTFT assembled and connected, do that now.
  16. Now only one more piece of software called retrogame lets you connect buttons directly to the Raspberry Pi’s GPIO header and simulates key presses. It can be downloaded from the command line using:

    git clone https://github.com/adafruit/Adafruit-Retrogame
    
  17. Enter the directory by using the following command:

    cd Adafruit-Retrogame
    
  18. Edit the file retrogame.c by using the command below:

    sudo nano retrogame.c
    
  19. A full list of available key codes can be found at /usr/include/linux/input.h

  20. look for the table called ioStandard i know that it says for HDMI only, but because we are using that fbcp software that we installed before. The pi actually thinks that it is outputting over HDMI in an attempt to trick it into using gpu based hardware acceleration. Your IoStandard table should look like the one below:

Note: depending on your display, modifying the IOTFT table may be the right thing to do.(advised by @jimmyplaysdrums) just try both and see what works for you.

    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) 
    { 4,  KEY_LEFT     }, // Joystick (4 pins) 
    { 19, KEY_RIGHT    }, 
    { 16, KEY_UP       }, 
    { 26, KEY_DOWN     }, 
    { 14, KEY_LEFTCTRL }, // A/Fire/jump/primary/RED
    { 15, KEY_LEFTALT  }, // B/Bomb/secondary/YELLOW 
    { 20, KEY_Z        }, // X/BLUE 
    { 18, KEY_X        }, // Y/GREEN 
    {  5, KEY_SPACE    }, // Select 
    {  6, KEY_ENTER    }, // Start 
    { 12, KEY_A        }, // L Shoulder 
    { 13, KEY_S        }, // R Shoulder 
    { 17, KEY_ESC      }, // Exit ROM PiTFT Button 1
    { 22, KEY_1        }, // PiTFT Button 2
    { 23, KEY_2        }, // PiTFT Button 3
    { 27, KEY_3        }, // PiTFT Button 4
  1. After editing, compile and run the code with:

    make retrogame
    sudo mv retrogame /usr/local/bin
    
  2. To make retrogame start on boot as we did before open the /etc/rc.local file using the command below.

    sudo nano /etc/rc.local
    
  3. now before the final exit 0 line insert the line below, then save and exit.

    /usr/local/bin/retrogame &
    
  4. Now only one more step until your on your way, its so that Emulationstsation recognizes retrogame as a keyboard. All you need to do is open the file /etc/udev/rules.d/10-retrogame.rules using the command

    sudo nano /etc/udev/rules.d/10-retrogame.rules
    
  5. Then copy and paste the line below into the new file:

    SUBSYSTEM=="input", ATTRS{name}=="retrogame", ENV{ID_INPUT_KEYBOARD}="1"
    

    Then save and close this file then reboot.

  6. Enjoy! and be sure to post any problems you receive in the comments and I will try and debug with you.

5
  • Ok. Good news and bad news. First, the pin/key table didn't work in the ioStandard section but when I added it to the ioTFT section the buttons started to work! (this is with the TFT screen attached and no HDMI screen attached btw). Second, all the buttons seem to work except for the UP on the D-pad and the Y button. It could be a hardware issue since I double checked the correct pins are chosen in the table (16 and 18). I'll keep you updated after I take it apart again. Commented May 4, 2016 at 18:51
  • Ohh, ok cool I'll make that an edit, right now. Commented May 4, 2016 at 18:52
  • Not a problem man, always glad to help! Commented May 4, 2016 at 18:54
  • It's most likely a hardware issue, be sure to check the cables too, for any bent or missing pins Commented May 4, 2016 at 19:48
  • Also make sure that you've installed the buttons in the correct orientation, I've seen way too many people solder the wrong two pins and end up with a button that's always on or always off. Commented May 4, 2016 at 20:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.