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

Thread: Teensy 4 : Sketch does not run unless Serial Monitor is open

  1. #1

    Teensy 4 : Sketch does not run unless Serial Monitor is open

    I compiled a sketch and it is running fine.

    I then close the Arduino IDE and disconnect power to the Teensy 4 (It is powered via Vin).

    When I reconnect power to the board, nothing happens until I reopen the Arduino IDE AND start the Serial Monitor.

    What may be causing this?

    Thanks in advance for the community's help.

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,737
    Posting the sketch would allow a good answer … a good guess is that there is something like :: while (!Serial); in setup that won't pass until the Serial Monitor connects.

  3. #3
    Thank you @defragster. I appreciate your prompt help to this frustrating problem.

    Here is my code. BTW, when USB cable is connected, the board does pull an IP Address.

    Code:
    void setup()
    {
      //------------------------------------------------------------
      Serial.begin(115200);
      delay(2000);
      Serial.println("Starting ...");
      //------------------------------------------------------------
      //https://www.pjrc.com/store/wiz820_sd_adaptor.html#init
      //https://github.com/PaulStoffregen/Ethernet
    
      pinMode(9, OUTPUT);
      digitalWrite(9, LOW);    // begin reset the WIZ820io
      pinMode(10, OUTPUT);
      digitalWrite(10, HIGH);  // de-select WIZ820io
      pinMode(4, OUTPUT);
      digitalWrite(4, HIGH);   // de-select the SD Card
      digitalWrite(9, HIGH);   // end reset pulse
      //------------------------------------------------------------
      Serial1.addStorageForRead(buf1, sizeof(buf1));
      Serial2.addStorageForRead(buf2, sizeof(buf2));
      Serial3.addStorageForRead(buf3, sizeof(buf3));
      //------------------------------------------------------------
    
      for (int i = 0; i < 2; i++)      // for (int i = 0; i < 3; i++)
      {
        leddar[i].init();
        sumTime[i] = 0;
      }
    
      //------------------------------------------------------------
      Serial.println("Ethernet WebServer Example");
      Ethernet.begin(mac, ip);
      if (Ethernet.hardwareStatus() == EthernetNoHardware) {
        Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
        while (true) {
          delay(1); // do nothing, no point running without Ethernet hardware
        }
      }
    
      if (Ethernet.linkStatus() == LinkOFF) {
        //Serial.println("Ethernet cable is not connected.");   //not working?
      }
      server.begin();
      Serial.print("server is at ");
      Serial.println(Ethernet.localIP());
    
      //------------------------------------------------------------
      Serial.print("Initializing SD card...");
      if (!SD.begin(chipSelect)) {
        Serial.println("initialization failed!");
        //return;
      }
      Serial.println("initialization done.");
      write2SD();
      readSD();
    
      //------------------------------------------------------------
      u8g2.begin();
      u8g2_prepare();
      String myVal = "jimmie";
      showU8G2(11, 12, myVal);
      delay(2000);
      //------------------------------------------------------------
    
      Serial.println("------------->>>>  Starting");
    }
    Last edited by jimmie; 08-30-2019 at 02:44 AM. Reason: edits.

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,737
    That is just code for setup() , not a complete sketch - the typical problem is the noted while(!Serial) which doesn't show there.

    It may be that one of the .init()/.begin() functions stops to wait for !Serial to exist?

    Without the Serial Monitor printing it will be hard to say where it stops without adding blink output to LED_BUILTIN (#13) or to a UART or something for an indication of where the code stops to figure out why.

  5. #5
    Thank you @defragster. Your input helped me debug further.

    You were right about the culprit.

    I found out that the library I am using has the Leonardo while (!Serial)

    Thanks again.
    Last edited by jimmie; 08-30-2019 at 03:06 AM.

  6. #6
    Senior Member
    Join Date
    Oct 2012
    Location
    Portland OR
    Posts
    676
    Your setup code includes: "Serial.println("Starting ...");" which uses the Teensy USB-serial device. Currently on T4 I believe if you send any characters to the USB-Serial device (using Serial.X instead of Serial1.X etc for a real UART) then the serial interrupt system is disabled until the USB endpoint is accessed and the data is read out by the USB host PC. I'm not sure it is supposed to work that way, I don't think other Teensy models do that; but apparently for now, it does work that way. This was reported here: https://forum.pjrc.com/threads/57325...l=1#post214149

  7. #7
    Thank you JBeale.

    The culprit was the
    Code:
    while(!Serial)
    statement in the library I was using.

    The only problem remaining now is the SD behavior on the T4 .... :-).

  8. #8
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,737
    Quote Originally Posted by JBeale View Post
    Your setup code includes: "Serial.println("Starting ...");" which uses the Teensy USB-serial device. Currently on T4 I believe if you send any characters to the USB-Serial device (using Serial.X instead of Serial1.X etc for a real UART) then the serial interrupt system is disabled until the USB endpoint is accessed and the data is read out by the USB host PC. I'm not sure it is supposed to work that way, I don't think other Teensy models do that; but apparently for now, it does work that way. This was reported here: https://forum.pjrc.com/threads/57325...l=1#post214149
    This isn't a case of Serial.available not incrementing. I ran a sample and that problem is real - but that is reading input - which works - just not having .available() be reliable yet.

    Teensy 4 is perfectly good starting up and printing when Serial is not online so as found the problem was the embedded " while (!Serial) " This have been working well through T4 Beta period.

  9. #9
    Senior Member
    Join Date
    Oct 2012
    Location
    Portland OR
    Posts
    676
    Thanks for that correction defragster, I did misinterpret the problem. I would correct or delete my earlier post but the forum no longer seems to allow that.

Posting Permissions

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