This my first Arduino project. And I am stuck. It is a two handle 4 button throttle. Only one handle responds however. The throttle is not recognized in Win 11 Usb Game Controllers. Isnt listed at all.
Ive tried a number of YT vids, and no luck. Sorry if this has been asked before.
In device manager this board shows up under Port coms lpt.
In IDE, the board shows up as Arduino Micro on com # xyz.
I saw that more complex versions of this sketch have been posted here already, but still no luck for me. I can not figure out why one potentiometer responds and the other does not. I may try to replace it. And still no luck with USB game controller.
#include <Joystick.h>
// Create the Joystick
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_MULTI_AXIS, 4, 0,
false, false, true, false, false, false,
false, true, false, false, false);
// Constant that maps the physical pin to the joystick button.
// Pin 2 = Button 1
// Pin 3 = Button 2
// Pin 4 = Button 3
// Pin 5 = Button 4
// Last state of the buttons
int lastButtonState[4] = {0,0,0,0};
void setup() {
Joystick.setThrottleRange(0, 1023);
Joystick.setZAxisRange(0, 1023);
// Initialize Button Pins
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
// Initialize Joystick Library
Joystick.begin();
}
void loop() {
// Read pin values
for (int index = 0; index < 4; index++)
{
int currentButtonState = !digitalRead(index + 2);
if (currentButtonState != lastButtonState[index])
{
Joystick.setButton(index, currentButtonState);
lastButtonState[index] = currentButtonState;
}
lastButtonState[index] = currentButtonState;
}
Joystick.setThrottle(analogRead(A0));
Joystick.setZAxis(analogRead(A1));
delay(50);
}
How do you know that this works or works not?
How do you see what is read from the analog inputs?
All buttonstates should be boolean, not int
(This wil likely not fix your problem).
I kept trying different games one recognized the arduino. I was able to go into settings and see that one throttle arm was responding. The other did not.
The Joystick library sends data over usb to whatever controller?
Is that the way this works? Sorry, but I don't know this library....
What arguments are you supposed to give to Joystick? It seems there are a lot and you might have mixed up some of them...
Please add a wiring diagram and a photo of your actual setup.
Do you have solid connections between the Pro Micro and the joysticks? Pro Micro's generally come without headers, requiring that you do some soldering.
Yes I did solder the pins in carefully. I've looked and they all seem to be ok.
I asked on another forum andit was pointed out that the following could be an issue: 1. Missing Joystick.sendState() calls 2. Auto-send mode might be disabled
I have no idea where to place those in the sketch.
// Set to true to test "Auto Send" mode or false to test "Manual Send" mode.
//const bool testAutoSendMode = true;
const bool testAutoSendMode = false;
Thank you everyone. I will try these. I appreciate the help and patience.
As far as usb game controller is concerned, I found this for the pastebin sketch that I linked to. Code must be changed from JOYSTICK_TYPE_MULTI_AXIS into JOYSTICK_TYPE_JOYSTICK
and now I can see all buttons and both axis in usb game controller.
I am going to redo all the wires that are T joined. I usually solder, but I think it is time to start using crimps. I will keep you informed.
Thanks everyone for reading and your help. I managed to get both handles working in one game. Looks like I may have to use a 3rd party joystick controller for some of my other games.