Monday, September 07, 2015

Linux Support for Arduino Leonardo / Micro USB Game Controllers

A few months ago I posted an article that described how 3 USB game controllers could be added to the Arduino Leonardo and the Arduino Micro. Out of the box, they look like a USB serial port, keyboard, and mouse to the host computer, but with these modifications they can also look like 3 game controllers. This works great on Microsoft Windows (I have tested it on 7, 8.1, and 10), but it does not work on Linux.

If you plug the modified Arduino Leonardo or Arduino Micro into a machine running Linux and do a listing on the input devices, you will see the Arduino mouse, but not the joysticks.

Before Plugging in the Arduino Leonardo or Micro


After Plugging in the Arduino Leonardo








After Plugging in the Arduino Micro








To get this to work on Linux, you need to adjust a setting on the usbhid driver. This can be done by editing the /boot/cmdline.txt file. Add the following string to the end of the line of text in this file (there should only be one line of text in this file):

For the Arduino Leonardo

usbhid.quirks=0x2341:0x8036:0x040

For the Arduino Micro

usbhid.quirks=0x2341:0x8037:0x040

Explanation

0x2341 is the Vendor ID for Arduino
0x8036 is the Product ID for the Leonardo
0x8037 is the Product ID for the Micro
0x040 indicates the Multiple Input “quirk” should be used (i.e. HID_QUIRK_MULTI_INPUT)

Example







After changing the /boot/cmdline.txt file the Linux machine will need to be rebooted. You will need to have root privileges to edit the /boot/cmdline.txt file. Now when the modified Arduino Leonardo or Arduino Micro is plugged in, three new joysticks will appear.

After Applying Setting – Arduino Leonardo













After Applying Setting – Arduino Micro













3 comments:

farro said...

Thank you!

Unknown said...

Hi Matthew

I recently purchased a gaming handbrake from eBay (Ardunio Leonardo based) which works perfectly in Windows, however Linux does not recognise any input when moving the handbrake back and forth.

Posting the above text to the /boot/cmdline.txt file does not appear to work as a fix in Ubuntu 20.04LTS running on a desktop.

"ls /dev/input/by-id" currently gives me the following output:
usb-Arduino_LLC_Arduino_Leonardo_HIDFH-if02-event-joystick
usb-Arduino_LLC_Arduino_Leonardo_HIDFH-if02-joystick

Any ideas of how to get this working would be much appreciated.

Harry

Matthew Heironimus said...

I would try the suggestion listed on the Wiki and see if that addresses your issue: https://github.com/MHeironimus/ArduinoJoystickLibrary/wiki/FAQ#linux-support.