DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

【Click the above「blue words」 to follow DF Maker Community and become a tech beauty control together】

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

Through this project, you will learn how to design a breadboard gamepad circuit, and how to communicate this circuit as a gamepad with Android devices, TV boxes, PlayStation, and computers.

The main text begins! (There is a video demonstration at the end)

Step 1: Doit ESP32 Devkit V1 Development Board

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

In terms of the circuit, I chose the low-cost Doit ESP32 Devkit V1 development board, which provides wireless communication options such as WiFi, Bluetooth, and ESP-NOW.

The ESP32 board model used in this project has a total of 30 I/O pins. Some models have 36 I/O pins and are longer in size. The Doit ESP32 Devkit V1 development board can operate with a supply voltage of 4V to 12V via the VIN pin.

More details can be found here:https://lastminuteengineers.com/esp32-pinout-reference/

Step 2: Build the Circuit on the Breadboard

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide
DIY ESP32 Bluetooth GamePad: A Comprehensive Guide
DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

In addition to the ESP32 development board, the gamepad circuit also requires a joystick module, buttons, resistors, and some wires.

  • 12mm button switch with round cover
  • 4K7 resistors for buttons
  • XY joystick module
  • Doit ESP32 Devkit V1 development board
  • Breadboard
  • Jumper wires

Step 3: Set Up the ESP32 Development Board

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

Steps:

1. Download and install the latest version of Arduino IDE from the official Arduino website.

2. Open Arduino IDE, go to “Preferences” > “Board Manager URLs”, paste the shared ESP32 package link, and click the OK button.

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide
DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

3. Navigate to “Tools” > “Boards Manager”.

4. Search for “ESP32” in the Boards Manager and install the ESP32 board.

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

5. Select the appropriate ESP32 board from the “Tools” > “Board” menu.

Additional Boards Manager URL:

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

Step 4: Source Code for BLE GamePad and NIM BLE Library

The source code includes a library called “BLE GamePad”. You can find detailed explanations and examples on the library’s GitHub page.

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

Go to “Add Library” search for the “BLE GamePad” library and install it. This library also requires the “NIM BLE” library. If the library is already installed, we can take a closer look at the source code.

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide
DIY ESP32 Bluetooth GamePad: A Comprehensive Guide
DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

GitHub address:https://github.com/lemmingDev/ESP32-BLE-Gamepad

Step 5: GamePad Source Code

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

The shared gamepad source code contains a total of 13 buttons that define the key functions of a standard gamepad. Additionally, the source code provides three gamepad modes.

This description block contains the key names of the mods and the button numbers for different gamepad mods. Each key name has a corresponding pin number.

/*
 * ANDROID GamePad
 * {A=1, B=2, C=3, X=4, Y=5, Z=6, L1=7, R1=8, L2=9, R2=10,
 * Select=11, Start=12, PS=13, L3=14 , R3=15} 
 * 
 * PS GamePad Mode
 * {SQUARE=1, X=2, CIRCLE=3, TRIANGLE=4, L1=5, R1=6, L2=7, R2=8,
 * Select=9, Start=10, L3=11, R3=12, PS=13}
 * 
 */

The “Buttons Pins” array represents the physical button pins used on the development board. The “Number Buttons” constant specifies the number of buttons and includes the pin values for each button connection.

int buttonsPins[NUM_BUTTONS] = {X_BUTTON, CIRCLE_BUTTON, TRIANGLE_BUTTON, SQUARE_BUTTON,
                          R1_BUTTON, R2_BUTTON, L1_BUTTON, L2_BUTTON,
                          START_BUTTON, SELECT_BUTTON, PS_BUTTON,
                          R3_BUTTON, L3_BUTTON};

The “Android GamePad Buttons” array contains an ordered list of buttons used in Android GamePad mode. Each button is assigned a number. For example, button “A” is number 1, button “B” is number 2.

int androidGamepadButtons[NUM_BUTTONS] = {1, 2, 3, 4, 8, 10, 7, 9, 12, 11, 13, 15, 14};

The “PS GamePad Buttons” array contains the list of buttons used in PlayStation GamePad mode.

int PS1GamepadButtons[NUM_BUTTONS] = {2, 3, 4, 1, 6, 8, 5, 7, 10, 9, 13, 12, 11};

The “PC GamePad Buttons” array contains the list of buttons used in computer gamepad mode.

int PCGamepadButtons[NUM_BUTTONS] = {1, 2, 4, 3, 6, 8, 5, 7, 10, 9, 0, 12, 11};

The “GamePad Mode” variable contains the current GamePad mode. By default, the Android mode is assigned, but this value can be changed later in the code.

GamepadModes gamepadMode = ANDROID;

Let’s update the source code based on the components found in the breadboard circuit. There are 4 buttons and a joystick module in the circuit, and I will choose the “Android Gamepad” mode to test the circuit. Define the pin of the components on the circuit, the key functions that the gamepad should call, and update the pin numbers. Then upload the source code.

