Serial Monitor does not open after Reset

Frank B

Senior Member
The Serial Monitor closes, but does not re-open on a Teensy-reset.

Tested with software-reset:
Code:
 void setup() {
  Serial.begin(9600);
  Serial.print("Bye, World");
  delay(5000);
  *(volatile uint32_t *)0xE000ED0C = 0x5FA0004;
}

void loop() {}

Wasn't that fixed a long time ago?
 
Last edited:
Hi. I just tested your code. Upon reset the serial monitor closes and I have to reopen it. I just click on the SM icon again. It disconnects from the system then reconnects automatically.
 
Ok, I think, I missunderstood. So you have to click the button every time (like me) ? That's not "automatic" for me..

Would be better if could re-connect without having to click a button..
 
Indeed very painful to use IDE SerMon - for me the window stays open but doesn't reconnect until closed { SerMon text gets grayed when offline } and opened IIRC - that's another great thing about TyCommander.
 
That's the effect I am seeing as well. Would be nice if it stayed opened under the Arduino ide.
 
Got curious so I did a little googling and found a couple of interesting things:

A post from 2011 on the Arduino forum complaining about the same issue: http://forum.arduino.cc/index.php?topic=71178.0

Something called Meguno: Aduino upload monitor: http://www.megunolink.com/documenta...15475200:1&utm_referrer=https://www.bing.com/

Seems the problem is with avrdude opens the port in exclusive mode among other things.

Don't know enough to figure out if you can change this within the configure file.

Cheers

EDIT: I am pretty stubborn. Figured had to be an issue at some point somewhere with Arduino in general. Came across this that might be of interest: https://github.com/arduino/Arduino/pull/2742 and https://github.com/arduino/Arduino/pull/115
 
Last edited:
The Serial Monitor closes, but does not re-open on a Teensy-reset.

Tested with software-reset:
Code:
 void setup() {
  Serial.begin(9600);
  Serial.print("Bye, World");
  delay(5000);
  *(volatile uint32_t *)0xE000ED0C = 0x5FA0004;
}

void loop() {}

Wasn't that fixed a long time ago?
Does the USB actually disconnect and reconnect in Windows during this type of reset? If it doesn't then the "Teensy Monitor" probably won't see anything.

Got curious so I did a little googling and found a couple of interesting things:

A post from 2011 on the Arduino forum complaining about the same issue: http://forum.arduino.cc/index.php?topic=71178.0

Something called Meguno: Aduino upload monitor: http://www.megunolink.com/documenta...15475200:1&utm_referrer=https://www.bing.com/

Seems the problem is with avrdude opens the port in exclusive mode among other things.

Don't know enough to figure out if you can change this within the configure file.

Cheers
Teensyduino uses TeensyMonitor.java instead of the standard SerialMonitor.java which has Threaded approach that monitors the connection where the Arduino Serial Monitor does not.
 
Hi Duff. What actually happens is that the Arduino serial monitor stays open but does not automatically reconnect after reset or reupload of a sketch. You have to physically click on the SM button to get it to reconnect. At least I am getting to understand where things are getting done :)

CLARIFICATION: By staying open I mean the monitor window stays open but it indicates that the TeensyMonitor is closed not online
 
Last edited:
Ok. If I am reading the code correctly. It looks like if the TeensyMonitor window is open and online it will suspend the thread and take the monitor offline. It seems to resume it but never calls reopener to start the monitor and bring it back online. The code is in a few places to make this happen. Not sure how to create my own version of Teensyduino to try it out. Maybe somebody can point me in the right direction or tell me if I am off base.
 
Not sure how to create my own version of Teensyduino to try it out. Maybe somebody can point me in the right direction or tell me if I am off base.
I downloaded Paul's Arduino version and tried to build it but it is missing files that the build script needs. If you want to build Arduino this guide will show you how but it won't have Teensyduino, maybe Paul can provide how he builds Arduino for Teensy. I would like to use some more advanced java libraries for the SerialPlotter so you can have things like bar graphs for the Audio Libraries FFT.
 
