ESP32 BLE GamePad

by ElectroPoint4u in Circuits > Remote Control

27141 Views, 48 Favorites, 0 Comments

ESP32 BLE GamePad

DIY BLE Gamepad using ESP32 | PCBway

This is a wireless DIY Gamepad which you can use on both Android and windows to play your favorite video games. Like most of the traditional Game Controllers it has Two analog joysticks, two Trigger buttons, D-pad buttons and some LEDs. It runs on two 18650 Li-Ion battery. also there is a USB type-C port on the PCB for charging and Programming the on Board ESP32 microcontroller.

Supplies

  1. ESP32
  2. 6 ws2812b
  3. 2 Joystick
  4. 2 Angle Push Button
  5. 8 Push button
  6. 18560 battery and Battery holder
  7. 3 way toggle switch
  8. TP4056 battery charging circuit with protection
  9. MT3608 boost converter

Back Story

DFR0623-detail-003_768x512.jpg

You may have seen such DIY game controllers before. But most of them uses Arduino. Or more specifically Arduino pro micro or Leonardo board. Because these boards support HID, or human interface devices over USB. but ESP32 doesn't have such feature. Instead esp32 have BLE, or Bluetooth low energy, which we can use to communicate wirelessly over Bluetooth.

Schematic

Schematic_ESP32-BLE-Controller_2021-01-04.png

FIrst I made the schematic in EasyEDA. Initially it may looks a lot of connections but there are just buttons connected to a GPIO pin of ESP32. So we have ESP32 module, as the central controller, then we have the USB type-C port, and a 3.3v regulator to convert 5v to 3.3v. Then we have the programming circuit, using ch340c usb to serial converter with auto programming mode and auto reset circuitry using duel transistors. We also have a battery charging circuit using TP4056 Li-ion Charger module, along with overcharge, and over discharge protection with the help of DW01A and FS8205A IC. Which then boost up to 5v, using the boost converter ic MT3608. Next we have the joysticks, D-Pad buttons, trigger buttons, Neopixel LEDs, i2c port. And finally a 3 way switch, to toggle between USB power and battery power.

PCB Design

PCB_PCB_2020-11-26_21-51-49_2021-01-13.png
PCB_PCB_2020-11-26_21-51-49_2021-01-13 (1).png
photo_2021-01-13_01-32-43.jpg
PCB_PCB_2020-11-26_21-51-49_2021-01-13 (2).png

After finishing the schematic I continued to design the PCB. The shape of the PCB is inspired by the latest PS5 Controller. To do this first I downloaded an Image of it for reference. Which I then outlined and create a DXF file using InkScape. I used it to make the outline of the PCB and SilkScreen graphics. then I place all the components one by one in the appropriate position followed by completing the routing. Then I head over to PCBway for manufacturing the PCB. You can also get the same board as mine by following this link.

PCB Assembly

photo_2021-01-13_00-56-50.jpg
photo_2021-01-13_00-57-01.jpg
photo_2021-01-13_00-57-31.jpg
photo_2021-01-13_00-57-07.jpg
photo_2021-01-13_00-57-12.jpg
photo_2021-01-13_00-57-16.jpg

After getting the PCB I started assembling it. First I solder the Type-C connector. And soldering those tiny pins is a bit tricky. First I added some solder to the PCB pads. Then I position the connector over it and gently heat up the pads. which turns out not bad actually, considering I was using type-C connector for the first time in my project. Anyways I continued to solder the rest of the SMD components as well. At one point I needed a 2k resistor which I didn't have so I had to improvise. I soldered two 5k resistor and one 10k resistor on top of each other connected in parallel and the equivalent resistance became 2k. After finishing the top part i soldered 2 battery holder at the back of the PCB. and the assembly was finished.

Testing

photo_2021-01-13_00-57-27.jpg
BLE Gamepad RGB Test

After Assembling I test each sections one by one Starting from the battery charging circuit. I plug the USB type C cable and the battery started charging. when the charging is finished the green LED turned on indicating the battery is fully charged. Then I test the programming circuit. For that I wrote a small sketch which reads the Analog input value on the ADC pin and converts it into voltage level. which shows the battery level perfectly on the serial monitor. Then I also test the RGB leds by uploading a example sketch from the fastLED library

Final Code

photo_2021-01-13_00-57-35.jpg
photo_2021-01-13_00-57-39.jpg

The code is based on BLE Gamepad library by lemmingDev. In the code I have defined all the GPIO pins for different inputs. Then in the setup there are some initial led animations. And as soon as the board is connected to the device, all LEDs will turn Green. And it will check battery voltage, in a time interval, which is defined earlier. Then we get the button states, and set the gamepad buttons accordingly. Then we take the analog inputs, and map it to suitable values. And finally set the axis according to the values we received. After uploading the code open Bluetooth menu on your Smartphone or PC and you will see a new device pops up. click on that to connect it and you are ready to play.

Watch the Full Video

DIY BLE Gamepad using ESP32 | PCBway