unable to read serial data

Status
Not open for further replies.

Mann

Member
Hi,

I recently got started on my new Teensy 3.6 and I tried running the HelloSerialMonitor example, then I opened the serialmonitor on the Arduino IDE. The output froze after a few lines of "hello world" and the window wouldn't close until I press the reboot button on the Teensy.

The code I used:
Code:
void setup()   {                
  Serial.begin(38400);
}

void loop()                     
{
  Serial.println("Hello World");
  delay(1000);
}


Output from the serial monitor when it frooze:
frozen.png


I tried using "cat /dev/ttyACM0", it still freezes after 20-30 lines output. Sometimes it just outputs one line of "Hello world " and closes.
If I kept rebooting, every 5th or 6th time the serial monitor would work, but "cat /dev/ttyACM0" would either freeze or exit.

system and software specs:
host operating system : Ubuntu 18.04
Arduino 1.8.5

Any suggestions to fix this problem would be appreciated.
 

Attachments

  • HelloSerialMonitor.pde
    146 bytes · Views: 65
Oh no, looks like the tty line discipline problem. :(

Which version of Teensyduino are you using? Click Help > About the check.
 
I've installed version 1.42 and the situation is better but not completely solved. It freezes at a reduced frequency, once every three times of reboot
 

Attachments

  • tty_freeze.png
    tty_freeze.png
    22.2 KB · Views: 112
Code:
void setup()   {                
  Serial.begin(38400);
[B]delay(1000); // try as a test?[/B]
}

void loop()                     
{
  Serial.println("Hello World");
  delay(1000);
}

try with a delay in setup before just printing immediately first thing in loop as a test?
 
@tonton81, I have tried your code.
tty_freeze.png

I've spent some time with it and noticed that when I open the serial monitor on the IDE, it does not freeze at all. No matter how many times I reboot the Teensy there is no freeze. Later, I use the cat command(the top section of the image) and it was very smooth.

However, when I tried using the cat command first(as seen from the lower half of the image) before using the serial monitor, it prints four lines of "Hello world" and then freezes. This behavior repeats after every reboot.
 
Thanks, I'm not a linux expert tho, but all these details you can give will help Paul if there indeed is an issue
 
I've spent some time with it and noticed that when I open the serial monitor on the IDE, it does not freeze at all. No matter how many times I reboot the Teensy there is no freeze. Later, I use the cat command(the top section of the image) and it was very smooth.

However, when I tried using the cat command first(as seen from the lower half of the image) before using the serial monitor, it prints four lines of "Hello world" and then freezes. This behavior repeats after every reboot.

Yup, that's the Linux tty line discipline problem. It's one of the many subtle issues I fixed with version 1.42.

The problem is your Linux system is defaulting to using a tty "line discipline", when you really just want "raw mode". When you use "cat" it just opens the port without affecting these sorts of settings. When you use the serial monitor with 1.42, it configures the port to raw mode. Even after closing the serial monitor, the port remains in raw mode unless some other program reconfigures it to again use whatever undesirable line discipline setting was present before.

While the Arduino Serial Monitor is the only officially supported software, hopefully knowing the issue is related to "line discipline" settings will help you to search for solutions if you want to access the port another way. You might also look for "stty". If you find alternate ways, please share here so others who later find this thread might benefit.
 
Yup, that's the Linux tty line discipline problem. It's one of the many subtle issues I fixed with version 1.42.

The problem is your Linux system is defaulting to using a tty "line discipline", when you really just want "raw mode". When you use "cat" it just opens the port without affecting these sorts of settings. When you use the serial monitor with 1.42, it configures the port to raw mode. Even after closing the serial monitor, the port remains in raw mode unless some other program reconfigures it to again use whatever undesirable line discipline setting was present before.

While the Arduino Serial Monitor is the only officially supported software, hopefully knowing the issue is related to "line discipline" settings will help you to search for solutions if you want to access the port another way. You might also look for "stty". If you find alternate ways, please share here so others who later find this thread might benefit.

I looked at the current settings for the tty, adjusted the speed and then set it to raw mode:
tty_freeze.png

running "cat" completely froze it.

There is something else I noticed, When I reduce the delay time using "delay(x)" to 2 ms or removing the function itself, the serial monitor freezes. Sometimes it works well. When the delay time is large(>50 ms) the Serial monitor works perfectly.
 
Are you sure the serial monitor really "freezes"?

When I test here, it scrolls very fast, sometimes not even flickering. But if I try to select a line of text with my mouse, it's very clearly scrolling at high speed.

Please try running this. You should see the number increasing very rapidly! When each line is different, it's much easier to visually see the data is rapidly scrolling.

Code:
unsigned int count=0;

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

void loop()                     
{
  count = count + 1;
  Serial.print("Hello World ");
  Serial.println(count);
  //delay(2);
}

It's also possible the Java-based Arduino IDE may be using too much CPU time (indeed locking up) if you have a slow PC. Try running "top" in a terminal window, or use any of the other Linux process monitoring programs. On my PC, java uses about 20% CPU time when the serial monitor is scrolling at high speed with this program running (the delay line commented out).

Also on my Linux machine, the serial monitor window seems to update much more rapidly if I hover my mouse inside any of the Arduino IDE windows. If I move my mouse outside those windows, it seems Linux (or perhaps something in the X11 subsystem) is reducing the update rate of the serial monitor window. Strangely, the results in "top" don't seem to change much either way.
 
Are you sure the serial monitor really "freezes"?

When I test here, it scrolls very fast, sometimes not even flickering. But if I try to select a line of text with my mouse, it's very clearly scrolling at high speed.

Please try running this. You should see the number increasing very rapidly! When each line is different, it's much easier to visually see the data is rapidly scrolling.

Code:

unsigned int count=0;

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

void loop()
{
count = count + 1;
Serial.print("Hello World ");
Serial.println(count);
//delay(2);
}

It was freezing when the delay was lowered, but this code freezes it a lot
freeze.png

I used "top" to monitor the consumption. When there is a freeze, java's CPU time is between 1-4% . But there were some cases when the serial monitor worked perfectly and java was using around 40-80 %, I think I saw a spike of 150 % (for a very brief moment) although this never effected the serial monitor. It seems even if java was consuming a lot of CPU time, it doesn't seem to effect the serial monitor. What do you think?.

Did you try rebooting the Teensy and opening the Serial monitor?


Also on my Linux machine, the serial monitor window seems to update much more rapidly if I hover my mouse inside any of the Arduino IDE windows. If I move my mouse outside those windows, it seems Linux (or perhaps something in the X11 subsystem) is reducing the update rate of the serial monitor window. Strangely, the results in "top" don't seem to change much either way.

I had the same experience when the Serial monitor was working.
 
Status
Not open for further replies.
Back
Top