USB Joystick with Teensy 3.2: Which voltage for pots?

Status
Not open for further replies.

reibuehl

Member
Hi all,

I am trying to convert an old analog joystick to USB. I currently use the "Basic USB Joystick" example from Teensyduino. I have the two buttons already working but I am unsure how to wire the two potentiometers - should I use the Vin pin or one of the 3.3V pins to power them?

Best regards,
Reiner
 
hi reibuehl

you should wire one end to 3.3V the other end to gnd and the middle pin (the wiper) to one of the Analog input pins.

do you know what value the pots are?

if you find the input jumps around a bit you can add a small capacitor between the wiper and gnd. also the library ResponsiveAnalogRead is great for smoothing out pots

cheers Paul
 
Hi Paul,

the old wiring did not have a ground connection. It just had +5V from the game port on one end and the wire back to the game port on the middle wiper. So I will add ground to the currently not connected ends.

The pots don't have a value printed on them but they measure at 1.147 k each. So I guess they are 1.2k or 1k nominal.

Best regards,
Reiner
 
Hi Paul,

I connected the pots as adviced but the analog values I read are only between ~660 and 1023. Shouldn't I get a bigger range?


Best regards,
Reiner
 
hi Reiner,

You should aim to get the full range from 0 - 1023, are there any resistors in series with the pots?

could you post a picture to get an idea of what you're dealing with

cheers Paul
 
hi Reiner,

You should aim to get the full range from 0 - 1023, are there any resistors in series with the pots?

could you post a picture to get an idea of what you're dealing with

cheers Paul

The pots have no resistors in series, they where connected directly to the respective pins on the 15-pin D-Sub game port connector. I made some pictures of what I have right now:

20200809_112244.jpg20200809_112318.jpg

The cable color and connections:

DSub PinColorDescriptionTeensy Pin
1Orange5V3V3
2BlackButton1D0
3WhiteAxis1A0
4GreenGNDGND
5n/cn/cn/c
6BlueAxis2A1
7BrownButton2D1
 
Hi Reiner,

Your wiring looks ok.

The pot will be expecting to turn about 270 degree to get the full range, from the picture I don't think that mechanism will be able to turn the full range so your 660-1023 may be as good as you will get?

You can use the map function to re-map your available range (660-1023) to something else (say 0-255) e.g. x_new=map (x, 660, 1023, 0, 255);

cheers, Paul
 
It has been awhile since I did a remote control using joysticks... Lots of fun.

Not sure how easy it is to do, but what happens if you switch which one is 3.3v and which one is GND. What range do you get then? If you get a lower range like, 0-660 or some such thing then you might check to see what voltage range you get if you instead use 5v. If the top end does not then exceed 3.3v you might get a slightly larger range. And as your 3.2 is 5v tolerant, it should not hurt your unit, EXCEPT if you try to use one of the Analog only pins, which is NOT 5v tolerant.

Looks like fun!
 
Hi Reiner,

Your wiring looks ok.

The pot will be expecting to turn about 270 degree to get the full range, from the picture I don't think that mechanism will be able to turn the full range so your 660-1023 may be as good as you will get?

You can use the map function to re-map your available range (660-1023) to something else (say 0-255) e.g. x_new=map (x, 660, 1023, 0, 255);

cheers, Paul
Thought I would mention that when I did some of my remote control work, like updated firmware for the Arbotix Commander or for a DIY remote control, I did the mapping of the analog input data two different ways, depending on if the joystick axis was centering or non-centering (throttle).

The code had a mode to turn on a calibration mode, where I move all of the different joysicks, pots, sliders...) from top and bottom of range. Note on joysticks I would typically go only up/down left/right and not the different diagonal ones as I wanted moving straight up to give me the full max (or min)... And for the centering axis, I would also capture the rest positions...

Also note, in the old code, I would keep running sums for the last N samples (in the one I looking at 8)...

As you mentioned doing USB joystick I think. I believe the range for them is 0-1023 (10 bit)

My Joystick reading would after getting the new value (in my case the sum/8), I would check to see if value > MAX_FOR_THAT_AXIS and set output to 1023 (or 0), likewise if < MIN.. set to 0(1023)

As @houtson mentioned for throttle like axis I would do something similar to what he mentioned other than I would change to: x_new=map (x, 660, 1023, 0, 1023);

For centering like joysticks, depending on how accurate it always comes back to logical 0, I would have a settable (either hard coded or user changeable) center slop factor.
And then if (VAL-MID_POINT) < SLOP_VALUE then set output to 512

Also ran into issue where Center point was not truly center of range. So I would do two mapping. Something like:
if (x < center) new_x = map(x, min, center, 0, 512);
else new_x = map(x, center, max, 512, 1023);


Again sorry if this is not related to what you are asking.
 
Hi Reiner,
You can use the map function to re-map your available range (660-1023) to something else (say 0-255) e.g. x_new=map (x, 660, 1023, 0, 255);

Thanks! That was a great idea. I implemented it now with a map and now the values I see in the Windows Gamepad Setup utility correlate fairly well with the actual joystick position. That is good enough for the moment :)

Best regards,
Reiner
 
Status
Not open for further replies.
Back
Top