TeensyPiGamepad

Joined
Mar 7, 2016
Messages
44
Likes
52
Location
Canada
Portables
1
This is a microcontroller project but I am posting it in the Raspberry Pi section so people can use it as a ressource. This is basically code to use a Teensy with your sbc with Retroarch as a gamepad/touch screen driver. Here is the GitHub repository: https://github.com/hazbounn/TeensyPiGamepad

Feel free to use this code in your projects (I would appreciate if you gave me credit for it though :P )
Do report issues/possible improvements in this thread.

And here a is copy of the Readme :

Arduino code to use a Teensy 3.2 as a media controller for linux systems using Retroarch and EmualtionStation. The Teensy behaves as a gamepad, mouse and keyboard. This code provides basic gamepad funcionnality (for use with 3ds sliders as joysticks), a resistive touch screen driver which converts the user's touch input to usb mouse input, and volume control.

PIN MAPPINGS

Teensy pin Physical Component
0 y
1 b
2 a
3 x
4 l
5 r
6 start
7 select
8 dpad up
9 dpad right
10 dpad down
11 dpad left
14 (analog 0) touch x-
15 (analog 1) touch y+
16 (analog 2) touch x+
17 (analog 3) touch y-
18 (analog 4) slider Y
19 (analog 5) slider X

Edit: I can't get the darn formatting right with the Xenforo editor...

FUNCTIONNALITY

Basic gamepad functionnality is implemented. You just need to map the buttons in the retroarch configuration. Note that start button has been mapped to the "enter" key and the select button has been maped to the "space" key (it may be easier to map them using a usb keyboard before using the Teensy). This
allowed easier navigation in Kodi and various dialog selections.

A "hotkey" mode has also been implemented. It is activated by pressing the L and R buttons
at the same time. Hotkey functions:
l+r+a = start (map to enter key in retroarch)
l+r+b = select (map to space key in retroarch)
l+r+left = quit (mapped to the "escape" key. It is useful in EmulationStation and Retroarch )
l+r+(up || down) = (volume up || violume down) (eliminates the need for hardware volume control)

EDITING AND BUILDING

Simply clone the repository and build the project.
Any functionnality you do not want to use has to be commented out before compiling (especially the touchscreen code). The project has been coded with Teensyduino 1.6 using the Visual Studio IDE with the Visual Micro plugin. It can be edited in the arduino IDE but comments will not appear the way they should because of Arduino's different text formatting. If you do not want to install arduino and want to keep all functionnalities (including the touch screen), you can simply flash the Teensy with the hex file found in the "./core_project/Debug" folder using the Teensy Loader application downloaded from the PJRC website.

Note: if you want to use regular analog joysticks instead of 3ds sliders:
change line 209 to: yValue = analogRead(4)
change line 215 to: xValue = analogRead(5)



Any improvements are welcome! Simply create a Pull Request and I will take a look.
Send me a PM on bitbuilt.net/forums/ if you have any questions (username Pinotte).
 
Last edited:

Nick

.
Joined
Apr 24, 2016
Messages
121
Likes
20
Is there a way to add another stick like the viewing/c stick to the teensy board? It would be nice to use one of these to make a pi portable with emulation station for ps1 controls or even use it instead of the c buttons for n64
 
Joined
Mar 7, 2016
Messages
44
Likes
52
Location
Canada
Portables
1
Is there a way to add another stick like the viewing/c stick to the teensy board? It would be nice to use one of these to make a pi portable with emulation station for ps1 controls or even use it instead of the c buttons for n64
Yes it can easily be done but I'm neck deep into work, finals and have a technical interview coming up so it might be a while before I do it myself...
https://www.pjrc.com/teensy/td_joystick.html
^This is the documentation, all you have to do is duplicate my code for the joystick X and Y and aply it to the joystick z and zRotate (don't forget to map the pins and set them to inputs in the setup). Feel free to add the feature yourself and make a pull request.
 
Last edited:
Joined
Dec 10, 2016
Messages
578
Likes
663
Location
Constant Fear
Portables
sin^2(x) + cos^2(x) +e^(i*pi)
sorry if this is a noob question, but i cant get this to install onto my Teensy (3.2)
 
Joined
Mar 7, 2016
Messages
44
Likes
52
Location
Canada
Portables
1
sorry if this is a noob question, but i cant get this to install onto my Teensy (3.2)
I'm going to need more details. Are you compiling the code or are you flashing the hex file? If you are compiling the code which version of the arduino ide are you using and have you installed the teensyduino addon to make it compatible with the teensy?
 
Joined
Dec 10, 2016
Messages
578
Likes
663
Location
Constant Fear
Portables
sin^2(x) + cos^2(x) +e^(i*pi)
I'm going to need more details. Are you compiling the code or are you flashing the hex file? If you are compiling the code which version of the arduino ide are you using and have you installed the teensyduino addon to make it compatible with the teensy?
I was using the Teensyduino, and i am just lost.
 
Top