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

Thread: Using a 10k Potentiometer as Steering Wheel with teensy 3.1

  1. #1
    Member
    Join Date
    Feb 2014
    Location
    Brazil
    Posts
    41

    Using a 10k Potentiometer as Steering Wheel with teensy 3.1

    I have a spare Teensy 3.1 and I would like to use a 10k potentiometer as a steering wheel.

    I put the board in mode "Keyboard + Mouse + Joystick" but I can't see in the library documentation how I can use the 10k Pot as Steering Wheel.

    The Joystick class is the same used in Arduino? Or this library has own methods?

    Anyone can guide me?

    I know the 10k Pot is not the correct part to use for this project, but it's what I've in hand for now... In the future I'll buy and encoder.

    Thanks!

  2. #2
    If I understand correctly when the pot is 12 o'clock (I'll call this zero) you want the wheels straight, when the pot is say 3 oclock you want them right, and 9 oclock to the left correct?

    What do you want the values of center, left, and right to be?

    maybe this?


    float bits = 0.0;
    float right = 10.0, left = -10.0;
    float out = 0.0;

    bits = analogRead(YOUR_PIN_CONNECTED_TO_POT);

    // assuming you are using default analogReadResolution giving 10 bits (0-1024)
    // ground to left pot pin, 3v3 to right pot pin
    // change -10 and 10 to the values that represent left and right signals
    out = map(bits, 0.0, 1024.0, left, right);
    Serial.println(out,3);

    Hope this helps.

  3. #3
    Senior Member
    Join Date
    Feb 2016
    Location
    Australia
    Posts
    293
    I imagine this would get you started:
    https://www.pjrc.com/teensy/td_joystick.html

  4. #4
    Member
    Join Date
    Feb 2014
    Location
    Brazil
    Posts
    41
    Hi KrisKasprzak, I'll try this code and see if it works as a Joystick.

    Hi Gibbedy, this is one of my questions, this library is the same used in Arduino and I can cofig the joystick as steering? I can't find this specific information in the docs.

    Thanks again.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,656
    Quote Originally Posted by hexodin View Post
    this is one of my questions, this library is the same used in Arduino and I can cofig the joystick as steering? I can't find this specific information in the docs.
    It is not identical to Arduino's HID libraries. But hopefully you can see clearly how to use it?

    In Arduino IDE, click File > Examples > Teensy > USB_Joystick for example programs to get started. They can also be accessed online with these links

    https://github.com/PaulStoffregen/Te...asic/Basic.ino

    https://github.com/PaulStoffregen/Te...ns/Buttons.ino

    https://github.com/PaulStoffregen/Te...e/Complete.ino

    The usage specific to steering depends on software running on your PC (or Mac). It may even be different depending on which specific software you run. Some software (eg, games) even can have configuration choices to change how the mapping from joystick/gamepad to actual control works.

    The main point is you won't find anything specific to steering in any particular game or motion simulator on the Teensy side. You'll use functions like sending the X or Y or Z or Zr axis. Then software on your PC maps that sensor data to the concept of a steering wheel as is needed for the specific PC software.

    While you're still experimenting and learning, I would recommend first testing with the Joystick control panel in Windows or "jstest" on Linux. These can show you clearly and plainly what your PC is really receiving.

  6. #6
    Member
    Join Date
    Feb 2014
    Location
    Brazil
    Posts
    41
    Thank you Paul, now I've a base to start. I'm already trying with jstest.

    I'm trying to build a steering wheel to my 6 years old son to play Truck Simulators(American/Euro). I already see someone on youtube make this with Arduino Leonardo and 10k Pot, so I have various Teensy boards here, from 2 to 3.2 and I think it's a good project to make.

  7. #7
    Member
    Join Date
    Feb 2014
    Location
    Brazil
    Posts
    41
    I tried all suggestions without success.

    I got something when:
    1. Used the pot to control the movements of a mouse mapping the values to Mouse.move function;
    2. Used the pot to act like the Joystick X;

    In both cases I've to change game settings to mouse or joystick, I can't make the game works with a steering wheel...

    I checked the Arduino Joystick library and in this library you can set the Arduino to act as steering wheel:

    Code:
    public:
        Joystick_(
            uint8_t hidReportId = JOYSTICK_DEFAULT_REPORT_ID,
            uint8_t joystickType = JOYSTICK_TYPE_JOYSTICK,
            uint8_t buttonCount = JOYSTICK_DEFAULT_BUTTON_COUNT,
            uint8_t hatSwitchCount = JOYSTICK_DEFAULT_HATSWITCH_COUNT,
            bool includeXAxis = true,
            bool includeYAxis = true,
            bool includeZAxis = true,
            bool includeRxAxis = true,
            bool includeRyAxis = true,
            bool includeRzAxis = true,
            bool includeRudder = true,
            bool includeThrottle = true,
            bool includeAccelerator = true,
            bool includeBrake = true,
            bool includeSteering = true);
    Code:
        inline void setSteeringRange(int32_t minimum, int32_t maximum)
        {
            _steeringMinimum = minimum;
            _steeringMaximum = maximum;
        }
    Code:
        void setSteering(int32_t value);
    I don't know, but I don't think Teensyduino has those methods.

    It's possible to add this functions? Or create a separate library to use Teensy as steering? Or use the Joystick library from Arduino?

    Teensy has a separate library to deal with Flight Simulator controls, It would be fair to have one for racing, car, trucks(steering wheel) e etc. simulators

    Thanks again.

  8. #8
    Senior Member
    Join Date
    Feb 2016
    Location
    Australia
    Posts
    293
    I pulled a teensy LC out, wired a pot to 3.3V as lc ain't 5v tolerant, and loaded the exact sketch from the example i linked and it worked. The longest time was 4 minutes to get joystick to work in project cars. I didn't have long and can't explain further at the moment but the teensy and libraries wont be your problem. It will be wiring, but more likely joystick calibration/setup.

    Gavin.

  9. #9
    Member
    Join Date
    Feb 2014
    Location
    Brazil
    Posts
    41
    Hi Gavin the connections/wiring are correct, I can debug the results from serial output. Maybe vary from game to game.

    I tested all examples and tested my own code with all objects from Teensyduino USB Joystick without success.

    I have a Teensy LC here and I'll test, but I think it's not the problem.

    In any case, working or not, my suggestion is Teensy make available a library specific for this purpose.

    However, I've a Teensy 2 and a Teensy 2++ here and if I can't use version 3, maybe I can use Arduino Joystick Library with this ATMega from Teensy 2.

  10. #10
    Senior Member
    Join Date
    Feb 2016
    Location
    Australia
    Posts
    293
    I assumed a steering wheel and a joystick were the same thing as far as the computer is concerned.

  11. #11
    Member
    Join Date
    Feb 2014
    Location
    Brazil
    Posts
    41
    Nobody is saying anything different from that, in fact, they are the same thing however, the interfaces are different in such a way that Teensy has a specific library for flight simulators, I see no reason not to have one for rancing/car simulators (support for steering wheel).

    And finally I managed to move the steering wheel using Joystick.Y, however, the joystick is not recognized as a steering wheel and it is not possible, for example, to set the number of degrees.

    This is the minimal code I do and work:

    Code:
    void setup() {
      pinMode(A0, INPUT_PULLUP);
    }
    
    void loop() {
      Joystick.Y(analogRead(A0));
    }
    Here is a image showing the steering wheel works.
    Click image for larger version. 

Name:	joy1.png 
Views:	6 
Size:	100.2 KB 
ID:	30562

    But in this image you see I can't configure the steering wheel (joystick lost)
    Click image for larger version. 

Name:	joy2.png 
Views:	12 
Size:	107.2 KB 
ID:	30563

Posting Permissions

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