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

Thread: Teensy 3.5 serial console not active in setup()

  1. #1

    Teensy 3.5 serial console not active in setup()

    Arduino 1.8.9
    OsX 10.11.6
    Teensydunio 1.46 B10

    I could not get messages in setup() to appear in the console. I reduced it down to this:

    Code:
    void setup() {
      Serial.begin(9600);
      Serial.println("Hello from Teensy");
    }
    void loop() {}
    The message will not appear in the console until I do this:

    Code:
    void setup() {
      Serial.begin(9600);
      delay(2000);
      Serial.println("Hello from Teensy");
    }
    void loop() {}
    Not sure of the time it takes for the console to connect but the 2 second delay definitely fixes the issue.

    What am I missing?

    Edit: not sure if this matters but the board is mounted on a Talldog DIP-64 Breakout. Powered by USB cable, VIN jumper on.
    Edit: Not a breakout issue, just tried a virgin 3.6 board and it too has the same issue. Teensy clock rates don't matter either.
    Last edited by aFewBits; 06-08-2019 at 12:16 AM. Reason: added notes

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,136
    After .begin() add this:
    Code:
      while(!Serial);
    This gives the Serial device time to show up.

    Pete

  3. #3
    Thank you, that will get me moving off of full stop.

    Was not aware it was required with Teensy and I never needed it prior to now. Will do some tests on older versions. (1.8.7 & 1.44)

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,032
    Teensy has Native USB on the processor - so it disconnects during programming, unlike Arduino devices with a USB device off chip that stays connected during programming so the computer doesn't lose the connection.

    Teensy hits setup() 300 milliseconds after powering up and getting the processor initialized. Then Serial can take another 30 or 200+ milliseconds to have the host usably connected - so getting started printing before Serial is online can lose stuff for some milliseconds without a wait. And if it Serial Monitor is not active until you connect it that adds the human time.

    So the while(!Serial); will then wait forever until connected. If Serial is handy but not critical using something like : while(!Serial && millis() <2000); will in that case wait up to 2 seconds and then proceed - that is important to get right if the Teensy needs to run when a host doesn't connect - like a battery or other situation.

Posting Permissions

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