Make an Arduino Game-pad Controller - Trackmania, Rocket League
by reactoimpact in Circuits > Arduino
613 Views, 0 Favorites, 0 Comments
Make an Arduino Game-pad Controller - Trackmania, Rocket League
Got an Arduino? Control a game that needs analog steering with it!
Most Arduino Boards don't interface as a keyboard and prevent it to be used as a game pad. I have made a simple way to take an Arduino Uno and create a game-pad with Tinkercad circuit designer, Python and Arduino.
Supplies
Hardware
- 1 Arduino Uno
- USB cable
- 2 push buttons
- 1 potentiometer
- 2 10K resistors
- wires
Software
- Arduino IDE
- Python
Setting Up the Arduino
Gather your Arduino Uno and attach the push buttons, resistors and potentiometer as per the image above. After connecting all the parts, download the controller.ino file below. Once downloaded open in the Arduino IDE and upload it to your Arduino.
If you would like to see how this program works open this link: Tinkercad Circuits
The Arduino Sketch basically sends the button presses and potentiometer readings through the serial output to your computer. This is just data and doesn't simulate a controller on its own.
Downloads
Installing Python and Vgamepad
Ok, now for the slightly more difficult part.
To make the Arduino able to control an analog input via the serial port, you have to install Python, Vgamepad and PySimpleGui.
First install the latest version of python: https://www.python.org/downloads/
You can check if Python was installed by going into a Powershell/Command Prompt and typing py
PS C:\Users\react> py
it should then show you the version of python installed:
PS C:\Users\react> py
Python 3.11.2 (tags/v3.11.2:878ead1, Feb 7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
After Python is installed, open up a powershell/command prompt and type
PS C:\Users\react> pip install vgamepad pysimplegui
Lots of text should show up as it installs vgamepad and pysimplegui. If no errors show up it installed successfully.
Downloading the Python Program
Now that all the packages are installed, you can download the python program Controller.pyw below from GitHub as a zip file:
Download and unzip the files, make sure to use the Controller.pyw file when opening the program. You can delete the other files.
Put the program somewhere you can access it easily.
Putting It Al Together
That's it, you have everything to get it running!
Firstly, you should plug in your Arduino into your computer and close the Arduino IDE.
The wait a few seconds to open the controller.py by double clicking it. It will open a cmd window to run it as-well as the Gui.
You first have to enter the port that the Arduino is currently on by checking in the Arduino editor. It should be something like COM4.
If the program exits it may be because:
- The Arduino IDE's Serial Reader is still running
- You didn't input the right Com Port
- The Arduino is not plugged in
Congrats! If the program doesn't exit, it should be working!
Open this gampad-tester to test it out.
All the code available is here: GitHub
Plese feel free to submit any issues or improvements i could make.