Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ESP32 Controller

A hybrid application that bridges a PC gaming controller (via SDL2) to an ESP32 microcontroller over Wi-Fi (UDP) to control motor outputs.

Overview

This project consists of two parts:

  1. 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.
  2. 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 analogWrite command on designated pins (used for interfacing with a motor driver).

Repository Structure

  • 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.

Prerequisites

For the PC Client (Linux/macOS)

  • C++ Compiler (e.g., g++ or clang++)
  • SDL2 Library (install via package manager, e.g., sudo apt-get install libsdl2-dev on Debian/Ubuntu)

For the ESP32 Receiver

  • Arduino IDE or PlatformIO
  • Installed ESP32 Board Definitions in your IDE.

Setup and Usage

1. Configure the ESP32 Firmware

  • Open FIA/FIA.ino in 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).

2. Configure and Build the PC Client

  • Update the destination IP address in the C++ networking logic (src/netw.cpp or src/SDLCONF.cpp where sendData is 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

3. Run the System

  • 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 EN2 and EN4 for connected motors.

Hardware Connections (ESP32)

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)

About

A Simple ESP32 Controller Connection using SDL2 and UDP server

Resources

Stars

0 stars

Watchers

1 watching

Forks

Contributors

Languages