The complete code can be downloaded at the end.

Step 6: Test the Breadboard Circuit with an Application

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide
DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

I used the “GamePad Tester” Android app to view and test the button and joystick functions.

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

Install the application, then open the Bluetooth connection and connect to the ESP32.

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

Open the application, go to “Android GamePad Tester” and complete the testing of the circuit components. Then, perform a real test of the circuit through a game.

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

I installed a racing app and am ready to start testing!

Step 7: Printed Circuit Board

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

I used the previously designed bat-themed printed circuit board to test as a gamepad.

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide
DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

Like the breadboard circuit, I chose easy-to-assemble solderable components. Install the required components on the PCB, then solder them in place using a soldering iron and solder wire.

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide
DIY ESP32 Bluetooth GamePad: A Comprehensive Guide
  • 1x Diode SB560
  • 3x Capacitor 100uF 16V
  • 2x XY Thumb Joystick
  • 1x Voltage Regulator 7805CV (*optional)
  • 2x LED 3mm
  • 2x Resistor 220R
  • 6x Resistor 4K7
  • 1x Doit ESP32 DevKit V1
  • 2x Female Header 1×15 2.54
  • 2x Female Header 1×4 2.54
  • 1x Connector
  • 4x 12mm Button Switch with Round Cover

PCB Gerber files:pcbway.com/project/shareproject/DIY_ESP32_Bluetooth_GamePad_for_Android_PlayStation_and_PC

Step 8: Test the Printed Circuit Board

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

The design includes 4 buttons and 2 joysticks, with each joystick connected to a button. Therefore, custom source code is needed for 6 buttons and 2 joysticks.

Then I uploaded the source code. The circuit includes a female header for a voltage regulator. If you want to power the circuit with an external power supply and the voltage is higher than the working range of the ESP32 (6 to 12v), you can use a regulator (*7805CV).

You can power the ESP32 through USB input without using a regulator, or you can power it externally within the 6 to 12 volts range using jumper wires.

I used a blank PCB as a cover to prevent hand contact with the circuit. Insert the ESP32 board into the circuit and then test the buttons and joystick using the gamepad testing application. Next, I opened a racing game for control testing.

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide
DIY ESP32 Bluetooth GamePad: A Comprehensive Guide
DIY ESP32 Bluetooth GamePad: A Comprehensive Guide
DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

This part of the code can also be downloaded at the end.

Step 9: Summary

This circuit works very well on Android phones. I tested it again on Android TV and Android TV Box, and the results were also satisfactory. The tests on Windows-based PCs were also successful, but I encountered some connection issues on the MacBook. After some research, I assigned the PS mode to the joystick buttons and held it down while establishing the Bluetooth connection, resulting in a successful connection, and the MacBook recognized the circuit as a game controller. I also tested the circuit with two ESP32 boards, using ESP-NOW for communication between them, and the results were also successful.

If you want to know what else can be done with this circuit, you can refer to the following projects.

You can use this PCB in the project, which has various wireless communication options, such as from ESP32 to ESP32 and from Bluetooth to WiFi.

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide
DIY ESP32 Bluetooth GamePad: A Comprehensive Guide
DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

1.https://www.instructables.com/ESP32-Joystick-Hand-Controller-ESP-NOW/

2.https://www.instructables.com/ESP32-Servo-Motor-Controller-Board-Wireless-Contro/

3.https://www.instructables.com/ESP32-Mecanum-Wheels-Robot-and-Bluetooth-Gamepad-C/

Original author: MertArduino

Original link: https://www.instructables.com/DIY-ESP32-Bluetooth-GamePad-for-Android-PlayStatio/

Please indicate the source information when reprinting

Hardware Arsenal

DF Hardware Arsenal

Click to learn more👆

DIY ESP32 Bluetooth GamePad: A Comprehensive Guide

DFRobot Official Brand Store https://dfrobot.taobao.com/

DFRobot Official Flagship Store https://dfrobot.jd.com/

If you have anything to say, feel free toleave a message!

The code mentioned in the article can be downloaded by clicking Read the original text or reply to the public account with “bat controller” to download.

Review of previous projects

Understand the entire series of Raspberry Pi in one article!

Learn these 20 Linux commands to master your Raspberry Pi!

Raspberry Pi Cyberdeck with 6 screens, check it out!

Light up the Christmas tree with Raspberry Pi

Raspberry Pi DIY cloud server, portable in your pocket!

Make a “digital microscope” with Raspberry Pi

Spring is here, you need a retro-style Raspberry Pi camera

3D printed Raspberry Pi spider robot

Make a handheld computer with Raspberry Pi and ESP32!

Build a retro gaming console based on Raspberry Pi Zero

The most comprehensive! How to choose Raspberry Pi expansion boards? A video solves it!

Click to read👆

Leave a Comment

×