{RESOLVED} Stupid Person Using Teensy 3.5 For First Time

Is there a wrong way to set up inputs and outputs?

That was rhetorical. I’m sure there are plenty of terrible ways to attempt such a task. But I’m definitely having trouble with the inputs on my Teensy, and wanted to see if it’s something I’m doing wrong or if there is some microscopic fine print in the documentation telling me I can’t accomplish this task.

My controller board is basically divided in half - 20 pins acting as outputs (eventually to be connected to solenoid drivers) and 20 pins acting as inputs (to be connected to microswitches). I’ve written up a control system that links them together in the way I wanted, but have run into a little issue.

As is preferred practice, I’ve minimalized it into the smallest program that shows the problem. Here’s some very simple test code, which works exactly as intended.

void setup() {
  pinMode(13, OUTPUT);
  pinMode(20, INPUT_PULLUP);
}

void loop() {
  digitalWrite(13, !digitalRead(20));   // set the LED on
  delay(20);
}

When I jumper across from ground to pin 20, the LED flicks on, and stays on until I disconnect the wire. Good. But then, I choose to set up a few more pins for output…

void setup() {
  for(int i = 0; i < 20; ++i)
  {
    pinMode(i, OUTPUT);
  }
  pinMode(20, INPUT_PULLUP);
}

void loop() {
  digitalWrite(13, !digitalRead(20));   // set the LED on
  delay(20);
}

… and suddenly, as soon as I upload, the LED comes on and stays on, and remains that way regardless of how much I poke pin 20 with my probe wire. Individually activating the outputs shows that activating certain ones (including 8 and 19 for example) seem to trigger the problem.

This obviously puts a damper on my grand plans for this device. Is there some sort of setup that I need to do to make sure the pins behave as I want?

That's a pretty simple description of the problem. I will try to test it on one of my Teensy's tomorrow. I don't see anything obvious for why that is not doing what you expect.

Do you currently have anything connected to those outputs?

Does it make a difference if you explicitly write the outputs HIGH or LOW in the loop that sets the pin mode?

I think it would make more sense to ask this on the PJRC Forum.

Pete

@MorganS: Thank you! I will try that and have a look at the results when I get back from work. I'll try testing some voltages as well. Currently the board is disconnected from any external devices, save for the USB cable temporarily tethered to my PC.

@el_supremo: In hindsight, that probably would have been good. This just happened to be the first place I thought of, given I've been working in an IDE with the Arduino name plastered all over it. I'll see if the problem gets solved here and otherwise I'll go check out their forums.

Well, I feel extremely stupid at this point. Thanks for the help anyway, guys.

While toying around with the board, I happened to turn it over. The board was still stuck to the shipping foam during all of this since I didn't have a mounted socket to install it into. Lo and behold, the back of the shipping foam had a sticker reading "Anti-static foam is conductive - remove before use."

I can't believe that in all the tests I did, I never once thought to turn it over and look at the back. Lesson learned.

Nice one! Thanks for the feedback.