First Serial.print not seen on USB

Status
Not open for further replies.

bboyes

Well-known member
I'm attempting to get into some major code on Teensy3, which we are using to prototype a commercial product. I was not seeing serial output (a simple "blah blah test program" message) at the end of setup() so I've backed up to a really simple blink program. And even it does not work as expected.

This is on Win7 Pro 64, Arduino 1.05

I was not seeing Serial.print output when it was at the end of setup(). I'm not sure if it is OK to have Serial.print() in setup() (since it is really a constructor, right?) so I have moved it to loop() and moved the rest of my code into a while(1).

Even with the huge delay I usually don't see the one-time only Serial.print output over the Teensy3 USB in the Arduino 1.05 Serial Monitor. Sometimes, maybe 20% of the time, it is there.

The delay is there to give me time to manually open the Serial Monitor window. In an older Arduino, that would cause a reset of the module but I seem to recall that feature went away a while back.

I'm baffled. If serial output doesn't occur as expected, I worry that other things are also not executing as they should.

const uint8_t PIN = 13;
const uint16_t PERIOD = 1000; // on and off 50% of this time
const uint16_t HALF = PERIOD/2;

void setup() {
// initialize the digital pin as an output.
Serial.begin(115200); // use max baud rate
pinMode(PIN, OUTPUT);
}

void loop() {

delay(5000);
Serial.print("Blink period "); // This ouptut almost never displays!
Serial.print(PERIOD);
Serial.print(" msec on pin ");
Serial.println(PIN);

while (1)
{
digitalWrite(PIN, HIGH); // set the LED on
Serial.print(1);
delay(HALF); // wait for some msec
digitalWrite(PIN, LOW); // set the LED off
Serial.println(0);
delay(HALF); // wait for some msec
}
}
 
Last edited:
Well, I have learned a couple of things. The delay at the start of loop needs to be more than 3000 msec or the first serial output is lost. Also if the Serial Monitor window is only a few lines tall, the first output scrolls the window down (it doesn't need to be scrolled for just one line of display!) so the first line of serial output is hidden. Perhaps it really takes several seconds to configure the Serial Monitor port and receive characters through Java in Windows?
 
Also the Arduino IDE gets insanely slow and the Serial Monitor stops responding. Is there some known issue with 1.05? It has hung up like this twice. Once it died ungracefully with a Java AWT error:
11-6-2013 10-30-30 AM.png
Maybe time for a whole PC reboot. Have not seen this sort of trouble previously.
 
With the Teensy3 the Serial.prints() will start the instant the setup() routine runs, whether or not there's anything connected to the serial port, with no buffering. So the first Serial.print() is really happening, there's just nothing to see it.

Your delay is one workaround but what I usually do is put this in setup:

Code:
while (!Serial);

which stops the Teensy until you've opened the serial port.

Regarding your other issue, the only time I've seen that is when I don't have any delays between Serial.prints() and the IDE's serial monitor can't keep up and gets overloaded. Most of the time I've just slowed things down but for one project I had strict timing requirements and ended up just switching to putty to watch the output.

Good luck!
 
That while (!Serial) works really well. Of course some of the time I want the code to start without Serial Monitor open so I can combine with a longish timeout such as

while((!Serial) && (millis()<5000)); // wait until serial monitor is open or time delay
 
Yes, this restart-upon-serial-monitor-open and the USB disk stuff are the 2 features from Teensy 2.0 that I _still_ have not yet ported over to Teensy 3.0.

Sorry, it's on my to-do list, but at a lower priority than a bunch of other stuff.
 
I've seen that java error here. Or at least I think I have... difficult to be 100% certain if it's really the same thing from only that screenshot.

It seems the Arduino IDE leaks a lot of memory as the Serial Monitor window accumulates more text. This isn't unique to Teensy, but only Teensy and Arduino Due can transmit fast enough for it to become a huge problem (Leonardo is relatively slow, despite having the same hardware as Teensy 2.0). It's not only the text itself, but a tremendous amount of overhead. How it can waste so much memory is a mystery to me. I have looked into this a couple times, but I'm afraid that part of the IDE involves a lot of event passing through Java Swing UI layers which are beyond my knowledge of Java.

The code is all open source. If someone who's a Java expert wanted to look into this, I could write up a summary to at least get them started.
 
When I reset my Teensy3, win7 looses the serial port and putty stops receiving serial output from the Teensy3. I need to kill the putty window and power cycle the Teensy3, and resetart putty in order to continue. My Uno just restarts over with no hassles since the port doesn't go away.
 
Status
Not open for further replies.
Back
Top