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

Thread: Teensy 3.1 Button problems

  1. #1
    Junior Member
    Join Date
    Aug 2015
    Posts
    4

    Teensy 3.1 Button problems

    Hey Everybody,
    I am completely new to teensy and arduino so please excuse any of my mistakes. Anyway im trying use my teensy 3.1 as a joystick, i currently have 2 buttons connected to it(starting out simple) and im using the microsoft game properties to test it. The problem is when i press one of the buttons it shows the button working but it also changes all of the axis controls and the hat control. I am Running windows 10. I have the pictures of the before and after attached.

    Here is the code:
    #include <Bounce.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

    void setup() {
    // Configure the pins for input mode with pullup resistors.
    // The pushbuttons connect from each pin to ground. When
    // the button is pressed, the pin reads LOW because the button
    // shorts it to ground. When released, the pin reads HIGH
    // because the pullup resistor connects to +5 volts inside
    // the chip. LOW for "on", and HIGH for "off" may seem
    // backwards, but using the on-chip pullup resistors is very
    // convenient. The scheme is called "active low", and it's
    // very commonly used in electronics... so much that the chip
    // has built-in pullup resistors!
    pinMode(0, INPUT_PULLUP);
    pinMode(1, INPUT_PULLUP);

    }

    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();


    // 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);
    }


    // 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);
    }


    }
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	before.jpg 
Views:	104 
Size:	58.0 KB 
ID:	4839   Click image for larger version. 

Name:	After.jpg 
Views:	77 
Size:	57.2 KB 
ID:	4840  


  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,691
    Any chance you could try on a pre-10 version of Windows?

    I just got my copy of 10 today... haven't installed it yet. Will do soon.

  3. #3
    Junior Member
    Join Date
    Aug 2015
    Posts
    4
    I just tried it on windows 8.1 (Had my laptop near me) and unfortunately it does the same thing

  4. #4
    Junior Member
    Join Date
    Aug 2015
    Posts
    4
    Im still having problems any ideas?

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,691
    Ok, I've managed to reproduce the problem you're seeing on Windows 10. Well, at least I think I've got the same thing here.

    After programming Teensy and opening JOY.CPL, I see this:

    Click image for larger version. 

Name:	Capture1.PNG 
Views:	133 
Size:	269.5 KB 
ID:	4947
    (click for full size)

    Then, as soon as I press a button, the X-Y position and 4 axes go to zero, as well as the button indicates pressed.

    Click image for larger version. 

