Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 10 of 10

Thread: USB Joystick with Teensy 3.2: Which voltage for pots?

  1. #1
    Junior Member
    Join Date
    Aug 2020
    Posts
    5

    USB Joystick with Teensy 3.2: Which voltage for pots?

    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

  2. #2
    Senior Member houtson's Avatar
    Join Date
    Aug 2015
    Location
    Scotland
    Posts
    135
    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

  3. #3
    Junior Member
    Join Date
    Aug 2020
    Posts
    5
    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

  4. #4
    Junior Member
    Join Date
    Aug 2020
    Posts
    5
    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

  5. #5
    Senior Member houtson's Avatar
    Join Date
    Aug 2015
    Location
    Scotland
    Posts
    135
    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

  6. #6
    Junior Member
    Join Date
    Aug 2020
    Posts
    5
    Quote Originally Posted by houtson View Post
    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:

    Click image for larger version. 

Name:	20200809_112244.jpg 
Views:	8 
Size:	155.1 KB 
ID:	21325Click image for larger version. 

Name:	20200809_112318.jpg 
Views:	11 
Size:	108.6 KB 
ID:	21326

    The cable color and connections:

    DSub Pin Color Description Teensy Pin
    1 Orange 5V 3V3
    2 Black Button1 D0
    3 White Axis1 A0
    4 Green GND GND
    5 n/c n/c n/c
    6 Blue Axis2 A1
    7 Brown Button2 D1

  7. #7
    Senior Member houtson's Avatar
    Join Date
    Aug 2015
    Location
    Scotland
    Posts
    135
    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

  8. #8
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    7,903
    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!

  9. #9
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    7,903
    Quote Originally Posted by houtson View Post
    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.

  10. #10
    Junior Member
    Join Date
    Aug 2020
    Posts
    5
    Quote Originally Posted by houtson View Post
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •