Sketch help DIY project 3/4 working. DIY throttle

Hello,

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 have a Pro Micro 5V 32U4

I have the latest version of IDE

This is the throttle I am trying to get working Flight Simulator Throttle Quadrant by Shoyun - Thingiverse

This is the sketch [Throttle Quadrant Code - Pastebin.com)]

I also have the GitHub - MHeironimus/ArduinoJoystickLibrary: An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support. added to my IDE

I've tried yt vids, and seeking help on other forums. With help I was able to verify and upload the sketch. But the issues still persist.

Thanks for reading.

Grab your sketch, format it, use the <CODE> button in the Reply box, and paste your code where you see "paste your code here"

Select your board and port, using:
IDE >> TOOLS >> BOARD >> AVR BOARDS >> your board (Arduino Micro?)
IDE >> TOOLS >> PORT >> your port

Hi,

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);
}

What does that mean?

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.

Replace or repair the controller.

Thanks everyone for your responses.

I wonder if it is the board. Bad circuits/boards happen. Would anyone be able to suggest a good 5V 32U4 pro micro?

Thanks everyone.

Seldom, approaching never. Joysticks (which seems to be the topic) are known to break under abuse.

The one you own... unless it has an undisclosed issue.

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.

Can you swap wires around to see if it is the one potentiometer, or what the potentiometer is connected to?

You could also try two other analog inputs.

You could add serial printing to see what the analog inputs are getting.

a7

Hello,

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.

Thanks

Example here: ArduinoJoystickLibrary/examples/JoystickTest/JoystickTest.ino at master · MHeironimus/ArduinoJoystickLibrary · GitHub

// Set to true to test "Auto Send" mode or false to test "Manual Send" mode.
//const bool testAutoSendMode = true;
const bool testAutoSendMode = false;

Prototype here: ArduinoJoystickLibrary/src/Joystick.cpp at master · MHeironimus/ArduinoJoystickLibrary · GitHub

Also in the prototype (link above) are what these arguments are for...

Joystick_::Joystick_(
	uint8_t hidReportId,
	uint8_t joystickType,
    uint8_t buttonCount,
	uint8_t hatSwitchCount,
	bool includeXAxis,
	bool includeYAxis,
	bool includeZAxis,
	bool includeRxAxis,
	bool includeRyAxis,
	bool includeRzAxis,
	bool includeRudder,
	bool includeThrottle,
	bool includeAccelerator,
	bool includeBrake,
	bool includeSteering)

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 again!

So, I have found out that the 2nd handle does not respond. I think that I need to create another entry for non responding axis in the sketch?

Here is the origional circuit diagram. Both pots have power and data so how to separate them? 269.2 KB file on MEGA

Any ideas?

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.

Thanks everyone.