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,055Coins
    Ratings:
    +2,505 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK
    Hey guys forgive the rookie question but how the F can i get my Teensy LC to work as a button box and allow me to add the "encoder library" to the script so it will all just work as it should, Struggling to get a scrip loaded that seems to work, I can get the one test push button attached to flash the LED on the Teensy, but for the Life of me cant get a button to light up in the Game Controllers where its coming up as a keyboard/joystick/gamepad ect ect.


    Thanks
  2. stevemontuno

    stevemontuno Active Member

    Joined:
    Apr 24, 2015
    Messages:
    316
    Location:
    UK
    Balance:
    1,461Coins
    Ratings:
    +335 / 0 / -0
    My Motion Simulator:
    2DOF
    Have you uninstalled all the Fanatec drivers from your PC?
  3. 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,055Coins
    Ratings:
    +2,505 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK

    Huh ? why would i do that ?
  4. stevemontuno

    stevemontuno Active Member

    Joined:
    Apr 24, 2015
    Messages:
    316
    Location:
    UK
    Balance:
    1,461Coins
    Ratings:
    +335 / 0 / -0
    My Motion Simulator:
    2DOF
    I think it's some interference thing with the drivers ,,well so a few guys on iRacing forum seem to think ,,, this is from one guy's post ,,

    So I just copied the hex code from github directly, put it in an csw.hex called file and then the flash worked. The next thing was, my PC was showing it as a Clubsport wheel (my csw formula wheel) but it showed it as a steering wheel with axis etc.. Since I have the Fanatec Base V2 and installed the drivers of it there was some confusion on my PC I guess. So you have to deinstall all Fanatec drivers I guess. I connected the Teensy LC with the F1 rim to my laptop where no Fanatec drivers are installed and everything just works perfectly. Every button etc.
  5. 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,055Coins
    Ratings:
    +2,505 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK
    My Fanatec/Teensy Conversion works 100% perfectly fine....didn't have a problem doing that one.

    im trying to get a Stand alone Teensy LC to work with some Standard cheap Ebay buttons and an Alps encoder...
  6. stevemontuno

    stevemontuno Active Member

    Joined:
    Apr 24, 2015
    Messages:
    316
    Location:
    UK
    Balance:
    1,461Coins
    Ratings:
    +335 / 0 / -0
    My Motion Simulator:
    2DOF
    Ahh sorry dude ,,,thought you were on about your wheel ,, i need to look into these teensy boards a bit more as they seem pretty handy for modding stuff on the cheap,,
  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,055Coins
    Ratings:
    +2,505 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK

    I suck with understanding these kinds of things. :confused:o_O:think:blush
  8. tadythefish

    tadythefish Active Member

    Joined:
    Jul 8, 2009
    Messages:
    148
    Occupation:
    Process automation engineer
    Location:
    Slovenia
    Balance:
    677Coins
    Ratings:
    +95 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    Maybe I can help.. I use Teensys all the time ... 3.1 or 3.6 most of the time.. But I can't understand what is your problem.. Can you explain please
  9. SilentChill

    SilentChill Problem Maker

    Joined:
    Jul 19, 2014
    Messages:
    2,643
    Occupation:
    Railway Maintenance
    Location:
    Morecambe, Lancashire, England
    Balance:
    20,557Coins
    Ratings:
    +3,487 / 34 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF
    He wants to use it for buttons/encoders as a hid device/controller
  10. 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,055Coins
    Ratings:
    +2,505 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK

    I have the start to the code going, with a buttons example and a "two knobs" example that the guys on pjrc helped with...... the buttons all work, but as soon as i plug in all the ALPS connector's i start to get double presses of buttons. And im at a loss as to why.





    da code


    // Hacked up combined of two example sketches. With pins 5 and 6
    // not being used as buttons but instead encoder.
    #include <Bounce.h>
    #include <Encoder.h>

    // Create Bounce objects for each button. The Bounce object
    // automatically deals with contact chatter or "bounce", and
    // it makes detecting changes very simple.
    Bounce button0 = Bounce(0, 10);
    Bounce button1 = Bounce(1, 10); // 10 = 10 ms debounce time
    Bounce button2 = Bounce(2, 10); // which is appropriate for
    Bounce button3 = Bounce(3, 10); // most mechanical pushbuttons
    Bounce button4 = Bounce(4, 10);
    Bounce button7 = Bounce(7, 10);
    Bounce button8 = Bounce(8, 10);
    Bounce button9 = Bounce(9, 10);
    Encoder myEnc(5, 6);
    void setup() {
    pinMode(0, INPUT_PULLUP);
    pinMode(1, INPUT_PULLUP);
    pinMode(2, INPUT_PULLUP);
    pinMode(3, INPUT_PULLUP);
    pinMode(4, INPUT_PULLUP);
    pinMode(7, INPUT_PULLUP);
    pinMode(8, INPUT_PULLUP);
    pinMode(9, INPUT_PULLUP);

    myEnc.write(512); // try to init in middle

    }

    void loop() {
    // Update all the buttons. There should not be any long
    // delays in loop(), so this runs repetitively at a rate
    // faster than the buttons could be pressed and released.
    button0.update();
    button1.update();
    button2.update();
    button3.update();
    button4.update();
    button7.update();
    button8.update();
    button9.update();

    // Check each button for "falling" edge.
    // Update the Joystick buttons only upon changes.
    // falling = high (not pressed - voltage from pullup resistor)
    // to low (pressed - button connects pin to ground)
    if (button0.fallingEdge()) {
    Joystick.button(1, 1);
    }
    if (button1.fallingEdge()) {
    Joystick.button(2, 1);
    }
    if (button2.fallingEdge()) {
    Joystick.button(3, 1);
    }
    if (button3.fallingEdge()) {
    Joystick.button(4, 1);
    }
    if (button4.fallingEdge()) {
    Joystick.button(5, 1);
    }
    if (button7.fallingEdge()) {
    Joystick.button(8, 1);
    }
    if (button8.fallingEdge()) {
    Joystick.button(9, 1);
    }
    if (button9.fallingEdge()) {
    Joystick.button(10, 1);
    }

    // Check each button for "rising" edge
    // Update the Joystick buttons only upon changes.
    // rising = low (pressed - button connects pin to ground)
    // to high (not pressed - voltage from pullup resistor)
    if (button0.risingEdge()) {
    Joystick.button(1, 0);
    }
    if (button1.risingEdge()) {
    Joystick.button(2, 0);
    }
    if (button2.risingEdge()) {
    Joystick.button(3, 0);
    }
    if (button3.risingEdge()) {
    Joystick.button(4, 0);
    }
    if (button4.risingEdge()) {
    Joystick.button(5, 0);
    }
    if (button7.risingEdge()) {
    Joystick.button(8, 0);
    }
    if (button8.risingEdge()) {
    Joystick.button(9, 0);
    }
    if (button9.risingEdge()) {
    Joystick.button(10, 0);
    }

    // Play around with Encoder?
    long enc = myEnc.read(); // get current value
    // make sure it is in the bounds for joystick
    if (enc < 0) {
    enc = 0;
    myEnc.write(0);
    } else if (enc > 1023) {
    enc = 1023;
    myEnc.write(1023);
    }
    Joystick.sliderLeft(enc);
    }
  11. 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,055Coins
    Ratings:
    +2,505 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK
  12. tadythefish

    tadythefish Active Member

    Joined:
    Jul 8, 2009
    Messages:
    148
    Occupation:
    Process automation engineer
    Location:
    Slovenia
    Balance:
    677Coins
    Ratings:
    +95 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    I will look at the code more closely in the evening... So in short you want the LC to act like a joystick.. Have a few buttons and an encoder...
    I never played around with the joystick library but i have it in the examples. I will play with it...
    Last edited: Feb 8, 2017
  13. tadythefish

    tadythefish Active Member

    Joined:
    Jul 8, 2009
    Messages:
    148
    Occupation:
    Process automation engineer
    Location:
    Slovenia
    Balance:
    677Coins
    Ratings:
    +95 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    OK I have compiled your code but I don't hava a rotary encoder. I have one at work so no problems after tomorrow. But can you help me out with what kind of software are you using on the PC to see the buttons and the encoder?

    Never mind .. found it in windows :)
    Last edited: Feb 8, 2017
  14. 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,055Coins
    Ratings:
    +2,505 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK
    Thanks bud, I have a funny feeling this is something specific to the Alps Encoder. here's the full data sheet if your curious to look and see why it might be doing the double press.


    http://www.alps.com/prod/info/E/PDF/MultiControl/Switch/RKJXT1F/RKJXT1F.PDF
  15. tadythefish

    tadythefish Active Member

    Joined:
    Jul 8, 2009
    Messages:
    148
    Occupation:
    Process automation engineer
    Location:
    Slovenia
    Balance:
    677Coins
    Ratings:
    +95 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    I have tested your code end buttons also work here..But as I said tomorow I will test with a encoder knob. I have googled what kind you have (ALPS) and I have the same one.
    Her is what i need from you. Please make a simple wiring diagram ( don't bother with estetics) so I can replicate your circuit.
    And here are my thoughts....

    - I haven't looked at the Bounce library on how it works but if the code can detect rising and falling edges of the signal from the buttons, then it must use interrupst... All good and well ... BUT the encoder library also uses interrupts to catch the changes of A an B signal. If someone was witing a code that needs a few milliseconds to cycle then pulses would be lost.
    If both libraries use interrupts maybe one of the libraries is disabling and enabling them. This could be a big problem. Usualy I don't ever use software debounce (I had to download and install the library) ;) But instead I add a capacitor and a resistor to the input and hardware bounce the button. These buttons don't get pressed fast so the cap and resistor values are not cruical. I can calculate them for you if you would like to make it with hardware debounce.

    - I would recommend using external pullup resistors of 1k or so (just to be safe). The Internal pullups are rated at 50k to 100k. If the microprocessor is working with 3.3V that is a very weak pullup. Even a moist finger can set it off

    More tomorow :)
  16. tadythefish

    tadythefish Active Member

    Joined:
    Jul 8, 2009
    Messages:
    148
    Occupation:
    Process automation engineer
    Location:
    Slovenia
    Balance:
    677Coins
    Ratings:
    +95 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    Thank you for the datasheet... I don't have this one :) but I do have a similar encoder... So this one works like an encoder when you turn the shaft and there is a button if you press the shaft in (COM signal) and Left,Right,Up,Down (A,B,C,D).. Am I right?
  17. 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,055Coins
    Ratings:
    +2,505 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK

    Correct.

    The Finger touching i experienced when playing with various button examples, I would touch both contacts with my fingers and it would register by the LED going out.

    theres a rough schematic in the pjrc forum link i posted above, Not very easy to read, or poorly laid out, tho the schematic itself is a Cluster F*ck of lines anyways.
  18. tadythefish

    tadythefish Active Member

    Joined:
    Jul 8, 2009
    Messages:
    148
    Occupation:
    Process automation engineer
    Location:
    Slovenia
    Balance:
    677Coins
    Ratings:
    +95 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    Amm on the forum you said you have connected the COM to ground.. So COM is ground and other terminals are wired to the inputs ( Push, A,B,C,D)??
    If that is correct then you wired it wrong. From the datasheet you have provided (Page 2 - Circuit diagram) I can see that PUSH should be ground (don't know why it is like that but it is written in the schematic diagram) and COM should be connected to the input where the pushbutton is connected.
    Thy swapping COM and PUSH wires.

    PUSH and Encoder COM should both be grounded
  19. tadythefish

    tadythefish Active Member

    Joined:
    Jul 8, 2009
    Messages:
    148
    Occupation:
    Process automation engineer
    Location:
    Slovenia
    Balance:
    677Coins
    Ratings:
    +95 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    This is how it should be done (if you look at the shematic)

    Attached Files:

    • Informative Informative x 1
  20. tadythefish

    tadythefish Active Member

    Joined:
    Jul 8, 2009
    Messages:
    148
    Occupation:
    Process automation engineer
    Location:
    Slovenia
    Balance:
    677Coins
    Ratings:
    +95 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    And this is how I would do it ( hardware debounce). If the libraries are fighting with each other I would do it like this. It does add quite a few components but this is good hardware debounce.
    The capacitor (100nF) and resistor (47Kohm) have an effect of slowly raising the voltage on the input. This adds some time delay but if you use simple push buttons this is not noticable. The 47k and 100nF combination gives you 12ms of delay before the voltage on the input is at 3V. I woul have to look at the teensy datasheet to see at what voltage on the input is considered logic HIGH ( this is less than 2.5V).
    But it is easier to try it out. If you still have bouncing issues then you have to raise the resistor value OR the capacitor value.
    I made the drawing as a quick quide line... The encoder shoul also be connected like the buttons (should be debounced). These encoders are mechanical and the bounce. You clould get false values!
    In your code you use interrupts on all inputs so any noise on the pins is going to trigger the code!

    The 1K resistor is there optionally BUT it helps protect the switch from current spikes. When you push the button the capacitor is discharged via 1K. If there was no resistor there would be (in theory) an infinent current spike at time zero. In practice there is alot of resistance in the wires, capacitor it self and switch contacts but never the less it could get to an ampere or so. In time this would destroy the contact plating so it is best to include it.
    Even if you don't make hardware debounce please at least add 1k resistors as external pull-ups ( from input to 3.3V) it will save you alot of headaches ;)

    Sorry for my english :)

    shematicBebounce.png
    And the scope traces....
    Bebounce.png
    False triggering....
    Bebounce2.png
    • Informative Informative x 3
    Last edited: Feb 8, 2017