digitalRead() the Teensy's 3.3V logic? (digitalRead not working)

Status
Not open for further replies.

mcooi77

Member
I'm working on a final class project with my Teensy 3.2 and the Audio shield. The project has several pots and buttons hooked up to the remaining (free) analog pins. I'll also start by saying I read the Teensy Digital Input/Output documentation found here: https://www.pjrc.com/teensy/td_digital.html. No luck.

The Arduino digitalRead() function appears to only work with 5V logic, or I'm just missing something very obvious here. I feel compelled to also state this isn't close to my first time using an Arduino board. I tried a simple digitalRead() using the code below:

Code:
const int pos1 = 16;   //"top" position
const int pos2 = 17;   //"bottom" position
int selectTop;
int selectBtm;

void setup() {
  Serial.begin(9600);
  pinMode(pos1, INPUT_PULLUP);
  pinMode(pos2, INPUT_PULLUP);
}

void loop() {
  selectTop = digitalRead(pos1);
  selectBtm = digitalRead(pos2);

  if(selectTop == LOW)
  {
    Serial.print("Switch is in the TOP position.");
    Serial.println("");
  }
  else if(selectBtm == LOW)
 {
    Serial.print("Switch is in the BOTTOM position.");
    Serial.println("");
 }
}

My Oscope confirms that during switch "position 1" I am indeed being pulled down to 0V, and at all other times reading a steady 3.1V high. Likewise for the "position 2". Yet, for the life of me I can't get anything showing on the Serial monitor. Not sure what I'm missing here or than the digitalRead must be looking for a "regular" 5V high and the 3V "no mans land" isn't doing enough to register as a "HIGH." But if that was true, not sure why a 0V signal wouldn't do anything either.

If I switch over all the "Digital..." functions to analog, reading below an arbitrary threshold of 200, the simple code above works flawlessly.
 
Thanks for the suggestion! For reference of anyone who stumbles across this thread: I wasn't able to find the cause. But after a restart of everything the next morning seems to be working. Additionally, perhaps check for errant logic statements, "mixing if/else if" statements, or digitalWrite high and pinMode(input) conflicting statements.
 
Status
Not open for further replies.
Back
Top