Name:	Capture2.PNG 
Views:	129 
Size:	270.2 KB 
ID:	4946
    (click for full size)

    This may seem as if something is wrong on Teensy, causing the buttons to interfere with the axes. However, there is actually nothing wrong on the Teensy side.

    The problem is Windows 10 is just making up default data before it receives any communication from Teensy. Before that first button press, Windows has never received any info from Teensy, so it has absolutely no idea what the X, Y, Z, Zr and Slider position are. It's just defaulting to showing them at the center of their range.

    If you never set those parameters, Teensy defaults to zero (on a scale of 0 to 1023). Perhaps Teensy should instead default to 512? Obviously Windows is assuming the default is 512, before it gets any real info.

    Anyway, if you want the Windows joystick control panel to respond the way you expect, all you need to do is add a little code inside setup(), like this:

    Code:
        Joystick.Z(512);  // same as Windows default

  6. #6
    Junior Member
    Join Date
    Aug 2015
    Posts
    4
    I am so glad you able to reproduce it, for a little bit i thought i was going crazy lol. Your solution works perfectly, thank you so much paul for your help.

  7. #7
    Hello guys,
    i have the same problem, but where i have to put in that code, please?

    This don't work.

    Thank you very much.

    Manuel
    #include <Bounce.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
    Joystick.Z(512); // same as Windows default
    void setup() {
    // Configure the pins for input mode with pullup resistors.
    // The pushbuttons connect from each pin to ground. When
    // the button is pressed, the pin reads LOW because the button
    // shorts it to ground. When released, the pin reads HIGH
    // because the pullup resistor connects to +5 volts inside
    // the chip. LOW for "on", and HIGH for "off" may seem
    // backwards, but using the on-chip pullup resistors is very
    // convenient. The scheme is called "active low", and it's
    // very commonly used in electronics... so much that the chip
    // has built-in pullup resistors!
    pinMode(0, INPUT_PULLUP);
    pinMode(1, INPUT_PULLUP);

    }

    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();


    // 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);
    }


    // 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);
    }


    }

  8. #8
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    7,101
    Quote Originally Posted by PaulStoffregen View Post

    Anyway, if you want the Windows joystick control panel to respond the way you expect, all you need to do is add a little code inside setup(), like this:

    Code:
        Joystick.Z(512);  // same as Windows default
    Quote Originally Posted by Manuel Staedel View Post
    Hello guys,
    i have the same problem, but where i have to put in that code, please?

    This don't work.

    Thank you very much.

    Manuel
    Based on Paul's post:

    Code:
     void setup() {
        Joystick.Z(512);  // same as Windows default
        // … other setup code
     }

  9. #9
    Is that correct?

    #include <Bounce.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
    void setup() {
    Joystick.Z(512); // same as Windows default

    // Configure the pins for input mode with pullup resistors.
    // The pushbuttons connect from each pin to ground. When
    // the button is pressed, the pin reads LOW because the button
    // shorts it to ground. When released, the pin reads HIGH
    // because the pullup resistor connects to +5 volts inside
    // the chip. LOW for "on", and HIGH for "off" may seem
    // backwards, but using the on-chip pullup resistors is very
    // convenient. The scheme is called "active low", and it's
    // very commonly used in electronics... so much that the chip
    // has built-in pullup resistors!
    pinMode(0, INPUT_PULLUP);
    pinMode(1, INPUT_PULLUP);

    }

    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();


    // 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);
    }


    // 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);
    }


    }

  10. #10
    With that code, i have the same problem again.
    After press the first button, you see that.
    Click image for larger version. 

Name:	2018-12-04 18_10_40-Teensy 3.1 Button problems.png 
Views:	4 
Size:	14.8 KB 
ID:	15280

  11. #11
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,774
    Quote Originally Posted by Manuel Staedel View Post
    With that code, i have the same problem again.
    After press the first button, you see that.
    Click image for larger version. 

Name:	2018-12-04 18_10_40-Teensy 3.1 Button problems.png 
Views:	4 
Size:	14.8 KB 
ID:	15280
    Yes, sometimes blind copy&paste without trying to understand what it does, does not help..

    first, try this:
    Code:
    void setup() {
    // same as Windows default
    Joystick.Z(512);
    Joystick.X(512);
    Joystick.Y(512);
    Joystick.Zrotate(512);
    Joystick.sliderLeft(512);
    Joystick.sliderRight(512);
    //Joystick.slider(512);
    [...]
    .. this uses the Windows defaults for the other values, too
    To see the change, click on "Auf Standard zurücksetzen"
    Click image for larger version. 

Name:	2018-12-04 20_41_00-Window.png 
Views:	3 
Size:	15.1 KB 
ID:	15281
    Last edited by Frank B; 12-04-2018 at 07:43 PM. Reason: add picture

  12. #12
    After that, all buttons in the middle or off, but if you click one time, the + are upper left and the round-button are up.
    I want only buttons on my teensyLC.

  13. #13
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,774
    Nö,bei mir nicht. Hast auf "Auf Standard zurücksetzen" geklickt? Hast du das neue Programm überhaupt auf den Teensy übertragen?

  14. #14
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,774
    Quote Originally Posted by Manuel Staedel View Post
    I want only buttons on my teensyLC.
    hm. then, connect only buttons?.. ;-)

  15. #15
    Ja, habe auf Zurücksetzen geklickt und auch den Code drauf kopiert inkl Reboot.
    Leider reagiert er nun auf keine Taste mehr.

  16. #16
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,774
    something is wrong.. perhaps sleep a night and try it again.
    sorry, I don't know what the problem is now. Ausserdem läuft dr who im TV.

  17. #17
    Vielen Dank trotzdem, viel Spaß beim schauen.

Posting Permissions

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