Teensy 4.1 Do pins 11+12 not work for pinMode(11, INPUT_PULLUP) ??

asdf44

Member
Do pins 11,12 work for pinMode INPUT_PULLUP?

I have the code in a loop using various pins 10-12, 26, 29, 32-35, 40. But only pins 11, and 12 do not work

simplified the code would look like this:

Code:
setup() {
  pinMode(11, INPUT_PULLUP);
}
void loop() {
   sw3.bounce.update();
   if(sw3.bounce.fallingEdge()) {
      Serial.println("11");
   }
}

The actual code is:
Code:
const int NUM_SWITCHES = 12;
SwitchInfo switches[NUM_SWITCHES] = {
  SwitchInfo("SWITCH_INCREASE",              33, DEBOUNCE_SWITCH,           KEYBOARD, "Y", 0, 0, 0, 0), //S1  working
  SwitchInfo("SWITCH_DECREASE",              34, DEBOUNCE_SWITCH,           KEYBOARD, "Z", 0, 0, 0, 0), //S2 working
  SwitchInfo("SWITCH_PREVIOUS",              11, DEBOUNCE_SWITCH,           KEYBOARD, "1", 0, 0, 0, 0), //S3 FAILS!!!
  SwitchInfo("SWITCH_NEXT",                  12, DEBOUNCE_SWITCH,           KEYBOARD, "2", 0, 0, 0, 0), //S4 FAILS!!!
  SwitchInfo("ROTARY_SVG_WIDTH_CLICK",       18, DEBOUNCE_ROTARY_SWITCH,    KEYBOARD, "C", 0, 0, 0, 0), //E1 working
  SwitchInfo("ROTARY_VIEWBOX_WIDTH_CLICK",   15, DEBOUNCE_ROTARY_SWITCH,    KEYBOARD, "F", 0, 0, 0, 0), //E2 working
  SwitchInfo("ROTARY_SVG_Y_CLICK",           35, DEBOUNCE_ROTARY_SWITCH,    KEYBOARD, "I", 0, 0, 0, 0), //E3 working
  SwitchInfo("ROTARY_VIEWBOX_Y_CLICK",       40, DEBOUNCE_ROTARY_SWITCH,    KEYBOARD, "L", 0, 0, 0, 0), //E4 working
  SwitchInfo("ROTARY_VIEWBOX_HEIGHT_CLICK",  29, DEBOUNCE_ROTARY_SWITCH,    KEYBOARD, "O", 0, 0, 0, 0), //E5 working
  SwitchInfo("ROTARY_SVG_HEIGHT_CLICK",      32, DEBOUNCE_ROTARY_SWITCH,    KEYBOARD, "R", 0, 0, 0, 0), //E6 working
  SwitchInfo("ROTARY_VIEWBOX_X_CLICK",       26, DEBOUNCE_ROTARY_SWITCH,    KEYBOARD, "U", 0, 0, 0, 0), //E7 working
  SwitchInfo("ROTARY_SVG_X_CLICK",           10, DEBOUNCE_ROTARY_SWITCH,    KEYBOARD, "X", 0, 0, 0, 0)  //E8 working
};
void setup() {
  Serial.begin(9600);
  for (int i = 0; i < NUM_SWITCHES; i++) {
    pinMode(switches[i].pin, INPUT_PULLUP);
  }
}
void loop() {
  for (int i = 0; i < NUM_SWITCHES; i++) {
      switches[i].bounce.update();
      if (switches[i].bounce.fallingEdge()) {
           Serial.println(String("fallingEdge Switch SingleCharPrint switch i:") + i);
      }
  }

So either pins 11,12 do not work or it's a hardware issue. However no way it's a hardware issue. I'm using a continuity tester and I can verify that the circut opens and closes as expected.

Help!
 
Here is the code

If you look at lines 153-154
Code:
  SwitchInfo("SWITCH_PREVIOUS",              11, DEBOUNCE_SWITCH,           KEYBOARD, "1", 0, 0, 0, 0), //S3
  SwitchInfo("SWITCH_NEXT",                  12, DEBOUNCE_SWITCH,           KEYBOARD, "2", 0, 0, 0, 0), //S4

you can see that there is nothing different except the pin numbers of the 2 non-working switches when compared to the other 10 working switches
 
To check the hardware you can use a simple sketch without any library, e.g. use the pushbutton pullup example from tutorial 3.
If the pins are working you can rule out any problems with your cable connections or the Teensy hardware.

From a quick look at the code I couldn't find where
Code:
switches[i].pin
is set. That is probably working somewhere as intendend.

Is it possible that there is a pin conflict with other libraries? SD? Or anything else that uses these SPI pins?
 
Neither of the programs you showed actually compile if copied into Arduino IDE. Even the simple one, if the missing "void" is added on setup, still does not compile because "sw3" is undefined.

However, this simple program does compile.

Code:
void setup() {
  pinMode(11, INPUT_PULLUP);
}
void loop() {
  if (digitalRead(11) == LOW) {
    Serial.println("pin 11 is low");
    delay(50);
  }
}

I ran it just now on a Teensy 4.1. Definitely does print "pin 11 is low" when I touch a wire between pin 11 and GND. Here's a screenshot of it in action.

1736339808305.png


Please use this simple program to test your hardware.

Maybe pin 11 on your board really is damaged somehow? Or maybe something about your program is defective?

One thing I can say for sure, pin 11 really does work properly on undamaged hardware. Hopefully you can see that from this simple test.
 
Last edited:
Looking at your code on github (which I'll admit, I have so far not tried compiling or running), I'm pretty sure the problem is at line 514.

Code:
  if (!SD.begin(4)) {
    Serial.println("Error reading SD card. Using default configuration v12");
  } else {
    Serial.println("SD card found. Using configuration");
    readConfiguration();
  }

Calling SD.begin(4) turns on the SPI port. Pins 11, 12, 13 become controlled by SPI for data communication with the SD card. When controlled by SPI, those pins become inaccessible for ordinary GPIO.
 
Sorry for the confusion folks! I was trying to boil down the code to the simplest possible version to explain my question without asking you all to dig through 600 lines of code.

Someone suggested to me that I should change SD.begin(4) to SD.begin(BUILTIN_SDCARD) because "Specifying BUILTIN_SDCARD will use the dedicated SDIO interface for the onboard microSD slot and not use SPI"

I'll give this a shot, but perhaps you'd know better if this is a good course of action to take. Unfortunately I've already built the PCB boards so I'm kind of stuck with these pins.

Thank you so much for your help!
 
Confirm BUILTIN_SDCARD will not conflict with pins 11, 12, 13. On Teensy 4.1 it uses pins 42-47.

If you're only storing a small amount of data, you could also use LittleFS_Program which doesn't require adding a SD card or any other hardware. But do be aware writing to the program flash memory can stall your program for several milliseconds while the memory is busy writing.
 
Thank you it is working. I wanted the SD card so that I could allow users remap the keys on the keyboard. I added a video of what the thing looks like. On the github page if you care to see it.
I appreciate you spending time on my problem, I was thinking this was going to be much larger and more expensive to fix.
 
Back
Top