Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Arduino Joystick Library Download

213 views
Skip to first unread message

Tristan Ridings

unread,
Dec 31, 2023, 9:21:57 AM12/31/23
to
An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support. - GitHub - MHeironimus/ArduinoJoystickLibrary: An Arduino library tha...


That library has nothing to do with emulating a USB joystick and is the wrong library for your sketch.

Since both libraries use the name "Joystick.h" you will have problems if you install both. I would delete the current library and install the correct one.



arduino joystick library download

Download https://riru-aplorzo.blogspot.com/?kcn=2wZSsp






But I did discover that the multiaxis joystick specification is frought with trickiness. Specifying it results in a new device descriptor to windows. This results in the device getting a different com port after its flashed. After a few different changes the number of device descriptors increases and this results in weird behavior. I would get the Arduino in the USB game control panel but it would be totally unresponsive. Sometimes the port numbers would change unpredictably- The pro micro would start out on port 17. During the flash it would change to port 4 and then it would be recognized as port 12. These port numbers were erratic and this happened when I was changing the hidReportId and the joystick type.The documentation states


Default: 0x03 - Indicates the joystick's HID report ID. This value must be unique if you are creating multiple instances of Joystick. Do not use 0x01 or 0x02 as they are used by the built-in Arduino Keyboard and Mouse libraries.


your correct, that should be a 4. The code came from a guy (Jens) who made the same project, however he used an earlier version of the Joystick library. I have tried to earlier version of the library, but the resolution seems lower, and the results are still the same. That being said, I have simplified it, but still same results.


Ken Bou - The Windows Game Controller Test dialog only shows 7 axis, but there can be more than that (for games and applications that support it). You will need to use a third-party joystick test application to see over 7 axis. One I have used in the past can be found at -test-application/.


Matt, sorry to comment on an older post, but I've been at this a few days and am stuck. My first problem was I was using version 1 of your sketch, but that's fixed now. :)



Pretty much what I want to do is disable all the axis and hat so I can have 20 buttons. I can petty much do that, except whenever I press any button the "16" button presses and remains pressed. Also, the X, Y and Throttle move from 100% to 0 and the x/y axis moves back to 0 from center. I can turn all these off in joystick.h as you described with the true/false statements, only I still have the button 16 problem. It looks like my buttons are showing up as 1-15 and then 19-20.



I don't recall having this issue in version 1 but, I couldn't get the axis and hat to disable.



Can you get me pointed into the right direction? Thanks! (Leonardo R3, if it matters)


Hi Matthew and many thanks for the Joystick Library v2.0



Rather than waffle on at length here, I will post a link to my unanswered question on Arduino forum



=468358.0



I have almost -- but not quite -- got the hang of HID joystick emulation :-) I can make my Arduino actuate a selected axis, no problem; but I have not figured out how to expose all the axes to the application level, or how to make them map to the axes that any given game is expecting to find when the user configures input devices. I think I'm just one key concept away from enlightenment here... can you point me at an article or document that will make that last connection for me?


Hi Matthew, I'm in the process of building my own little Raspberry Pi based retro gaming console and your library will be of great help. Awesome work!

I've got one question though: The standard joystick constructor has 32 buttons. How would I get 32 buttons from the pins of an Arduino (Micro) (or a Pro Micro)? The only way I can think of would be to map multi-button-pushes/pin activations to single (API-level) buttons. Or am I missing something?

Also, let's assume I would like to switch between Joystick and Mouse input using the same controller (and thus the same buttons and joysticks/d-pads). Would it suffice to just send different commands/call the right functions (like Mouse.move(...), Mouse.press(...)) instead of the Joystick commands? Or is there something that has to be done with the HIDs?


All of this is daunting to me Matthew. My goal is to use this in my button box creation. Is it possible to have 28 - 30 button presses and 2 analogue stick using an arduino pro micro? And how do I best go about learning what I need to accomplish?






A found one of those rookie mistakes I mentioned... I didn't check the serial monitor...



So it seems My joystick is outputting X and Y axis as intended to the serial monitor, but what do I need to change so that I can see my actions on the Windows game controller settings panel?


Patrick McEnaney



