PDA

View Full Version : Teensy 3.0 doesn't restart on serial monitor



teckel
11-14-2012, 06:36 PM
I was trying to debug some code running on a Teensy 3.0 and was getting some really odd results. After a lot of going back and forth, I figured it out. When you open the serial monitor in the Arduino IDE, it doesn't restart the Teensy 3.0 as it does for ATmega boards including the Teensy 2.0. For example, see this sketch:



int cnt = 1;

void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
digitalWrite(LED_BUILTIN, HIGH);
}

void loop() {
Serial.println(cnt++);
delay(1000);
}


On an ATmega board (including Teensy 2.0), every time you open the serial monitor window in the Arduino IDE, the LED blinks and it starts the counting at 1, then 2, etc. But, run the same sketch on the Teensy 3.0 and you'll get something totally different. The LED doesn't blink and the counter will display how many seconds since you uploaded the program or the last time you hit the reset button. For example, 5 then 6, etc. If you close the serial monitor, wait 10 seconds and open the serial monitor again, the LED won't blink and the display will read something like 17, 18, etc.

Try this, with the above sketch on a Teensy 3.0, try to get the serial monitor to start with 1, near impossible (best I could do was 2). Because of this, all sketches where you want to get a serial output you need to start the sketch with a several second delay, hit the reset button on the Teensy 3.0, then open the serial monitor.

Am I missing something or doesn't the Teensy 3.0 have the ability to trigger a restart via the serial monitor?

Tim

Nantonos
11-14-2012, 06:40 PM
I would say that not restarting every time you open a serial monitor is a feature, not a bug. If you want it to restart, press the restart button.

Nantonos
11-14-2012, 06:43 PM
Because of this, all sketches where you want to get a serial output you need to start the sketch with a several second delay, hit the reset button on the Teensy 3.0, then open the serial monitor.


This is the benefit of the Arduino ERW environment (a lightly modified Arduuino release with some bug fixes and improvements). One of the the features it gives is 'upload then open serial monitor'.

teckel
11-14-2012, 07:04 PM
I would say that not restarting every time you open a serial monitor is a feature, not a bug. If you want it to restart, press the restart button.

Not considering the ramifications this will cause, for consistency, it should work the same as the 8bit ATmega. Also, it's not a feature at all, as a simple sketch like below won't work on the Teensy 3.0:



void setup() {
Serial.begin(115200);
}

void loop() {
Serial.println("Hello world!");
while(1) {}
}


This sketch doesn't work on the Teensy 3.0, because you can never start the serial monitor fast enough to see the output.

It's also a complex task for testing. You can't hit the reset button on the Teensy 3.0 when the serial monitor is open. So, to do multiple tests you need to always, close serial monitor, reset button, wait, open serial monitor. This is on top of adding a several second delay to the start of every sketch. If you don't exactly follow these steps, it won't work. Forget closing the serial monitor before hitting reset, sorry, won't work.

A different programming environment is a moot point as Teensy 3.0 is designed to work in the Arduino IDE, as it should.

Tim

JBeale
11-14-2012, 07:11 PM
Teensy 3 does not yet auto-restart on serial port reset in the way 8-bit Arduino does, but that feature is planned. Due to the way Teensy 3 does USB, it is a non-trivial task.

See "Missing Features, Coming Soon...." at this post
http://www.kickstarter.com/projects/paulstoffregen/teensy-30-32-bit-arm-cortex-m4-usable-in-arduino-a/posts/331757
and also:
http://forum.pjrc.com/threads/118-Serial-port-monitor-problem?p=334&viewfull=1#post334
http://forum.pjrc.com/threads/118-Serial-port-monitor-problem?p=340&viewfull=1#post340

teckel
11-14-2012, 07:19 PM
Thanks! Not being part of the Kickstarter, I didn't look there nor know that's where the known problems are listed. I did search these forums for serial problems, but didn't find that thread. Sorry for asking a duplicate question already answered.

I would suggest a Teensy 3.0 forum with a sticky "known issues" thread. That would probably catch most problems like this.

Tim

Jp3141
12-17-2012, 01:02 AM
Not considering the ramifications this will cause, for consistency, it should work the same as the 8bit ATmega. Also, it's not a feature at all, as a simple sketch like below won't work on the Teensy 3.0:



void setup() {
Serial.begin(115200);
}

void loop() {
Serial.println("Hello world!");
while(1) {}
}


This sketch doesn't work on the Teensy 3.0, because you can never start the serial monitor fast enough to see the output.

It's also a complex task for testing. You can't hit the reset button on the Teensy 3.0 when the serial monitor is open. So, to do multiple tests you need to always, close serial monitor, reset button, wait, open serial monitor. This is on top of adding a several second delay to the start of every sketch. If you don't exactly follow these steps, it won't work. Forget closing the serial monitor before hitting reset, sorry, won't work.

A different programming environment is a moot point as Teensy 3.0 is designed to work in the Arduino IDE, as it should.

Tim

I ran into this too, so I use:
while (!Serial && (i++ < 10*10)) { // or ~ 10 seconds
digitalWrite(LEDpin, HIGH); delay(50); digitalWrite(LEDpin, LOW); delay(50); }

This will hang around for about 10 s, or until the serial monitor starts -- best of both worlds