Greetings!
Working on a project where I use joysticks to control the direction and speed of a motor. While writing the code I noticed that the joystick meets it's maximum range values before it reaches its' maximum throw.
It this due to the quality of the joystick? I am using the analogRead command, is there a better command to use?
Would appreciate any help.
Tinkerman @tinkerman,
You mentioned a joystick, but nothing else. If it is a joystick with just contact switches, it's just off and on... no real values except for 0x0000 and 0xffff.
Try looping and displaying the results of the analog read command, as you go through the range of the joystick, and you will most likely know (or be able to get help) how to proceed.
Best,
Frank
Working on a project where I use joysticks to control the direction and speed of a motor. While writing the code I noticed that the joystick meets it's maximum range values before it reaches its' maximum throw.
It this due to the quality of the joystick?
Probably, but it may be poor construction of the joystick itself (was it a cheap product ?).
There are several alternatives, all unpleasant. You can a) try a higher quality (cost) joystick; b) glue a barrier onto your existing joystick so that the travel and potentiometer match, c) make a do-it-yourself joystick with a potentiometer, d) try taking the joystick apart and carefully repositioning the built-in pot. That last method might work if the stick seems to give a reading before it's moved and stops changing before it finishes. Such behaviour indicates that the pot is mis-aligned.
Using analogRead doesn't matter, it's just reading the effective resistance of the pot and has absolutely nothing to do with the relative positioning of the joystick lever. So its not causing a problem and can't be used to correct the joystick.
Anything seems possible when you don't know what you're talking about.
Hi @tinkerman,
Sorry, I don't have any experience of commercial joysticks, but as @will has mentioned, they usually use a potentiometer, and any of the mechanical defects mentioned sound feasible.
However, if it were mine, as a kind of cross-check, I would start with using a multimeter to measure the voltage that the joystick is sending to the processor changes smoothly over the whole range of movement of the stick, and that all of those voltages are within the range of the analogue-to-digital converter.
Remember, analogRead, does not 'actually' measure resistance, but voltage, so this is using the meter to directly display the voltage that analogRead is 'seeing'.
In particular, if the processor is a 3.3V, make sure the energising voltage provided to the joystick is not 5V.
https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/ lists the Arduino processors that are 3.3V, with other boards like Raspberry Pi Pico, ESP32, ESP8266, also being 3.3V processors.
Note, this is only a 'last chance saloon' check, but it might give you a little more insight into what is happening, and how to fix it.
Best wishes, Dave
@tinkerman If it's a generic stick as opposed to say a Microsoft then I would suspect build quality. Here is a Msft Sidewinder for comparison.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@will Thanks for the suggestions. The joystick I am using is one of those breakout board types. I've used them before for controlling servos, which worked well.
In this case, the values change so quickly that it makes it difficult to do a slow roll up on the motor to maximum speed. I want to use this type of joystick because of the built in switch that allows me to run two motor independently.
I think I paid $5 each. Would you be able to suggest a better one?
@tinkerman It's simple mechanics, the shorter the stick the faster the numbers will change.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@zander Understand that part of the mechanics, just trying to figure out the slack.
@tinkerman $5.
I think I have a few of those sticks, so if my heart is up to it tomorrow I will test all of them and report back.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@davee Thanks for the suggestions. I measured the voltage with the multimeter and it appears to be pretty smooth over a specific range, the voltage just tops out at the halfway point in either direction.
I'm thinking of trying a different type of control using a slide potentiometer.
I think I paid $5 each. Would you be able to suggest a better one?
Sorry but I can't make a recommendation. I don't ever recall buying a joystick.
Anything seems possible when you don't know what you're talking about.
Hi @tinkerman,
When you added the photo, I realised I had a couple of them in my 'spares' box, which I had added to an AliExpress order, to look at on a rainy day.
As the weather looked like it might rain, I rigged up a simple test with 6V battery and multimeter, and found the same as you did. They seem to be made with a weird potentiometer that gives a relatively wide mid-section, with almost no change; then a narrow section either side of the mid-section, which goes from 50% to 0%, or 50% to 100%, and outside of those sections, a pair of wider sections, which are either all 100% or all 0%. So the only parts with a graduated change, are two very small angle sectors, of maybe 10 degrees each.
So, in spite of looking to be 'fairly' well-made, their utility seems limited. However, I only paid about US $1 for a pair (including delivery), so I don't have too much to complain about.
I realise that you found the built-in switch convenient, but I notice Ali-Express also do larger joysticks, which superficially look like the type I have seen on radio control transmitters, etc. They are a variety of (higher) prices, but might be better if you wanted control in 2 dimensions, but maybe not including a switch. Sorry, I have no experience of them, nor do I have any in the 'spares' box.
Good luck with your quest. Dave