One thing I have noticed is you set the X and Y axis range to go from -512 to 512, but Arduino analog pins go from 0 to 1023 by default. This happens to be the default for the Joystick library, so you should be able to remove those lines.



Another thing to watch for is you need to have a delay in your loop or you can "overload" things. Adding a delay(50); might be a good idea.



Note: The Windows Game Controller Settings panel will only update if it has focus.



Have you tried using any of the example projects that come with the library?


Thanks for the reply.



I'll remove the axis range, since I guess it isn't needed, but being new to this, where exactly should I add the delay in my code?



And yes, I've fooled around with the example files, and had them working just fine in the Game Controller Dialog (except for some reason the button set to PIN 10 isn't working, and I'm not sure why; I've tried with two different joysticks, so my next step is to try a different pin, in case PIN 10 might by faulty on my board), but couldn't figure out how to adapt them to my use-case, so I figured starting from scratch was my best bet. I'm not sure what I'm missing that's causing my sketch to not work in the dialog though...


Adding a delay seems to have fixed my joystick axis (although I still don't exactly understand why, lol). But now my issue is that both of my buttons are stuck in the "ON" state, and pressing them doesn't do anything. I tried switching `if (button1State = 1)` to "0", but that just makes them stuck in the "OFF" state. Where am I going wrong with this part?



Also, I added a delay on the buttons too, is this necessary?



Thanks


Hi Matthew, I've got my simple joystick working but now I'm having issues with my 2nd project with your library. I'm using the same code that I got working with my joystick, but modified it to have a total of 8 buttons and 2 axis for a custom gamepad I've made. Everything worked exactly as planned at first, but the 2nd time I plugged it in I'm getting random twitchy movements on the thumbstick (which seems to favor the bottom-right corner) and most of the time "button 8" is stuck in the "ON" position, with 3 other buttons behaving erratically. "Button 8" is also stuck "ON" if I power up the board without even connecting my buttons to it.



I know my code is fine, because it worked exactly as intended at first, but all of a sudden it's behaving very erratically.



If I plug my joystick into the board, and reupload my original code for the joystick it works fine. It just seems to behave this way when I switch to my 8-button/2-axis sketch.



Any ideas? I've triple-checked my code, and there shouldn't be any issues there (as I said, it was working at first and I've made no changes to the code since).



Thanks,



Patrick


Yet another question Matthew...



I didn't see it listed anywhere on GitHub, but I'd like to add a deadzone to my joystick (same sketch as listed above), but I'm not sure if it's possible with your library or not.



My theory was that if I set 'autosendstate' to 'false' and wrote an 'if' statement that would poll my joystick to see if either axis was outside of my desired deadzone and 'then' either 'Joystick.begin()' or 'Joystick.sendState()' else 'break' or something similar.



Am I on the right track?



Thanks.


I don't know if this is related to your work, but I've come across some Arduino-based joysticks/adapters where in DirectInput the reported X axis range is 0-0 for buttons (instead of, say, 0-65535). That is not considered a valid range by some apps.



I am trying to establish whether there is an issue in interpretation, in hardware or in drivers. Any thoughts?


Hi Matthew

I am looking to create my own rudder pedal set and your code looks ideal (I'm definitely not a programmer, simply a user/adaptor). I have loaded your code and tried to compile the test programmes but get an error that the #include cannot be found. I note that the dynamicHID.h is not included in the joystick sketch code but is referenced in the Joystick.h file. I also note that the dynamicHID.h file is included as part of the download from GitHub. I've tried relocating the dynamicHID.h file into different folders to see if the compiler picks it up without success.

Any guidance would be appreciated.

Martin


Martin,



The error you describe usually is a result of the library not being installed correctly. When you open the Arduino IDE, click on File -> Examples and scroll to the bottom of the list. You should see an entry in the "Examples from custom libraries" section called Joystick. Another thing to check is the "Library Manager" (Sketch -> Include Library -> Manage Libraries...). If the library is installed correctly, you should see an entry called Joystick by Matthew Heironimus Version 2.0.5 INSTALLED. If either of these things are not present, the library was not installed correctly. Installation instructions can be found at -instructions.



Hope this helps,

Matt

35fe9a5643



0 new messages