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

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

  1. #1
    Junior Member
    Join Date
    Oct 2017
    Posts
    9

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

    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.

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Location
    Canada
    Posts
    834
    try removing the "else"? its a different comparison

  3. #3
    Junior Member
    Join Date
    Oct 2017
    Posts
    9
    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.

Posting Permissions

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