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. 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
    Should be doable:) ok i will try to write you a sxript for testing... Do you have the encoders and a teensy? Wich teensy do you have? You said two encoders what is the other ones function?
    The first encoder you specified the keystrokes for direction turning, can you pecify keystrokes for up,down,left and right?
    • Friendly Friendly x 1
  2. narbi

    narbi New Member

    Joined:
    Feb 18, 2018
    Messages:
    7
    Location:
    France
    Balance:
    189Coins
    Ratings:
    +3 / 0 / -0
    Encoders and teensy are on their way, should be here before the end of the week. I should be able to have some hardware ready next week end.
    Teensy LC.
    Only one encoder per teensy, as the purpose is the same, they only need to control 2 separate devices, it's easier that way.
    So one basic script is good, I will modify it for the second one changing the keystrokes, or keycodes, or whatever you will use.

    Push button : CTRL P
    Rotary clockwise : CTRL =
    Rotary counter clockwise : CTRL -
    Pad UP : CTRL N
    Pad DOWN : CTRL L
    Pad Left : CTRL SHIFT Left Arrow
    Pad Right : CTRL SHIFT Right Arrow

    Thank you for your help
  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
    I will do my best:)
    • Friendly Friendly x 1
  4. narbi

    narbi New Member

    Joined:
    Feb 18, 2018
    Messages:
    7
    Location:
    France
    Balance:
    189Coins
    Ratings:
    +3 / 0 / -0
    I got it working the way I wanted, I just had to adapt your code to my needs, but with the help of the included examples and online help I figured it out.
    Working flawlessly in both different situations.
    Attached are both codes.
    I changed the wiring too, COM + Enc-COM + Ground go to pin 0, push button to pin 2.

    Attached Files:

    • Winner Winner x 2
    • Informative Informative x 1
  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
    I am so sorry I couldn't help you. I'm on vacation and I don't have my laptop with me :/ But on rhe other hand I'm very happy. I like helping people but if you pulled off the project your self you learned alot:) like cheat sheets in school... If you wrote them your self you probably don't need them but if someone else wrote them for you you know nothing about the subject:)))
    This is the reason if you go to the Arduino or Teensy forums people will help you but they will not write whole codes for you ;) but this forum is different that is why I help people and write code for them. But you did is perfect!
    A little heads up.. If you use Pin0 and Pin1 you can't use Serial1 on theensy or Serial on arduino. Those pins are tipically avoided. But if you don't need Serial communication it's ok;)
    These Teensy boards are beasts. Check out the 3.6 it can run over 200MHz:) I use one for my Ethernet 2dof +traction loss servo controler:)

    Anyway this is exelent news if you have any questions or in need of help don't hesitate to contact me.

    Oh and THANK YOU for sharing your code with others!

    Sharing is caring!
    Open source is the way! :))
    • Like Like x 1
    • Friendly Friendly x 1
  6. Darius_p

    Darius_p New Member

    Joined:
    Feb 3, 2019
    Messages:
    10
    Balance:
    194Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    Arduino
    Hi guys,

    now I need help with this joystic. I used the same RKJXTIF component https://www.alps.com/prod/info/E/HTML/MultiControl/Switch/RKJXT/RKJXT1F42001.html

    I tried connecting based on scheme attached to Arduino UNO and reading for input_pullup. 4 ways (left, right, up, down) works to some extent, but its enough only little push to engage the button and it doesn't need to be clicked, and if it is clicked it immediately is seen as middle push button. Middle push somehow works fine. Here is a vid of the situation
    I tried adding resistors 10K in between pin and button, but didn't do the trick.

    I tried also to connect as ordinary button like here https://programmingelectronics.com/tutorial-17-using-a-button-old-version/ and read input. It works perfectly for 4 ways and rotary, but not for the center. If i am trying to connect center, then all 4 ways and center button seen as center.

    the code for the scheme is here:
    https://github.com/darjusp/test/blob/master/Button.ino

    Could you please lead to some direction how to engage all 5 buttons properly?

    Attached Files:

  7. 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
    Can you post your code?
  8. 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
    Sorry i just saw that you already did
  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
    First of all remove the 10k resistors that you connected between the switch and input.
    You should try to connect the 10k resistors between inputs and Vcc (5v or 3.3v depends on the type of teensy you are using)
    Second thing is the routine for reading the encoder is for me not good.
    Arduino and teensy have encoder library that handle the inputs of the encoder in a very efficient way with interrupts!
    You should really google for arduino encoder or if you have teensy boards installed in Arduino IDE just select the teensy you are using (i'm thinking you are because of the attached schematic) and look in the examples for Encoder
  10. Darius_p

    Darius_p New Member

    Joined:
    Feb 3, 2019
    Messages:
    10
    Balance:
    194Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    Arduino
    Thanks a lot for the reply.

    By attaching resistors between VCC and input, you mean like this in the scheme? or i got something wrong? Anyway i did like this and its still the same problem with center button

    Lets not bother too much about encoder yet, that was somehow working well in previous codes i tried :) it is this center button that messes all things up

    Attached Files:

  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
    Yes.. But connect it to 5v if you are using an Arduino.

    The stange thing with your schematics is that the name COM and PUSH are mixed up.. If you look at the wiring and schematics of the joystick everything is correct but labels are switched..
    Maybe just for the heck of it swap COM and PUSH wires
  12. Darius_p

    Darius_p New Member

    Joined:
    Feb 3, 2019
    Messages:
    10
    Balance:
    194Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    Arduino
    Hmm, i tried this one too, but then every button switch no matter which one, shows the same value (that is center button). Any more ideas where i messed up? it is wondering it neeeds only slight push of the switch and it starts reacting, for instance if i would do button based on "input" not on "input_pullup" than it works only after fully click
  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
    Input_pullup is the same as input but it activates a internal 20k resistor.. If you use external pullups you don't need input_pullup.
    First I would suggest that you disconnect the joystick and test the inputs with a piece of wire connected to GND.
  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
    I was looking at the truth table of the joystick and it is very strange.. It seems the push-com is ON if you push it IN or if you go left,right,up,down.. It is only OFF when it it left alone.. So it seems its working OK.
    You should be getting the COM signal if you push it out of fenter or push it IN

    Attached Files:

  15. 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
    Hmmmm.. Try changing the code from this..

    if (buttonStateA == LOW) {
    buttonWhich = 1;
    }
    if (buttonStateB == LOW) {
    buttonWhich = 2;
    }
    if (buttonStateC == LOW) {
    buttonWhich = 3;
    }
    if (buttonStateD == LOW) {
    buttonWhich = 4;
    }
    if (buttonStateCent == LOW) {
    buttonWhich = 5;
    }

    To this...
    if (buttonStateCent == LOW) {
    buttonWhich = 5;
    }
    if (buttonStateA == LOW) {
    buttonWhich = 1;
    }
    if (buttonStateB == LOW) {
    buttonWhich = 2;
    }
    if (buttonStateC == LOW) {
    buttonWhich = 3;
    }
    if (buttonStateD == LOW) {
    buttonWhich = 4;
    }
    Tell me if it works.. I just rearranged the if sentences
    • Informative Informative x 1
  16. Darius_p

    Darius_p New Member

    Joined:
    Feb 3, 2019
    Messages:
    10
    Balance:
    194Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    Arduino
    that worked well, it shows all the values :) what can i do next?
  17. Darius_p

    Darius_p New Member

    Joined:
    Feb 3, 2019
    Messages:
    10
    Balance:
    194Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    Arduino
    thank you that did work well all buttons are are shown, its just annoying that it starts reacting too quickly without needing a full click. I will try to remake a scheme and get your opinion on it
  18. Darius_p

    Darius_p New Member

    Joined:
    Feb 3, 2019
    Messages:
    10
    Balance:
    194Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    Arduino
    In this case (scheme attached), and with your adjusted code it works perfectly. Reaction to button only on full click, and all buttons engage :) Is anything terribly bad with this scheme?
    Oh and the code changed as well https://github.com/darjusp/test/blob/master/Button.ino

    Attached Files:

  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
    Your schematics show you have connected pull down resistors not pull up? Is this correct. If it is it is not good. Maybe it works maybe it doesn't

    As for the code i re-arranged the if sentences to test for the push button first.. In the previous version it was testing the push last.. Since your button always switches the push button even when you push forward backward left or right the code always registered the push because it was testingcthe push switch last.
  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
    If you pushed lets say the stick to B and you could look at the code in slow motion you would see that variable buttonWhich would be set to 2 and when the code continues trough the if sentences it would still be 2 but at the last if sentence when the code tests for push it would also be true. So the buttonWhich gets changed to 5.
    That is why you saw that it is always reading the push.
    The prevoius code that you provided would work if the joystick would only read the push when pushed but if you look at the truth table you can see that the push switch always reads true even if you push left right foward and backward. It's just how it is constructed