I'm a beginner and took on this project to make sim racing pedals. I'm using this library by MHeironimus: https://github.com/MHeironimus/ArduinoJoystickLibrary
I managed to understand the library and setup a potentiometer to an axis and use it in games but if I declare multiple axis ex: x for throttle, y for brake, if I turn the throttle, both x and y will move.
Also throttle, brake and clutch do not appear in the game (beamng). I think the problem is not the code but Windows, I read somewhere that I should deactivate "combined pedals" ? Thanks.
The problem is the same with the complete code I downloaded from someone who had the same project and did't complain about this issue which lead me to think it is a windows problem.
Appart from this issue, there's a few things I don't understand about his code :
-why does he makes if,else loop to put 0 as 0 as it already is for the throttle ?
-what are the delays for ?
-why does he divide the analog values by 4 ? is 1023 max value not adequate ?
-why does he create this deadzone on the pedal by substracting 127 ?
-What arduino-board are you using?
-Please post a schematic of your wiring (hand-drawn is fine).
-What value are the potentiometers?
-Does the value read by the ADC (analogRead) match the input value to that pin?
How do the axis values behave when you declare multiple axes? Do you get same value for every axis, or do they show different value but the value of every axis changes when you turn the potentiometer?
I had similar situation a while ago. In my case it was classic ADC channel crosstalk due to wrong combination of input impedance and ADC acquisition time.
Hello,
Thank you for all your ideas, I did test some yesterday :
I did the test with 2 instances of joystick, joystickx and joysticky, one axis per joystick. My computer put the device in "non specified" with a warning sign next to it.
I did a test on another computer, same problem
I'm using a guenuine arduino micro with a 10k pot connected the same way as on the jensarduino link.
I used Serial.print to see the values for analogread I get 0 to 1023 for A0 where the pot is connected and 0 for the A1 pin, but the problem is that this is not reciprocated on the computer where it is like the pot is connected to every pins.
If you declare multiple joystick-objects you should use unique HID-report IDs for each logical device. Otherwise the OS will probably get confused when it gets two identical HID-report descriptors.
Joystick_ joystickx(0x03); // Report ID 03
Joystick_ joysticky(0x04); // Report ID 04
I made same system with my arduino micro, two potentiometers connected to A0 and A1, but I cannot reproduce the problem. I get independent values for X and Y axis to both 'Serial.print' and to the OS.
Hello,
I'm sorry, the problem was that I did not connect anything on A1, I just connected a pot on both axis and it just works, I don't know why it shared the values when it should be 0 on A1 pin but it's fine now.
If A1 is not connected to anything, then that explains everything
If a pin is not connected you might expect it to be in ground-state, but in fact it is in floating-state, it will take whatever random value it pleases. This is why you should generally avoid reading values from unconnected pins.
In case of unconnected ADC pin we get another problem. During the ADC measurement the sample-and-hold capacitor gets charged to the voltage in the input-pin (e.g. A0). When we measure a different channel the capacitor is connected to a different input-pin (e.g. A1). What happens when this input-pin is not connected to anything? The capacitor tries to retain the voltage it currently has, which is the something close to the voltage of the last measurement.
Check out the ATmega32U4 datasheet section 24.7.1 and fig. 24-9 for more details.
If for some reason you want to always read value 0 from pin A1, just connect it to ground.
Okay, thank you for your help, I have to learn more about those micro controllers if I wish to do things on my own like that, it's better to stick with what worked for others otherwise when you don't know. Anyway, thank you all for your help, I have other projects involving arduino, so I may come back. See you soon.