The chip ATMega32u4 what is used in Arduino Leonardo, Micro or Pro Micro have ability to use custom USB HID Descriptors. Thanks this ability we can make our Arduino be as generic Gamepad!
This library contains a all things to "simulate" a PS2 gamepad (so two thumbsticks and 16 buttons).
The library need a Arduino IDE 1.6.6 or higher for proper running.
Next we need to download a library.
All the data and documentation are storaged in a GitHub repository:
https://github.com/GAMELASTER/ArduinoGamepad
For download click a "Download ZIP" button in right side.
Create a new directory named "Gamepad" in (typically located in Windows at) Documents > Arduino > libraries, and copy all files from "ArduinoGamepad-master" directory in downloaded ZIP into that directory.
Then start a Arduino IDE and library appear in list of libraries and in examples list.
For testing a real connection between hardware, Arduino and PC we need some buttons or thumbaxises.
I got two thumbaxises + 2 buttons (pressing a thumbaxises), connected it with Pro Micro and lets go make an Arduino Sketch.
I connected Left Thumbstick to:
I connected Right Thumbstick to
https://tkkrlab.nl/wiki/Arduino_KY-023_XY-axis_joystick_module
Compile, deploy and open Serial Monitor.
Try to move with thumbstick to minimum - maximum, try to click etc.
The thumbsticks can be a different. For me its have a relative values.
Minimum value of axis is 0 and fully maximum is 1000. So logically the center is 500.
At my Thumbstick is problem, the center have (almost) still different value, so when we will be doing a integration with library, we must make calibration, stabilisation and final formatting of values.
And the Z (pressing) i have 0 when pressed and 1 when released (this is not a true, its inverted, the invert doing a INPUT_PULLUP).
Sketch:
In this sketch I integrated my thumbsticks as I refferenced in previous step.
Now I will describe it.
The numbers of buttons is described in image upper.
Compile, deploy and lets go play some game!
I selected a Mirrors Edge, but Mirrors Edge supports only a XBOX 360 gamepad, this can be simply solved by downloading X360CE.
This library is a part of my project where I build custom handheld Raspberry Pi Retro Console, what will be posted here in Instructables when it will be done, for now I writing a blogs of developing at my blog, dont forget to look it!
Documentation, Bugs etc. is in GitHub:
http://github.com/GAMELASTER/ArduinoGamepad/
Or tell me it into a comments!