didnt read this thread yet but i had this issue running teens3.5 on an external usb hub, direct worked fine, hub intermittantly didnt work on reset for teensy, what i did was goto device manager and turned off usb power saving, that fixed it
 
Now here is the funny thing. I decided to check using an Arduino Mega 2560 what happens if I hit the reset the button while the sketch is running to see if I get the same behavior. Guess what. I don't. The Arduino Serial Monitor stays open and after reset it starts to print my test message. The same thing happens if I do an upload while the Arduino Serial Monitor is open. So, now have to see what has to get changed to make the two match.
 
Not funny at all. The Mega 2560 has a USB interface chip independent of the processor. The USB stays online connected to the PC while the processor resets.

The Teensy USB interface is native hardware on the core processor, when that is reset or restarted after upload the USB link necessarily drops.
 
Is the following the same contested behavior?

Run any program with while(!Serial); in setup:
edit: "while(!Serial);" not necessary, the helloWorld example is sufficient.

if downloading again while running, all OK Serial Monitor restarts

However, pressing prog button, downloads program (obviously), but Serial Monitor stays greyed (closed)
pressing SM button removes closed monitor and opens a new one
 
@defragster. Didn't think of that when I did the test. After awhile you just take things for granted and forget about whats under the hood.

@WMXZ. Yep. That's exactly what's happening. On uploading a sketch it will restart automatically (TM for teensyMonitor, goes from showing closed to showing online and will start printing such as helloworld). If you hit the reset button the TM shows that the connection is closed and stays grayed out.
 
Use TyCommander (aka TyQt ). It provides a much more alert and aware serial monitor. Does HID and USB, can also integrate to Arduino and replace TeensyLoader. It also identifies each Teensy by Serial# when multiples are connected to upload to chosen device. And has a GUI with RESET button. Also has a companion command line interface.
 
@defragster. Just looked at tyQT and it will definitely do the job. But there has to be way to accomplish this within teensyduino with out having to use a third party application. If not the tyQT it is. Haven't been able to find where to put it yet though.
 
@defragster. Just looked at tyQT and it will definitely do the job. But there has to be way to accomplish this within teensyduino with out having to use a third party application. If not the tyQT it is. Haven't been able to find where to put it yet though.

agree.
I can do it with my finger, but that is not the issue. I use TD for easy development. Otherwise I use my eclipse IDE which I set up to foce me to shutdown putty before uploading.
Every one has an alternative solution.
 
Last edited:
maybe Paul can provide how he builds Arduino for Teensy.

Assuming you're building my patched version of Arduino, the process is pretty simple. Just run "ant" (command line) in the build folder. Then copy app/pde.jar and arduino-core/arduino-core.jar to the lib folder of an already-installed copy of Arduino+Teensyduino.

Or if using Linux or Mac, delete those two jar files from lib and replace them with symbolic links to the compiled copies in the source tree. That's what I do when I work on the Java side. It's a *lot* faster than rebuilding the packages! :)

If you want to use a process similar to Arduino's, you probably can. I always put the build.xml changes in their own commit, so at least in theory anyone could try to apply the Java patches without my hacks to the build process. Then you'd want to copy the hardware/teensy folder (from an already installed copy) into the freshly complied & packaged copy of Arduino.

The installer also patches some of the stuff in File > Examples (mainly just the comments). If you want to get a perfectly matching result to the Teensyduino installer, don't forget those files. For a perfect match, you also need to use the same or a very similar JDK version. That's actually the first step I do for every Arduino release... figure out which JDK version they used, and then I rebuild Arduino without any patches and I do a full binary compare of all the compiled .class files from both jars. You can probably skip these paranoid steps if just experimenting. But if you do compare files, jars need to be checked by extracting and binary comparing their contents, since the jar itself has a small amount of unimportant metadata that never matches.
 
TyComm just gets unzipped into a directory you like. Then you execute it in place from there ( Windows may require it to be unblocked to Run ).

