A hybrid application that bridges a PC gaming controller (via SDL2) to an ESP32 microcontroller over Wi-Fi (UDP) to control motor outputs.
This project consists of two parts:
- PC Client (C++ & SDL2): Connects to a standard gamepad using SDL2 to read analog input values specifically from the Left and Right Triggers. It encapsulates these values into a string format
(RT,LT)and broadcasts them continuously via a UDP socket. - ESP32 Receiver (Arduino/C++): Connects to a pre-defined Wi-Fi network, spins up a UDP server, and listens for instructions. It parses the trigger values and maps them directly to PWM outputs via the
analogWritecommand on designated pins (used for interfacing with a motor driver).
include/: C++ header files for SDL configuration and UDP networking setup.src/: C++ source files containing the PC client logic.SDLCONF.cpp: Handles initializing SDL2, connecting to joysticks, reading trigger values, and formatting telemetry data.netw.cpp: Handles the creation of the UDP socket and packet transmissions.main.cpp: Entry point tying input sampling and networking together.
FIA/: Contains the Arduino sketch (FIA.ino) intended to be flashed onto the ESP32.
- C++ Compiler (e.g.,
g++orclang++) - SDL2 Library (install via package manager, e.g.,
sudo apt-get install libsdl2-devon Debian/Ubuntu)
- Arduino IDE or PlatformIO
- Installed ESP32 Board Definitions in your IDE.
- Open
FIA/FIA.inoin your Arduino IDE. - Modify the Wi-Fi credentials to match your local network:
const char* ssid = "YOUR_SSID"; const char* password = "YOUR_PASSWORD";
- Upload the code to your ESP32 board.
- Open the Serial Monitor with a baud rate of
115200. Once connected to Wi-Fi, note the IP address printed on the console (e.g.,192.168.1.X).
- Update the destination IP address in the C++ networking logic (
src/netw.cpporsrc/SDLCONF.cppwheresendDatais invoked) to match the ESP32's assigned IP address. - Compile the PC code. You can use a generic
g++compilation linking the SDL2 library:g++ src/*.cpp -o esp_controller -lSDL2
- Ensure a supported gamepad/controller is plugged into your PC via USB or paired via Bluetooth.
- Run the executable:
./esp_controller
- Press the Left Trigger (LT) and Right Trigger (RT). The values will be sent to the ESP32, which sequentially parses the packet and updates the PWM outputs on pins
EN2andEN4for connected motors.
The script expects a standard motor driver configuration (like an L298N). Example pinouts predefined in FIA.ino:
- Motor 1 Direction:
21,13| PWM (Enable):22 - Motor 2 Direction:
14,25| PWM (Enable):23(Controlled by RT) - Motor 3 Direction:
26,27| PWM (Enable):18 - Motor 4 Direction:
32,33| PWM (Enable):19(Controlled by LT)