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

Thread: Pin 13 on Teensy 3.2 wont work for switch

  1. #1

    Pin 13 on Teensy 3.2 wont work for switch

    Hi Im using a Teensy 3.2 as a USB game controller but for some reason PIN 13 seems to not work correctly. Is this because of the LED function? Is there a way around this?

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,767
    Is "not work correctly" :: 'intermittent', slow or not at all?

    Is the pin wired Pull UP or DOWN? Internally or externally?

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,591
    Quote Originally Posted by tonberryhunter View Post
    Is this because of the LED function?
    Yes. Or probably yes, given that we can't see your wiring or your code, but this is a common problem when pushbuttons are used in the ordinary way.

    Is there a way around this?
    Connect the pushbutton between 3.3V and pin 13, and a resistor from pin 13 to GND. Or try pinMode INPUT_PULLDOWN instead of a real resistor.

    Or use another pin.

  4. #4
    Quote Originally Posted by PaulStoffregen View Post
    Yes. Or probably yes, given that we can't see your wiring or your code, but this is a common problem when pushbuttons are used in the ordinary way.



    Connect the pushbutton between 3.3V and pin 13, and a resistor from pin 13 to GND. Or try pinMode INPUT_PULLDOWN instead of a real resistor.

    Or use another pin.
    All other switches are wired identically and working with the Arduino code setting pinMode to input_pullup.

    I did notice that when I grounded pin 13 to myself the switch seemed to work although the LED would go on and off. Not that I care if the led goes on and off but I wasnt sure if that would cause any issues elsewhere.

    Click image for larger version. 

Name:	IMG_20190904_042743.jpg 
Views:	6 
Size:	122.3 KB 
ID:	17487

  5. #5
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,269
    Quote Originally Posted by tonberryhunter View Post
    All other switches are wired identically and working with the Arduino code setting pinMode to input_pullup.

    I did notice that when I grounded pin 13 to myself the switch seemed to work although the LED would go on and off. Not that I care if the led goes on and off but I wasnt sure if that would cause any issues elsewhere.
    The issue is that since pin 13 has a LED attached to it, the LED includes a resistor, and that changes the electrical characteristics of the line when trying to read from it. Hence Paul's suggestions of ways to work around that resistor. IIRC, using INPUT_PULLDOWN (or the resistor) will also flip the result of digitalRead.

  6. #6
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,079
    You can then take the inverse of the flip afterwards !digitalRead

    keep a little //comment there if you do this so you understand why later on when working on your project

Posting Permissions

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