It would be nice to have the IDE be perfect - but because of, and in spite of, Paul's great efforts the Teensy isn't like other devices. Keeping it working and improving over time is enough to expect - Koromix made his dedicated solution and keeps after it well. In fact recent 'PURE_CODE' change broke check made before HEX upload - I just got a reply from yesterday email, and fix should be out this week.

I use TyComm almost exclusively since I got here - except when testing something new in a build. Closing TLoader and IDE and Integrate to Arduino is nice as noted - takes away the system JAVA burden of the IDE running SerMon - though that has improved, TyComm is more alert to how the Teensy behaves. Koromix has made a great Addon - other than all things PJRC - it is the best thing extending Teensy I've found. I often end up with multiple Teensy units online and TyComm allows multiple Serial windows not only to upload - but to view output independently. Teensy loader is functional, but not something that has been extended to the extent of TyComm, which was why Koromix made it and keeps it running and extending it.
 
@Frank - Could you please try with the original 400ms delay in pins_teensy.c? It was recently changed to this:

Code:
        // for background about this startup delay, please see these conversations
        // https://forum.pjrc.com/threads/36606-startup-time-(400ms)?p=113980&viewfull=1#post113980
        // https://forum.pjrc.com/threads/31290-Teensey-3-2-Teensey-Loader-1-24-Issues?p=87273&viewfull=1#post87273
        delay(50);
        usb_init();
        delay(350);

I believe what may be happening is 50 ms isn't enough time for Windows 10 to detect the USB port disconnected.

I tested just now on Linux, using this slightly modified code:

Code:
void setup() {
  pinMode(13, OUTPUT);
  pinMode(13, HIGH); // LED on when wait for serial monitor
  Serial.begin(9600);
  while (!Serial) ; // wait for serial monitor to reopen
  pinMode(13, LOW); // LED off when connection to serial monitor
  Serial.print("Bye, World");
  delay(5000);
  *(volatile uint32_t *)0xE000ED0C = 0x5FA0004;
}

void loop() {}

I see the serial monitor disconnect, but it doesn't reconnect. If I look in /dev, I see the port reappeared as /dev/ttyACM1. But the serial monitor is still looking for /dev/ttyACM0 to reappear. Looks like 50 ms just isn't enough time for the host controller + host driver to fully disconnect and free the driver instance. I'm not sure exactly what Windows does, but I'm pretty sure it's not good.
 
Hi Paul,
some observations:

- with original delay, windows plays the "usb disconnect device" sound - but not the "usb connect device" sound. Perhaps this is not important and a windows problem. Or, maybe, increasing the 50ms would be a good idea.
- with increased delay (1000ms), windows plays both sounds.

- increased delay does not help the arduino serial monitor (and LED stays on)

BUT:
With original delays (50ms/350ms) the TYQT monitor works well and reconnects automatically on my Windows10 machine. It must be a Teensyduino problem (?!)

TYQT has an other problem for me, as it does not want to upload new code.
I had to: Upload code with the teensy loader, close it, start TYQT. (But that's a TYQT thing)

I've corrected your code a bit ;-) (copy & paste error with pinMode)

Code:
void setup() {
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH); // LED on when wait for serial monitor

  Serial.begin(9600);
  while (!Serial) ; // wait for serial monitor to reopen
  digitalWrite(13, LOW); // LED off when connection to serial monitor
  Serial.print("Bye, World");
  delay(5000);
  *(volatile uint32_t *)0xE000ED0C = 0x5FA0004;
}

void loop() {
  
  }

EDIT:
During my testing, I managed to "brick" the teensy. It wasn't recognized by Windows anymore and seemed "dead".
I guess, TYQT was part of the problem.
The Teensyloader wasn't running, but the Taskmanager showed a running instance of teensyreboot.
Killing it, closing TYQT, reflashing with the teensyloader (after doing the "delete" trick with 15 sec button press) helped.
 
Last edited:
Back
Top