Arduino zero Joystick / Arduino zero HID / Arduino zero USB

Topic re-named for better visibility when searching for this problem.

Original problem: all well known HID joystick libs don't compile for zero
solution: this one does -> GitHub - controllercustom/JoystickWin: Arduino USB Joystick for Windows
additional problem: all HID/USB/keyboard/etc libs on zero fail to be recognised properly by windows
solution: see ptillisch's solution below

Thanks again to ptillisch for your assistance and expertise.

Arduino does, to my knowledge, not have an official joystick library. The fact that can find it here (https://docs.arduino.cc/libraries/joystick/) does not mean that it's an official library. Do you have a link to the library involved?

Maybe tell us which turns you took?

We can only hope that one day the Arduino team will develop some kind of board compatible with standard HID functionality.
but why on earth some who will want ever do joystick out of Zero, one board so big and expensive as some gamepads in the electronic store?

fair enough it was listed as "the joystick library" on the arduino docs but it may not be official.
attempting to compile it get missing USB/PluggableUSB.h errors, so i manually added that lib and its .cpp component. which just gets me missing DynamicHID errors so i manually added that libs and its .cpp component. which gets me missing USBHID errors. this went on and on and on so i got pissed off and manually included every single usb,hid,api,and core serial file in the arduino IDE (about 30 of them) to the joystick.h file, this actually stopped the missing file warnings but then i got endless "such and such was not defined in this scope" warnings which should be impossible as every core file written for the zero was included at this point. so i spent an entire day going down the list and manually adding all the missing definitions only to be met with errors saying that the data types of variables (that were written by the arduino team, ie; core lib variables) was incompatible or couldn't be compiled for the zero. if this code could feel pain i would have thrown it in a vat of acid by now

because its faster and more powerful than a mega, and the ATSAMD21G18A is a quarter the size of the mega chip and a quarter the price of the mega chip so when you design custom pcbs like i do its a great option.

are you planning entire airbus cockpit work with one single chip? i heard never someone was saying arduino micro/pro/leonardo is too slow for joystick.

its running two displays, audio playback, black box, and a bunch of other stuff simultaneously. so yes my code wouldnt even fit on a mega let alone a tiny little leonardo

sounds expensive. may be you hire someone to write HID lib for you.

good idea, i just put a bounty on it

I installed that library and compiled the example.

But I suspect that I'm missing something.

Hi @incognacho. Here are two libraries for making an Arduino board emulate a USB HID gamepad/joystick that appear to work with the Zero from a quick test I ran on my Windows machine:

HID-Project

This one is available for installation via the Arduino IDE Library Manager. Just search for HID-Project.

After installing the library, you can open an example sketch that demonstrates the use of the library by selecting File > Examples > HID-Project > Gamepad from the Arduino IDE menus.

JoystickWin

Despite the "Win" in the name of this library, and the "for Windows" in the primary description, the documentation and previous experiments with this library indicate that Arduino boards running sketches using this library are works just as well on Linux machines. I don't know about macOS, but there is a good chance it will work on that operating system as well.

This one is not in Library Manager so you'll need to download the library and then install it via Arduino IDE's "Add .ZIP Library..." feature. I'll provide instructions for doing that:

  1. Click the following link to open the library's GitHub repository homepage in your web browser:
    https://github.com/controllercustom/JoystickWin
  2. Click the "Code ▾" button you see on that page.
  3. Select Download ZIP from the menu.
    A download of the ZIP file of the library will start.
  4. Wait for the download to finish.
  5. Select Sketch > Include library > Add .ZIP Library from the Arduino IDE menus.
    The "Select the zip file containing the library you'd like to add" dialog will open.
  6. Select the downloaded file from the dialog.
  7. Click the "Open" button.
    The dialog will close.
  8. Wait for the installation process to finish, as indicated by a notification at the bottom right corner of the Arduino IDE window:

    ⓘ Successfully installed library from ...

After doing that, you can open an example sketch that demonstrates the use of the library by selecting File > Examples > JoystickWin-main > JoystickWin from the Arduino IDE menus.

@ptillisch , thank you for those recommendations, i appreciate you taking the time to test them on your machine however i have to assume you only tried to compile, not upload them as neither work unfortunately. they both looked very promising though.

while both compile for the zero (i guess that's progress) neither actually shows up as a joystick, and the keyboard examples on nicohoods library actually dont compile, similar issues to every other lib i have tried (undefined variables, missing definitions, redefinitions etc)

I tried completely removing the IDE from my computer and manually hunting down and deleting all cache files, libs, core file, install files, config files, and history files for the IDE since windows uninstaller only deletes the executable. And installing a fresh copy of IDE 2.3.3, then reinstalling the libs you recommended and trying again, i also tried on three separate zero boards just in case of a hardware failure. no luck, strangely both libs cause the single arduino zero connected to my windows machine to show up twice (on two separate com ports as two unique zero boards) so perhaps the code is in-fact sending the joystick data but is failing to identify itself as a joystick/gamepad.

to my knowledge no one has ever gotten a joystick lib to work properly on a zero before despite multiple joystick libs claiming to be compatible. someone DID get a seeeduino "xiao" (SAMD21) to work but they never explained how.

No, I uploaded the sketches to my board and then used the Windows "Game Controllers" utility to verify that the sketch was producing a game controller device and that the axis movements and button press behaviors of the game controller device were as expected for the sketch.

I also ran into this, but was hoping you would not. The problem is with the Windows drivers. For some reason the inappropriate "usbser" driver is installed for the board. The driver we need is the Windows built-in "HidUsb" driver.

Please try this:

  1. Connect the Zero board to your computer with the USB cable.
  2. Open the Windows Device Manager.
  3. Select View > Devices by type from the Device Manager menus.
  4. Open the "View" menu.
  5. If there is a to the left of the "Show hidden devices" menu item, click on "Show hidden devices" to disable it.
  6. Find the problematic device in the Device Manager tree (it will probably be under "Ports (COM & LPT)" section).
    :warning: The Zero will produce two devices. One of these is a functional USB CDC serial port. Make sure to select the other device.
  7. Right click on the problematic device.
    A context menu will open.
  8. Select "Uninstall device" from the menu.
    The "Uninstall Device" dialog will open.
  9. Check the "Attempt to remove the driver for this device" checkbox.
  10. Click the "Uninstall" button.
    The dialog will close.
  11. Disconnect the USB cable of the Zero board from your computer.
  12. Connect the Zero board to your computer with the USB cable.
  13. Wait to see if the problematic device appears once again. If so, repeat steps 6-13 again until the problematic device no longer appears.
    I believe it is necessary to do this multiple times in cases where multiple installations of the "usbser" driver have been made for the device.

After doing that, the Zero should now be recognized as a game controller.

I only tried the Gamepad example. For keyboard emulation I recommend using the official "Keyboard" library, which is installed as part of the Arduino IDE installation:

https://docs.arduino.cc/language-reference/en/functions/usb/Keyboard/

You will find a collection of example sketches that demonstrates the use of the library under the File > Examples > 09.USB > Keyboard menu in Arduino IDE.

I encountered the same problem with the keyboard emulation as we did with the game controller emulation:

Uninstalling the driver also solved that problem.

As I said above, I did. I didn't do testing beyond a quick check of the basic functionality though.

1 Like

@ptillisch good lord that actually worked, all right I'm a man of my word, how do you take payments?

I would strongly recommend posting that solution and the libraries you recommended in a fresh topic for future users to find as this seemed trivial for you however evidently from the github, element 14, and reddit forum discussions going back almost a decade the problem of finding a joystick lib that works / getting the computer to recognise said joystick on zero has been attempted by hundreds of people over the years with no success.

Thank you again for your time and assistance

I'm glad it is working!

I appreciate the offer. I don't need any payment more than knowing I was able to be of some assistance. However, if you want you can contribute to the people who made the much more significant contribution by writing these useful libraries. Unfortunately, I don't see a way to contribute to @customcontroller for their "JoystickWin" library. However, NicoHood, the developer of the "HID-Project" library (as well as other valuable contributions including work on the official "PluggableUSB" and "PluggableHID" code) does accept donations via the "Buy Me a Coffee", Patreon, and GitHub Sponsors services. There are links to each of the donation options under the "Sponsor this project" section of the library's GitHub page:

And donations to Arduino to support our work on free open source software, hardware, and documentation are always welcome:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.