1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

Teensy LC/Arduino Scripts

Discussion in 'Electronic and hardware generally' started by Nick Moxley, Jan 29, 2017.

  1. Nick Moxley

    Nick Moxley Well-Known Member

    Joined:
    Dec 13, 2013
    Messages:
    2,779
    Occupation:
    Owner/Operator- Moxleys Rantals
    Location:
    Winnipeg Manitoba Canada
    Balance:
    17,054Coins
    Ratings:
    +2,504 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK
    Ah HA i figured something out, I dont think the double presses is a problem, its only different in the regards to how I know the Fanatec "funky switch " to work.....Ive been pressing hard against the Left Right Up and Down stop which im now seeing its Activating the Push button #5. i can get clean signals by pressing on the up down left and right "gently" like you would with a D pad ......so Problem solved as far as im concerned.

    Except one question, Does a rotary normally effect a X/Y slider, or does it just do more individual button presses ? I cant say ive looked into that exactly....like adjusting brake Bias in Assetto, you can do it with button clicks....does/will a game see a rotary in the way I have it set now ? Or do i need the Rotary to do button presses ?


    PS re your debounce idea, I suffer from squiggly line/ohm resistance/curcuit board schematic aphobia. That might as well be written in Arabic, lol

    Jk you made it look pretty simple with the resistors in line and with lables on each..... but overall with the way i have it now, it seems to be working as intended. So is there a specific reason your debounce wiring would be better ?
  2. Nick Moxley

    Nick Moxley Well-Known Member

    Joined:
    Dec 13, 2013
    Messages:
    2,779
    Occupation:
    Owner/Operator- Moxleys Rantals
    Location:
    Winnipeg Manitoba Canada
    Balance:
    17,054Coins
    Ratings:
    +2,504 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK
    Ok now i have a request as i understand how Fanatec might be manipulating the script to get the Direction and the Push button to register a Single button when pressed together. Is that possible you could work out how to do that ? @tadythefish
  3. tadythefish

    tadythefish Active Member

    Joined:
    Jul 8, 2009
    Messages:
    148
    Occupation:
    Process automation engineer
    Location:
    Slovenia
    Balance:
    676Coins
    Ratings:
    +95 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    Rotary encoder in your controller works exactly the same way as an analog slider on a jostick. So how a game sees that slider is out of my area :)
    The rotary encoder in this teensy program doesn't do induvidual button presses. It changes the value from 0-1023 (the same way as a slider) so infact it it seen by the game as an analog value

    Ok let me see if I understand what you are saying... You don't need a slider like it is setup now.. But you want the encoder to act loke this: when you turn in one direction every click of the encoder is a push of one button, but if you turn it in the other direction it acts as if you were pressing two buttons at the same time?
    My debounce way is (for your needs) the same as sotware debouncing if the program is working (the two libraries not interfering with each other) so if everything is working in the test screen in windows there is no need to change the circuit
  4. Nick Moxley

    Nick Moxley Well-Known Member

    Joined:
    Dec 13, 2013
    Messages:
    2,779
    Occupation:
    Owner/Operator- Moxleys Rantals
    Location:
    Winnipeg Manitoba Canada
    Balance:
    17,054Coins
    Ratings:
    +2,504 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK


    No sorry ive confused you.



    The Double button press happens when you push the D pad ALL the way in 1 direction, causing you to click of the push button and what ever direction your pushing the joy stick in. I would like it so that when the teensy sees both buttons pressed, that is then make another button # press as a single button. Which is how im assuming Fanatec setup the Alps to work.

    I will test tomorrow how the Current encoder script works with the games....but have a feeling it wont work as i want.

    I want the rotary function to just emulate another button essentially, Roll left and you get a button press, roll left a bunch of times and it registers each click of the encoder.

    Did i explain that a little better ?


    PS super appreciate the help bud.
  5. tadythefish

    tadythefish Active Member

    Joined:
    Jul 8, 2009
    Messages:
    148
    Occupation:
    Process automation engineer
    Location:
    Slovenia
    Balance:
    676Coins
    Ratings:
    +95 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    Ok didn't get the first part of the message.. But lets go one thing a time :)
    First rotary encoder.... If i get it now every click of the encoder in lests say clockwise direction is triggering one button, and every click of the encoder in the counter clockwise direction is triggering another button :)
    Turning left pulses one button and turning right pulses anothet button (in short) :))

    No problem with helping... You have to know I am learning too ;)
    • Agree Agree x 1
  6. tadythefish

    tadythefish Active Member

    Joined:
    Jul 8, 2009
    Messages:
    148
    Occupation:
    Process automation engineer
    Location:
    Slovenia
    Balance:
    676Coins
    Ratings:
    +95 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    Ok I hope I understanded what you wanted with encoders... I went ahead and edited your code...
    You can download it in the attachment. Please try it out and tell me if this is what you wanted and then we can move on to the button problem :)

    I cleaned up the code a little bit, but it still need some editing (only estetics)
    In the file you will se where I changed parts of the code and added comments so you can better understand what is happening.
    I wrote TadyTheFish where I changed parts (delete it afterwards it's not copyright hahaha )

    Attached Files:

    • Winner Winner x 1
    • Useful Useful x 1
  7. Nick Moxley

    Nick Moxley Well-Known Member

    Joined:
    Dec 13, 2013
    Messages:
    2,779
    Occupation:
    Owner/Operator- Moxleys Rantals
    Location:
    Winnipeg Manitoba Canada
    Balance:
    17,054Coins
    Ratings:
    +2,504 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK

    Yes that is exactly what im thinking. I will test out your code asap and let you know. Thanks bud. :cheers
    • Like Like x 1
  8. Nick Moxley

    Nick Moxley Well-Known Member

    Joined:
    Dec 13, 2013
    Messages:
    2,779
    Occupation:
    Owner/Operator- Moxleys Rantals
    Location:
    Winnipeg Manitoba Canada
    Balance:
    17,054Coins
    Ratings:
    +2,504 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK

    Your changed did exactly as i wanted...the rotary now makes button 11 and 12 act as button presses....So now on to the D pad + push button double press issue.
    • Like Like x 1
    • Winner Winner x 1
  9. tadythefish

    tadythefish Active Member

    Joined:
    Jul 8, 2009
    Messages:
    148
    Occupation:
    Process automation engineer
    Location:
    Slovenia
    Balance:
    676Coins
    Ratings:
    +95 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    Nice to hear that we understand each other :) i hope it works...
    As for the buttons I re read you post and I think I know what you need.
    So you are trying to say that if you push the button IN you want a signal... Lets say button 1... And if you push the button forward you want a signal... Lets say button 2.. And so on for backward, left and right.. (this is how you want it to work)
    But the problem is when you push the button lets say forward (to the end) you get a signal on button 2 AND button 1 (the same as if you would push it forward and press it in)?
  10. tadythefish

    tadythefish Active Member

    Joined:
    Jul 8, 2009
    Messages:
    148
    Occupation:
    Process automation engineer
    Location:
    Slovenia
    Balance:
    676Coins
    Ratings:
    +95 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    Please check my previous post :) I'm in the mood for programming :)))
    • Friendly Friendly x 1
  11. tadythefish

    tadythefish Active Member

    Joined:
    Jul 8, 2009
    Messages:
    148
    Occupation:
    Process automation engineer
    Location:
    Slovenia
    Balance:
    676Coins
    Ratings:
    +95 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    Again I went ahead and edited the code... If my asumtion in the upper post is correct then this shoul do the trick.

    PLEASE NOTE
    The changes to the code are forcing you to use Button1 (looking at the windows test app) as the input for the PUSH IN
    Button2, Button3, Button4, Button5 for Left, Right,Forward, Reverse ( the order is not imporant)
    Button8, Button9 and Button 10 you can youse for anything you want (they don't have any effect on each other or other buttons)

    Button 11 and Button 12 are (like before) used by the encoder

    In this configuration (settings in the firmware):
    Teensy Pin-------Windows button
    0-----------------------Button 1 (PUSH IN button)
    1-----------------------Button 2 (Forward or Reverse or Left or Right)
    2-----------------------Button 3 (Forward or Reverse or Left or Right)
    3-----------------------Button 4 (Forward or Reverse or Left or Right)
    4-----------------------Button 5 (Forward or Reverse or Left or Right)
    5-----------------------Button 11 (Encoder A)
    6-----------------------Button 12 (Encoder B)
    7-----------------------Button 8 (Whatever you want)
    8-----------------------Button 9 (Whatever you want)
    9-----------------------Button 10 (Whatever you want)

    Please let me know how it goes :)

    Attached Files:

    • Useful Useful x 1
    Last edited: Feb 9, 2017
  12. Nick Moxley

    Nick Moxley Well-Known Member

    Joined:
    Dec 13, 2013
    Messages:
    2,779
    Occupation:
    Owner/Operator- Moxleys Rantals
    Location:
    Winnipeg Manitoba Canada
    Balance:
    17,054Coins
    Ratings:
    +2,504 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK
    It works in 1 direction without me changing any of the pins on the teensy currently how i have it wired (from the top mount schematic view and how i have it wired its the Green Pin and the Down direction) ....Tho if i slowly press in that direction i still see the single input from the Direction pad. So while i see your code at work, Is there a way to make it ignore that initial D pad direction input ? and Also make the combo of D pad direction XX plus # 5 press = Button XX I dont want the D pad in all directions to be one single button
  13. tadythefish

    tadythefish Active Member

    Joined:
    Jul 8, 2009
    Messages:
    148
    Occupation:
    Process automation engineer
    Location:
    Slovenia
    Balance:
    676Coins
    Ratings:
    +95 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    You have to know something... I don't have a D pad (never did) so I don't know hot you have it wired... I only know you have an encoder and a Pad that has 5 buttons inside one for push in (like enter), left, right, Forward, brackward...
    So in order for me to help you ( I love to do that :) ) please show me some pictures and maybe how it is wired so I can better understand the situation ;)
    And did you download the modified version of the program?
  14. tadythefish

    tadythefish Active Member

    Joined:
    Jul 8, 2009
    Messages:
    148
    Occupation:
    Process automation engineer
    Location:
    Slovenia
    Balance:
    676Coins
    Ratings:
    +95 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    OK I am looking at the pictures that you have provided on the PJRC forum and the datasheet off the encoder.. can you post a picture of the rear side of the encoder?

    I see how you connected everything...
    Teensy PIN--------- Wire color ---------- Enoder pin

    0 --------------------- Green ----------------- A
    1 --------------------- Grey ------------------ C
    2 --------------------- Blue -------------------- Push
    3 --------------------- Brown ----------------- D
    4 --------------------- Yellow ------------------ B
    5 --------------------- Orange ----------------- Encoder B
    6 --------------------- Red --------------------- Encoder A
    GND ---------------- Black ------------------- Ground terminal
    GND ---------------- Purple ------------------ Encoder COM

    Is this correct?

    If this is your wiring then I have assigned the wrong inputs to the code.. here is the corrected version please try it and report back
    NOTE: This shoul work as follows....
    When you PUSH IN button 1 should come on (windows test screen for joystick)
    When you push forward (button 2 or 3 or 4 or 5 should come on, one of them)
    When you push backward (button 2 or 3 or 4 or 5 should come on, one of them)
    When you push left (button 2 or 3 or 4 or 5 should come on, one of them)
    When you push right (button 2 or 3 or 4 or 5 should come on, one of them)

    I can't exactly tell you witch of the buttons come on since I don't know the orientation (how you have it mounted) of the encoder. But basicly this is how this code works. And we can make aditional changes

    Attached Files:

    • Useful Useful x 1
    Last edited: Feb 9, 2017
  15. Nick Moxley

    Nick Moxley Well-Known Member

    Joined:
    Dec 13, 2013
    Messages:
    2,779
    Occupation:
    Owner/Operator- Moxleys Rantals
    Location:
    Winnipeg Manitoba Canada
    Balance:
    17,054Coins
    Ratings:
    +2,504 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK


    No I have it as follows Not sure if you need to tweak it again,

    0 --------------------- Green ----------------- A
    1 --------------------- Grey ------------------ C
    2--------------------- Brown -------------------- B
    3 --------------------- Yellow ----------------- D
    4 --------------------- Black ------------------ Com
    5 --------------------- Red ----------------- Encoder A
    6 --------------------- Orange --------------------- Encoder B
    GND ---------------- grey ------------------- Ground terminal
    GND ---------------- Blue/Purple ------------------ Encoder COM/Push
  16. Nick Moxley

    Nick Moxley Well-Known Member

    Joined:
    Dec 13, 2013
    Messages:
    2,779
    Occupation:
    Owner/Operator- Moxleys Rantals
    Location:
    Winnipeg Manitoba Canada
    Balance:
    17,054Coins
    Ratings:
    +2,504 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK
    Pin 2 or Brown is the pin that im seeing that different activity on, If i press the D pad all the way, It lets go of the D pad number press, but sill unilized the "push" button number. which isn't what i want but that might be because of the code need changing....


    Again I Very much appreciate the help with this Tady, I owe ya one. ;)
    • Like Like x 1
  17. tadythefish

    tadythefish Active Member

    Joined:
    Jul 8, 2009
    Messages:
    148
    Occupation:
    Process automation engineer
    Location:
    Slovenia
    Balance:
    676Coins
    Ratings:
    +95 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    Try swapping wires Black and brown...
    PIN2 is the pin that COM needs to be connected...
    That pis is different from pin 0,1,3,4
    The code is written that if only pin 2 is LOW (push in) you get a signal.
    But if you push forward you said you get a signal forward AND push in... So i have edited the code to turn off the PUSH in signal if you press forward,reverse,left or right...
    So it is absolutley mandatory that the signal that is active (when low) when pushed in is connected to pin 2 of teensy and forward,backward,left and right are connected to 0,1,3,4
    So try swapping the Black and brown wires
    • Winner Winner x 1
    Last edited: Feb 10, 2017
  18. Nick Moxley

    Nick Moxley Well-Known Member

    Joined:
    Dec 13, 2013
    Messages:
    2,779
    Occupation:
    Owner/Operator- Moxleys Rantals
    Location:
    Winnipeg Manitoba Canada
    Balance:
    17,054Coins
    Ratings:
    +2,504 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK
    teensy-lc.jpg YOU ROCK @tadythefish


    That works exactly like i want and just like you said swapping the brown and black did the trick. I cant thank you enough man, I seriously owe you a favor.
    • Friendly Friendly x 2
    • Like Like x 1
  19. tadythefish

    tadythefish Active Member

    Joined:
    Jul 8, 2009
    Messages:
    148
    Occupation:
    Process automation engineer
    Location:
    Slovenia
    Balance:
    676Coins
    Ratings:
    +95 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    You don't owe me nothing :) well if you are ever in Slovenia (google it ;) ) you can buy me a beer;)
    If in the future you have any problems with aarduinos or Teensys drop me a line.. Im happy to help.. For me I get such a great feeling that someone is happy because I was able to help ;)
    • Winner Winner x 2
    • Friendly Friendly x 2
  20. tadythefish

    tadythefish Active Member

    Joined:
    Jul 8, 2009
    Messages:
    148
    Occupation:
    Process automation engineer
    Location:
    Slovenia
    Balance:
    676Coins
    Ratings:
    +95 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    @Nick Moxley
    If you want I can edit the code some more so you have all the pins used an prepared for future expansion.
    One last tip... You should really put Pull Up resistors on the used pins.. So you don't get any false triggers.... I can draw you a schematic (with colored resistors). And I mean a schematic for those who are not electrically expirienced :)
    • Like Like x 2
    • Useful Useful x 1
    Last edited: Feb 10, 2017