# USB Game Controller with SNES-like Layout

## Overview

![USB Game Controller with SNES-like Layout](https://cdn-learn.adafruit.com/assets/assets/000/136/250/medium800/circuitpython_controller.jpg?1744302072 )

This is a generic USB game controller which provides a two-handed gaming experience for retro gaming, or really any game you want to use a handheld rather than keyboard controller! Use it with your Raspberry Pi or desktop computer while playing emulated games, or as a controller to your CNC machine. It appears as a gamepad device (not a keyboard or mouse) which most games recognize.

The controller functions include a D-Pad, 2 Shoulder buttons, 2 Menu (Select / Start) and 4 Action (Classic X,Y,A,B) Buttons. It's powered through a USB-A Type connector.

This guide will demonstrate how to use CircuitPython and Arduino to read data from the controller and determine when buttons have been pressed.&nbsp;

## Parts
### USB Game Controller with SNES-like Layout

[USB Game Controller with SNES-like Layout](https://www.adafruit.com/product/6285)
This is a generic USB&nbsp;game controller, which plugs into to provide a two-handed gaming experience for retro gaming, or really any game you want to use a handheld rather than keyboard controller! Use it with your Raspberry Pi or desktop computer while playing emulated games, or as a...

In Stock
[Buy Now](https://www.adafruit.com/product/6285)
[Related Guides to the Product](https://learn.adafruit.com/products/6285/guides)
![Angled shot of SNES game controller with USB-A cable.](https://cdn-shop.adafruit.com/640x480/6285-00.jpg)

### Adafruit Fruit Jam - Mini RP2350 Computer

[Adafruit Fruit Jam - Mini RP2350 Computer](https://www.adafruit.com/product/6200)
We were catching up on a recent [hackaday hackchat with eben upton](https://hackaday.io/event/202122-raspberry-pi-hack-chat-with-eben-upton)&nbsp;and learned some fun facts: such as the DVI hack for the RP2040 was inspired by <a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/6200)
[Related Guides to the Product](https://learn.adafruit.com/products/6200/guides)
![Angled shot of assembled mini computer PCB with plate.](https://cdn-shop.adafruit.com/640x480/6200-10.jpg)

### Adafruit Metro RP2350

[Adafruit Metro RP2350](https://www.adafruit.com/product/6003)
Choo! Choo! This is the RP2350 Metro Line, making all station stops at "Dual Cortex M33 mountain", "528K RAM round-about" and "16 Megabytes of Flash town". This train is piled high with hardware that complements the Raspberry Pi RP2350 chip to make it an excellent...

In Stock
[Buy Now](https://www.adafruit.com/product/6003)
[Related Guides to the Product](https://learn.adafruit.com/products/6003/guides)
![Angled shot of black, credit card-sized microcontroller with stacking headers.](https://cdn-shop.adafruit.com/640x480/6003-06.jpg)

### Adafruit Feather RP2040 with USB Type A Host

[Adafruit Feather RP2040 with USB Type A Host](https://www.adafruit.com/product/5723)
You're probably really used to microcontroller boards with USB, but what about a dev board with two? Two is more than one, so that makes it twice as good! And the&nbsp; **Adafruit Feather RP2040 with USB Host** is **&nbsp;** definitely double-the-fun of our other Feather...

In Stock
[Buy Now](https://www.adafruit.com/product/5723)
[Related Guides to the Product](https://learn.adafruit.com/products/5723/guides)
![Angled shot of black rectangular microcontroller with USB C and USB A connectors at both ends.](https://cdn-shop.adafruit.com/640x480/5723-00.jpg)

### Adafruit CH334F Mini 2-Port USB Hub Breakout

[Adafruit CH334F Mini 2-Port USB Hub Breakout](https://www.adafruit.com/product/5999)
Sometimes, you've got something with a USB host, like an embedded Linux board, and you want to connect more than one thing. Or maybe you want to turn something like a keyboard into a multi-device USB peripheral. The&nbsp; **Adafruit CH334F Mini 2-Port USB Hub...**

In Stock
[Buy Now](https://www.adafruit.com/product/5999)
[Related Guides to the Product](https://learn.adafruit.com/products/5999/guides)
![Angled shot of black, square-shaped USB breakout board.](https://cdn-shop.adafruit.com/640x480/5999-04.jpg)

### USB Type A Jack Breakout Cable with Premium Female Jumpers

[USB Type A Jack Breakout Cable with Premium Female Jumpers](https://www.adafruit.com/product/4449)
If you'd like to connect a USB-host-capable chip to your USB peripheral, this cable will make the task very simple.&nbsp; **There is no converter chip in this cable!** &nbsp;It's basically a plain USB cable that's cut in half and with jumper sockets on the power and data...

In Stock
[Buy Now](https://www.adafruit.com/product/4449)
[Related Guides to the Product](https://learn.adafruit.com/products/4449/guides)
![USB Type A Socket Breakout Cable with Premium Female Jumpers](https://cdn-shop.adafruit.com/640x480/4449-02.jpg)

### USB Type A to Type C Cable - approx 1 meter / 3 ft long

[USB Type A to Type C Cable - approx 1 meter / 3 ft long](https://www.adafruit.com/product/4474)
As technology changes and adapts, so does Adafruit. This&nbsp;&nbsp; **USB Type A to Type C** cable will help you with the transition to USB C, even if you're still totin' around a USB Type A hub, computer or laptop.

USB C is the latest industry-standard connector for...

In Stock
[Buy Now](https://www.adafruit.com/product/4474)
[Related Guides to the Product](https://learn.adafruit.com/products/4474/guides)
![Angled shot of a coiled black, USB-C to USB-A cable.](https://cdn-shop.adafruit.com/640x480/4474-02.jpg)

# USB Game Controller with SNES-like Layout

## CircuitPython

The Feather RP2040 USB Host and Metro RP2350 devices both support USB Host and can be used with this game controller.&nbsp;

### Feather RP2040 USB Host Wiring

Connecting to the Feather RP2040 USB Host requires plugging in the USB game controller to the Feather's Host port.

![Adafruit Feather RP2040 USB Host with SNES-like USB game controller plugged in to the Host port.](https://cdn-learn.adafruit.com/assets/assets/000/139/672/medium640/gaming_feather_rp2040_snes_direct.png?1757705918)

### Metro RP2350 USB Host Wiring

Connecting to the Metro RP2350 USB Host port requires soldering pins to the broken out USB Host connections as shown in&nbsp;[this guide page](https://learn.adafruit.com/create-a-memory-game-on-metro-rp2350/preparing-the-metro-rp2350). Make the following connections between the Metro USB Host pins and USB Host breakout cable.

- **GND** to **Black** wire
- **D+** to **Green** wire
- **D-** to&nbsp; **White** wire
- **5V** to **Red** red

Then connect the USB Game Controller to the USB Host port on the breakout cable.

![Adafruit Metro RP2350 with USB Host breakout cable connected to the USB Host pins and a SNES-like USB game controller connected to the Host port.](https://cdn-learn.adafruit.com/assets/assets/000/139/674/medium640/gaming_metro_rp2350_snes_direct.png?1757707227)

### Fruit Jam Mini Computer

Connecting to the Fruit Jam requires plugging in the USB game controller to one of the Fruit Jam's USB Host ports.

![Adafruit Fruit Jam with SNES-like USB game controller plugged in to one of the USB Host ports.](https://cdn-learn.adafruit.com/assets/assets/000/139/673/medium640/gaming_fruit_jam_snes_direct.png?1757706051)

Warning: As of CircuitPython version 10.0.0-beta.3, the wired USB keyboard works on CircuitPython when connected directly to the USB Host pins or port. Prior releases of CircuitPython required connecting through a USB hub such as the CH334F.

## Demo Code

Connect the USB game controller while the microcontroller is unplugged from power. Only power up the microcontroller once the USB host connections are made securely.

Press the 'Download Project Bundle' button below to download a zip file containing the demo code. Connect your computer to your Feather or Metro via a known good data+power USB cable. Copy&nbsp; **code.py** and the required libraries to the **CIRCUITPY** drive on your device which appears when the board is connected to your computer via good USB cable.&nbsp;

The code will scan for connected USB devices, printing out information about each one it finds.&nbsp;

Then it will start a loop reading from the first device it found and printing messages when each of the gamepad buttons are pressed. Check the serial console to see the output.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/USB_SNES_Gamepad/CircuitPython_USB_Host/code.py

![Serial console output of the code.py script showing the USB device information and button pressed messages.](https://cdn-learn.adafruit.com/assets/assets/000/136/253/medium800/circuitpython_output.png?1744304869 )

## The Controller is Not Acting Right

The program presented works for the [generic SNES controller sold by Adafruit](https://www.adafruit.com/product/6285). Controllers from other sources may have key mappings a bit different from the Adafruit controller. This will help you adjust the code to your controller.

Near the top of the program are the following constants:

```auto
BTN_DPAD_UPDOWN_INDEX = 1
BTN_DPAD_RIGHTLEFT_INDEX = 0
BTN_ABXY_INDEX = 5
BTN_OTHER_INDEX = 6
```

These are the values obtained with the Adafruit controller. You can change the numbers to the ones output by your controller. For example a customer stated they changed&nbsp;`BTN_DPAD_UPDOWN_INDEX` to `4` from `1` and `BTN_DPAD_RIGHTLEFT_INDEX` to `3` from `0`.

How do you find the right numbers?

1. Trial and error based on the output of the program (shown above)
2. You can use a HID key mapper website. [https://joypad.ai/](https://joypad.ai/) is one such site (not tried).

If you are positive you bought your controller from Adafruit and it's not mapped right, you can post to the [Adafruit forums](https://forums.adafruit.com/) for assistance.

# USB Game Controller with SNES-like Layout

## Arduino

The Feather RP2040 USB Host and Metro RP2350 devices both support USB Host and can be used with this game controller.&nbsp;

### Wiring Feather RP2040 USB Host

Connecting to the Feather RP2040 USB Host requires plugging in a USB C cable to the Feather's Host port and connecting the other end to a USB Hub breakout such as the [CH334F](https://www.adafruit.com/product/5999).

![Feather RP2040 USB Host connected to CH334F USB Hub with USB SNES-like game pad connected to the hub.](https://cdn-learn.adafruit.com/assets/assets/000/136/284/medium640/circuitpython_feather_rp2040_ch334f_hub.png?1744738583)

![Feather RP2040 USB Host connected to CH334F USB Hub with USB SNES-like game pad connected to the hub.](https://cdn-learn.adafruit.com/assets/assets/000/136/285/medium640/circuitpython_feather_rp2040_ch334f_hub_closer.png?1744738607)

### Wiring Metro RP2350

Connecting to the Metro RP2350 USB Host port requires soldering pins to the broken out USB Host connections as shown in [this guide page](https://learn.adafruit.com/create-a-memory-game-on-metro-rp2350/preparing-the-metro-rp2350). Make the following connections between the Metro USB Host pins and CH334F host connection opposite the USB C connector.

- **GND** to **GND** with&nbsp; **Black** or **Blue**
- **D+** to **D+** with **Green**
- **D-** to **D-** with **White**
- **5V** to **5V** with **Red**

Note that the data pins are swapped on the Metro compared to the CH334F breakout. On the Metro **D-** is next to **5V** , whereas on the CH334F **D-** is next to **GND**.

Be sure to connect&nbsp; **D-** on the breakout to **D-** on the Metro, and **D+** on the breakout to **D+** on the Metro.

![Wiring diagram showing USB Host pins on Metro RP2350 connected to their counterparts on the CH334F USB Hub breakout and the SNES-like USB controller connected to the hub.](https://cdn-learn.adafruit.com/assets/assets/000/136/410/medium640/gaming_metro_rp2350_wiring.png?1745242392)

![Metro RP2350 with CH334F USB Hub breakout connected. A USB SNES-like game controller is connected to the USB hub breakout.](https://cdn-learn.adafruit.com/assets/assets/000/136/411/medium640/gaming_metro_rp2350_ch334f_hub.png?1745242417)

Warning: USB Host is under active development. At the time of writing this, the SNES-like controller only works when connected through a USB hub such as the CH334F.

## Install the Libraries

You can install the libraries for this project using the Library Manager in the Arduino IDE.

Click the Library Manager icon, search for Adafruit TinyUSB Arduino, and select the Adafruit TinyUSB Library.

If asked about dependencies click "Install All".

![Arduino IDE with library manager pane open and "tinyusb arduino" in the search box. The Adafruit TinyUSB Library appears in the results with the install button highlighted.](https://cdn-learn.adafruit.com/assets/assets/000/136/342/medium640/circuitpython_arduino_library_manager.png?1744982811)

![Arduino IDE dialog asking if the user wants to install dependencies for Adafruit TinyUSB library. The install all button is highlighted. ](https://cdn-learn.adafruit.com/assets/assets/000/136/343/medium640/circuitpython_install_dependencies.png?1744983019)

Then install the Pico PIO USB library. Click the **Library Manager** icon menu item again, search for&nbsp; **PIO USB** , and select the **Pico PIO USB** library by sekigon-gonnoc.

![Arduino IDE with library manager pane open and "pio usb" in the search box. The Pico PIO USB library by sekingon-gonnoc appears in the results with the install button highlighted.](https://cdn-learn.adafruit.com/assets/assets/000/136/344/medium640/circuitpython_piousb_install_libmanager.png?1744983207)

![Arduino IDE dialog asking if the user wants to install dependencies for Pico PIO USB library. The install all button is highlighted.](https://cdn-learn.adafruit.com/assets/assets/000/136/345/medium640/circuitpython_piousb_dependencies_install.png?1744983252)

## Code Prep

The code consists of a main **.ino** program file and two header files. The header files store configuration for USB host on the RP2040 and HID device reports for your gamepad. You'll need all three of these files to properly compile and run the project. These files are available in the **.ZIP** folder below or on [GitHub](https://github.com/adafruit/Adafruit_Learning_System_Guides/tree/main/USB_SNES_Gamepad/Arduino_Feather_RP2040_USB_Host/snes_gamepad_simpletest).

[snes_gamepad_simpletest.zip](https://cdn-learn.adafruit.com/assets/assets/000/136/346/original/snes_gamepad_simpletest.zip?1744983489)
 **snes\_gamepad\_simpletest.ino** :

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/USB_SNES_Gamepad/Arduino_Feather_RP2040_USB_Host/snes_gamepad_simpletest/snes_gamepad_simpletest.ino

 **gamepad\_reports.h** :

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/USB_SNES_Gamepad/Arduino_Feather_RP2040_USB_Host/snes_gamepad_simpletest/gamepad_reports.h

## Upload and Test

Before uploading, you'll need to update some settings in the Boards menu. Select the appropriate board that you are using, either **Adafruit Feather RP2040 USB Host** , or **Adafruit Metro RP2350**. Under **USB Stack** select **Adafruit TinyUSB**. Then, upload the sketch to your board. You can use the Serial Monitor in the Arduino IDE for debugging any errors.

![Arduino IDE tools menu with Adafruit Feather RP2040 USB Host board, and TinyUSB stack selected and highlighted.](https://cdn-learn.adafruit.com/assets/assets/000/136/347/medium800/circuitpython_tools_config.png?1744983841 )

## Serial Output

The code will connect to the SNES-like controller and read data coming from it. When it detects that buttons are pressed it will print which ones are down into the serial output.&nbsp;

![Arduino IDE serial output showing which buttons on the controller have been pressed.](https://cdn-learn.adafruit.com/assets/assets/000/136/348/medium800/circuitpython_usbhost_snes_serial_output.png?1744984132 )

## The Controller is Not Acting Right

The program presented works for the [generic SNES controller sold by Adafruit](https://www.adafruit.com/product/6285). Controllers from other sources may have key mappings a bit different from the Adafruit controller. This will help you adjust the code to your controller.

In **gamepad\_reports.h** are the following constants:

```auto
// HID reports for USB SNES-like controller

// Byte indices for the gamepad report
#define BYTE_DPAD_LEFT_RIGHT 0   // D-Pad left and right
#define BYTE_DPAD_UP_DOWN    1   // D-Pad up and down
// bytes 2,3,4 unused
#define BYTE_ABXY_BUTTONS    5   // A, B, X, Y
#define BYTE_OTHER_BUTTONS   6   // Shoulders, start, and select


#define DPAD_NEUTRAL         0x7F
// D-Pad directions
#define DPAD_UP              0x00
#define DPAD_RIGHT           0xFF
#define DPAD_DOWN            0xFF
#define DPAD_LEFT            0x00


// Face buttons (Byte[5])
#define BUTTON_NEUTRAL       0x0F
#define BUTTON_X             0x1F
#define BUTTON_A             0x2F
#define BUTTON_B             0x4F
#define BUTTON_Y             0x8F


// Miscellaneous buttons (Byte[6])
#define BUTTON_MISC_NEUTRAL   0x00
#define BUTTON_LEFT_SHOULDER  0x01
#define BUTTON_RIGHT_SHOULDER 0x02
#define BUTTON_SELECT         0x10
#define BUTTON_START          0x20
```

These are the values obtained with the Adafruit controller. You can change the numbers to the ones output by your controller. For example a customer stated they changed&nbsp;`BTN_DPAD_UPDOWN_INDEX` to `4` from `1` and `BTN_DPAD_RIGHTLEFT_INDEX` to `3` from `0`.

How do you find the right numbers?

1. Trial and error based on the output of the program (shown above)
2. You can use a HID key mapper website. [https://joypad.ai/](https://joypad.ai/) is one such site (not tried)

Change the appropriate value(s) and recompile the sketch.

If you are positive you bought your controller from Adafruit and it's not mapped right, you can post to the [Adafruit forums](https://forums.adafruit.com/) for assistance.


## Primary Products

### USB Game Controller with SNES-like Layout

[USB Game Controller with SNES-like Layout](https://www.adafruit.com/product/6285)
This is a generic USB&nbsp;game controller, which plugs into to provide a two-handed gaming experience for retro gaming, or really any game you want to use a handheld rather than keyboard controller! Use it with your Raspberry Pi or desktop computer while playing emulated games, or as a...

In Stock
[Buy Now](https://www.adafruit.com/product/6285)
[Related Guides to the Product](https://learn.adafruit.com/products/6285/guides)

## Featured Products

### Adafruit Fruit Jam - Mini RP2350 Computer

[Adafruit Fruit Jam - Mini RP2350 Computer](https://www.adafruit.com/product/6200)
We were catching up on a recent [hackaday hackchat with eben upton](https://hackaday.io/event/202122-raspberry-pi-hack-chat-with-eben-upton)&nbsp;and learned some fun facts: such as the DVI hack for the RP2040 was inspired by <a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/6200)
[Related Guides to the Product](https://learn.adafruit.com/products/6200/guides)
### Adafruit Metro RP2350

[Adafruit Metro RP2350](https://www.adafruit.com/product/6003)
Choo! Choo! This is the RP2350 Metro Line, making all station stops at "Dual Cortex M33 mountain", "528K RAM round-about" and "16 Megabytes of Flash town". This train is piled high with hardware that complements the Raspberry Pi RP2350 chip to make it an excellent...

In Stock
[Buy Now](https://www.adafruit.com/product/6003)
[Related Guides to the Product](https://learn.adafruit.com/products/6003/guides)
### Adafruit Feather RP2040 with USB Type A Host

[Adafruit Feather RP2040 with USB Type A Host](https://www.adafruit.com/product/5723)
You're probably really used to microcontroller boards with USB, but what about a dev board with two? Two is more than one, so that makes it twice as good! And the&nbsp; **Adafruit Feather RP2040 with USB Host** is **&nbsp;** definitely double-the-fun of our other Feather...

In Stock
[Buy Now](https://www.adafruit.com/product/5723)
[Related Guides to the Product](https://learn.adafruit.com/products/5723/guides)
### Adafruit CH334F Mini 2-Port USB Hub Breakout

[Adafruit CH334F Mini 2-Port USB Hub Breakout](https://www.adafruit.com/product/5999)
Sometimes, you've got something with a USB host, like an embedded Linux board, and you want to connect more than one thing. Or maybe you want to turn something like a keyboard into a multi-device USB peripheral. The&nbsp; **Adafruit CH334F Mini 2-Port USB Hub...**

In Stock
[Buy Now](https://www.adafruit.com/product/5999)
[Related Guides to the Product](https://learn.adafruit.com/products/5999/guides)
### USB Type A Jack Breakout Cable with Premium Female Jumpers

[USB Type A Jack Breakout Cable with Premium Female Jumpers](https://www.adafruit.com/product/4449)
If you'd like to connect a USB-host-capable chip to your USB peripheral, this cable will make the task very simple.&nbsp; **There is no converter chip in this cable!** &nbsp;It's basically a plain USB cable that's cut in half and with jumper sockets on the power and data...

In Stock
[Buy Now](https://www.adafruit.com/product/4449)
[Related Guides to the Product](https://learn.adafruit.com/products/4449/guides)
### USB Type A to Type C Cable - approx 1 meter / 3 ft long

[USB Type A to Type C Cable - approx 1 meter / 3 ft long](https://www.adafruit.com/product/4474)
As technology changes and adapts, so does Adafruit. This&nbsp;&nbsp; **USB Type A to Type C** cable will help you with the transition to USB C, even if you're still totin' around a USB Type A hub, computer or laptop.

USB C is the latest industry-standard connector for...

In Stock
[Buy Now](https://www.adafruit.com/product/4474)
[Related Guides to the Product](https://learn.adafruit.com/products/4474/guides)

## Related Guides

- [Adafruit Feather RP2040 with USB Type A Host](https://learn.adafruit.com/adafruit-feather-rp2040-with-usb-type-a-host.md)
- [Adafruit CH334F Mini USB Hub Breakouts](https://learn.adafruit.com/adafruit-ch334f-mini-4-port-usb-hub-breakout.md)
- [Adafruit Metro RP2350](https://learn.adafruit.com/adafruit-metro-rp2350.md)
- [Adafruit Fruit Jam](https://learn.adafruit.com/adafruit-fruit-jam.md)
- [Solderless Robot Toy Xylophone](https://learn.adafruit.com/solderless-robot-toy-xylophone.md)
- [DOOM Keeb](https://learn.adafruit.com/doom-keeb.md)
- [Using a Mouse with USB Host](https://learn.adafruit.com/using-a-mouse-with-usb-host.md)
- [CircuitPython Text Editor On The Go](https://learn.adafruit.com/circuitpython-text-editor-on-the-go.md)
- [Plotting Offline Data - JSONL to CSV files, filters and graphs](https://learn.adafruit.com/plotting-offline-data-jsonl-to-csv-files-filters-and-graphs.md)
- [How to Choose a Microcontroller](https://learn.adafruit.com/how-to-choose-a-microcontroller.md)
- [DIY Turbo Button Controller - HID Remapper](https://learn.adafruit.com/diy-turbo-button-controller-hid-remapper.md)
- [Case for Feather RP2040 USB Host](https://learn.adafruit.com/case-for-feather-rp2040-usb-host.md)
- [Create a Memory Game on Fruit Jam Metro RP2350](https://learn.adafruit.com/create-a-memory-game-on-metro-rp2350.md)
- [RP2040 RunCPM Emulator with USB Keyboard & HDMI screen](https://learn.adafruit.com/rp2040-runcpm-emulator-with-usb-keyboard-hdmi-screen.md)
- [USB MIDI Host Messenger](https://learn.adafruit.com/usb-midi-host-messenger.md)
- [Return to The Matrix with the Metro RP2350 or Fruit Jam](https://learn.adafruit.com/return-to-the-matrix-with-the-metro-rp2350.md)
- [Square NeoPixel Display with Black LED Acrylic](https://learn.adafruit.com/sqaure-neopixel-display-with-black-led-acrylic.md)
