How to Connect a Cheap AliExpress 9-Pin NES-Style Controller to an ESP32
by Cyrill in Circuits > Arduino
39 Views, 1 Favorites, 0 Comments
How to Connect a Cheap AliExpress 9-Pin NES-Style Controller to an ESP32
Many cheap retro game controllers from AliExpress use a 9-pin connector, but inside the cable there may only be 5 wires.
Supplies
What You Need
- ESP32 development board
- Cheap AliExpress 9-pin retro/NES-style controller - https://de.aliexpress.com/item/32919127872.html
- Jumper wires
- Multimeter
- Optional but recommended: 1 kΩ resistors for the three signal lines
Info
Many cheap retro game controllers from AliExpress use a 9-pin connector, but inside the cable there may only be 5 wires. I cut open one of these controllers and found the following wire colours:
The controller PCB was marked:
Although the plug looks like a DB9-style retro connector, this is not a simple Atari-style joystick where every direction has its own wire. It is a NES-style serial controller. That means it uses only five connections:
After testing with a multimeter and ESP32, this was the working pinout for my controller.
Final Wire Mapping
Wire colourFunctionESP32 connection
Red VCC 3V3
Yellow GND
White Data
GPIO 25
Blue Latch
GPIO 27
Brown Clock
GPIO 26
Important: wire colours may vary between manufacturers. This mapping worked for my AliExpress NES Ver:2.0 9-pin controller with 5 internal wires.
Open the Controller
Remove the screws from the back of the controller and inspect the PCB.
Mine had five cable wires soldered to the board:
The board was marked NES Ver:2.0, which was the first clue that this was a NES-style serial controller.
Identify the Power Wires
Using diode mode on the multimeter, I found that red and yellow behave like the power pair.
The result was:
On my controller, connecting red to 3.3 V and yellow to GND worked correctly.
Use 3.3 V, not 5 V, when connecting to an ESP32. The ESP32 GPIO pins are not 5 V tolerant.
Connect the Controller to the ESP32
Use this wiring:
Controller wire ESP32 pin
Red 3V3
Yellow GND
White GPIO 25
Brown GPIO 26
Blue GPIO 27
Recommended safer test wiring:
The resistors are not strictly required once the pinout is confirmed, but they are useful protection during testing
Upload the ESP32 Test Code
This code reads the controller and prints the pressed buttons in the Serial Monitor.
Open the Serial Monitor at:
ESP32 Arduino Code
Expected Serial Output
With no button pressed, the raw value should normally be:
When pressing a button, one bit should change from 1 to 0.
Typical NES button order:
ButtonRaw hex value
A 0xFE
B 0xFD
Select 0xFB
Start 0xF7
Up 0xEF
Down 0xDF
Left 0xBF
Right 0x7F
Some clone controllers may use a different button order, so test every button individually.
How the Protocol Works
The controller does not send all buttons on separate wires. Instead, the ESP32 talks to it using three signal lines:
The sequence is:
- ESP32 sends a short pulse on Latch.
- The controller captures the current state of all buttons.
- ESP32 sends 8 pulses on Clock.
- On each clock pulse, the controller sends one button state on Data.
- The ESP32 reads the 8 bits and converts them into button names.
The buttons are normally active LOW:
Troubleshooting
Nothing changes when pressing buttons
Check:
Also make sure the Serial Monitor is set to:
Random values appear
Possible causes:
- DATA wire is not connected properly
- GND is missing
- Wrong signal mapping
- No pull-up on DATA
The code uses:
so the data line should not float.
One button is always shown as pressed
Check whether that button is physically stuck or whether the carbon pad is shorted. Also inspect the PCB for solder bridges or damaged traces.
Controller does not work at 3.3 V
My controller worked at 3.3 V. Some clones may expect 5 V. If you use 5 V, do not connect the DATA line directly to the ESP32. Use a level shifter or at least a voltage divider on the DATA line.
For ESP32, the safest first test is always:
Final Pinout Summary
For my AliExpress 9-pin NES-style controller with 5 internal wires:
ESP32 pins used in the example:
This saves others from having to repeat the full multimeter and permutation-testing procedure.