Using the builtin LED pin for input (Teensy 3.5)

Status
Not open for further replies.

rarelynecessary

New member
So I'm picking back up a project I mostly finished but abandoned a few years ago making a midi controller with a teensy 3.5. When I was doing this the first time round (I lost the wip code so I've had to start over on that front), I had soldered one of my buttons onto pin 13, which is also the pin for the built-in LED. I'm not sure how to draw a schematic quickly, but this button basically goes GND -- Button -- Pin 13.

Cut to now, That pin in particular is giving me some trouble, which I think is related to the LED, but I could be wrong. In my larger code, I'm using Bounce2 to debounce, and it works totally as expected for everything except this one pin, which it reads as always being pressed down. Does this sound like it's being caused by the internal LED, and if so, is there anything I can do to stabilize this button without ripping out the soldering I've already one? Or is this probably being caused by something else? Any advice helps!

I've tried to make a shorter program to debug, here are the two I've used:

This prints out "Button pushed" as soon as it loads and doesn't stop no matter what I do
Code:
void setup() {
    Serial.begin(9600);
}

void loop () {
    if ( digitalRead(13) == LOW ) {
        Serial.println("Button pushed");
    }
}

This is more like what I actually have in my code. This will print "Button down" when I push the button, and "Button up" when I push another button (usually--it's sporadic whether or not that actually works), but not when I let go of the button on pin 13. It also starts out in a pressed state, so I have to hit another button before I can get it to show anything at all
Code:
#include "Bounce2.h"

Bounce b = Bounce();

void setup() {
    b.attach(13, INPUT_PULLUP);
    b.interval(25);
    Serial.begin(9600);
}

void loop () {
    b.update();
    if ( b.fell() ) {
        Serial.println("Button down");
    }
    if ( b.rose() ) {
        Serial.println("Button up");
    }
}

Quick Edit: This also may be a hardware problem, I just assumed it was a pin problem since it just happened to be a problem on the internal LED pin. If this sounds like something more likely to be hardware, I can find a way to test that instead :)
 
Last edited:
The first needs this line in setup() to provide pin 13 with LED power to go LOW on button press.

> pinMode( 13, INPUT_PULLUP );

So does Bounce on PJRC.com and this forum post suggest Bounce2 does as well : Bounce2-double-read
 
I definitely forgot to do that, thanks! Unfortunately, that hasn't fixed the problem. The first one has similar behavior (it spits out a ton of "Button pushed" immediately), but now it stops if I push any button, including the problematic one. The second one behaves the same.

Another quick edit: The second one will show the button up message a little more often now, and very rarely, will do it without needing me to push another button (that is, it'll work as expected)
 
The First code wholly unbounced will likely show a ton of on/off cycles - put a delay(50) after the print perhaps to hide those and show 'reliable' output.

Of course the Bounce2 library should have that if it is properly used and working.

Perhaps try the Bounce library noted on the PJRC.com site, or provided example that may be in bounce2?

This example does not use the same pin for Button and LED : (arduino)\hardware\teensy\avr\libraries\Bounce2\examples\bounce_button\bounce_button.ino

The LED with resistor combo may cause some issue?
 
Sorry, I may not have been clear enough in my OP--the bounce2 implementation is mostly fine, I have a few other buttons connected to the Teensy on different pins (basically all the odd pins from 1 to 31) and I'm using an extension of the code in the second sample I gave there for all of them; the others are all working 100% as expected, it's just this one that's giving me grief.
The pin selections right now are (unfortunately) semi-permanent, since when I was originally working on it a few years ago I had considered it working well enough to solder for some reason and the soldering to the board is in a place that's a little inaccessible without taking the whole thing apart :/.

(All this to say you're definitely right that using another pin would be a solution but with the amount of work that would take using the crappy tools I have I'm hoping there's a solution that doesn't involve me moving this to another pin)

I'll check out the PJRC.com Bounce library though and see if that helps!
 
The PJRC.com bounce library also works with all the pins that aren't 13, although on some of the higher ones (> ~15) it's a little more inconsistent
 
Status
Not open for further replies.
Back
Top