[posted] Gamepad to Touch Events with Teensy, AKA, TUBG: Teensy Unknown Battleground

Sinsid

New member
Introduction

I wanted a way to use an external controller to play a mobile phone game. Everything that I read online about how to do this did not seem acceptable.

Existing solutions that I found:

Download the game to your phone from some Chinese website. This is not an official copy of the game. This is problematic for a couple of reasons, it's clearly a bannable offense from the Game Devs point of view. It also requires installing an application on my device that I do not trust. And on an iOS device it would also requiring jailbreaking it. Not Acceptable.

Play the game via an emulator like BlueStacks. This is not a bannable offense from the Game Devs point of view. But they detect this and only let you play with other people using emulators. I have lots of friends that I play with that I know from other online games I play. So, the solution requires me to still be able to play with them. Not Acceptable.

Enter Teensy. iPads and Android tablets already support external touch pads. So why can’t I use Teensy do what I want using an official copy of the game, not running in an emulator?

It turns out that I can.

The Build

Compared to some of the other projects I see posted here, this project is very entry level. Which is great because that’s about my experience level working with electronics projects. Prior to this my experience was limited to building RetroPie's and one project I did with an Arduino for another mobile phone game years ago.

Hardware wise you need a Teensy 3.6 and a USB Host Cable for Teensy 3.6. Do not use a Teensy 4.0 (and probably 4.1). That was my first mistake. There is something wrong with the touchpad support in the 4.0. Trying that and finding it didn’t work did not deter me. Searching the forums suggested I may have more luck with a 3.6. Let's throw another $30 into this project and try the Teensy 3.6. That did work!

I also found that you need to run the Teensy on external power to get an iPad to recognize it. I am not sure if that is a requirement on an Android tablet or not because by the time I tested Android I was already running with external power.

iPad Specific Issues

First off, the only way I got the iPad to recognize the teensy was to use Apple's Lightning to USB 3 Camera Adapter. I first tried a cheaper generic version that I found on Amazon, but this did not work. Using the official Apple dongle and a Teensy on external power does work. HOWEVER... I was not able to get the iPad to recognize touch events. This is very disappointing and I am hoping it is just an issue with the USB descriptor. (https://forums.developer.apple.com/thread/69863 as a possible update. I will play around with this at some point.) I haven’t given up on this. I really want to get this working on iPads. I was able to use Keyboard and Mouse commands. And I wrote a version of TUBG that uses Mouse.Move commands. It's essentially a 1 finger solution. which isn't really practical. Also annoying is that the iPad doesn’t like Mouse.MoveTo, so all of the mouse commands need to be relative. There is tons of drift in these mouse commands. I programmed 1 button of my gamepad to move the mouse massively Up and Left to always put it in the top corner of the iPad. Essentially reset to 0,0. And I put all of the other buttons I wanted to use close to that corner as well. So, between frequent resets and the fact everything is close together is sort of works. It is still only a 1 finger solution though and that’s basically a deal breaker for playing a game like PUBG.

Android Specific Issues

None really. It just works. I had to buy a USB-C to Micro USB cable though. That's sort of the unicorn of USB cables.

Gamepad issues

I tried using a 3rd party PS3 controller at first. I have lots of them from my RetroPie builds. This confused me for about a day because I didn't know what inputs I should be getting. I was getting inputs that made no sense, and the joysticks were not reporting any events. Luckily, I had a XBOX360 Wireless receiver that I had also bought for the RetroPie, and decided to give that a try. Now all of the inputs that I got from the controller made sense!

TUBG.jpg


video: https://vimeo.com/426094066


TODO

I am going to keep working on iPad support and I would also like to make the buttons/touch event mapping into a config that can be read from a SD card.


Shopping List

TEENSY 3.6
https://www.pjrc.com/store/teensy36.html
$29.25

USB Host Cable for Teensy 3.6
https://www.pjrc.com/store/cable_usb_host_t36.html
$3.00

Pins (header), 14 pins, 0.1 inch (2.54 mm) spacing
https://www.pjrc.com/store/header_14x1.html
$0.28

R-Tech JC-Tech DC12V 1A Ul-Listed Switching Power Supply Adapter for CCTV - 5 Pack - Black
https://www.amazon.com/dp/B00FEOB4EI/
$3.00 each (only need 1)

MakerSpot Breadboard Power Supply Board Module 3.3V/5V Dual Voltage - 2 Pack
https://www.amazon.com/gp/product/B07L84QZTY/
$6.00 each (only need 1)

Teensy Parts Total
~$42.00

XBOX Wireless Controller Specific Items
(I used this because I already had it. Cheaper / easier options may work. Wired PS3 or Wired Xbox360, etc.
I tried a third party wired PS3 controller and its buttons / joysticks were all read wrong by teensy.
That’s almost certainly fixable if you know where to modify code in the teensy library)

Microsoft Xbox 360 Wireless Receiver for Windows
https://www.amazon.com/Microsoft-Xbox-Wireless-Receiver-Windows/dp/B000HZFCT2
$57.99

Xbox 360 Wireless Controller
https://www.amazon.com/Xbox-360-Wireless-Controller-Glossy-microsoft
~$30.00

Late Generation Samsung Android Tablet Specific Items

(listing this because it’s an unusual cable that you likely don't have)
Cable Matters USB C to Micro USB Cable (Micro USB to USB-C Cable)
https://www.amazon.com/gp/product/B00UUBRX0Y/
$7.48

Apple iPad Specific Items

Lightning to USB 3 Camera Adapter
https://www.apple.com/shop/product/MK0W2AM/A/lightning-to-usb-3-camera-adapter
$39.00

You will also need to buy jumper wires, a soldering iron, and probably an xacto knife if you don’t have them.
 
Last edited:
Just a quick update. I added an lcd touchscreen to this project and added support for reading configurations from an SD card.

My friend who is an industrial designer by trade made a case for all of this. Here are some pics of the mold that will be used for injection manufacturing (I have that term wrong probably).

E0C53E73-674F-44A6-B2C5-4AAAF79F0E17.jpg
EA62EE2E-6B1D-473D-8A5B-8255887D5D38.jpg
 
Back
Top