My Teensy LC keeps hanging, then disappearing...

Status
Not open for further replies.

mogplus8

Member
Hi All,
I am building a project around a Teensy LC. It reads lots of analog inputs (pots) then outputs a PPM stream. I am using VS Code with PlatformIO plugin, running under Linux Mint 19.3.

In my testing I have put lots of Serial.print statements in the code to see what the analog values being read are and what's being generated in the output stream, which are in the infinite loop part of the program. However I have found that quite often, but not all the time, the program will start when I load it, and then output 5 to 10 lines of output, sometimes more, sometimes less, and then just stop. I have tried hitting the reset button on the Teensy (which closes the monitor screen) which restarts the Teensy but it usually does the same thing. Sometimes it runs as expected, and continuously outputs to the monitor (so I can move the pots and see the numbers changing), sometimes it does it several times in a row, sometimes it just works without having to hit the reset button, but sometimes it just flatly refuses to display more than a few lines of output no matter how many times I reset it. So I go and have a cup of tea and come back and try again, and sometimes it works.

Sometimes, after I've hit reset several times (and restarted the monitor), I see a message asking me to enter the device address, as if /dev/ttyACM0 can't be found. If I check with "ls /dev/ttyACM*" sure enough it's not there. I have to physically unplug the Teensy and plug it in again, and it magically reappears.

It does exactly the same thing with the Arduino IDE too, although it seems to be a bit less cantankerous. I usually only have to reset it once to get it going.

Have I just got a dud Teensy, with some weird intermittent fault? Is there anything else I can try to get it to work properly?

All advice gratefully received.

:-\
 
Sometimes hard to know what is going on, when we can not see the code... Or output.... Also I am not much of a Linux expert, but maybe whatever you are using to see the Serial input is getting overrun and crashing...

Some guesses that might help:
a) I assume you already did it, as you say it works... But make sure you have the latest udev rules from the Teensy website.

b) Maybe your code is outputting lots of data before the Serial code is ready for it at the start of setup.
Try adding something like: while (!Serial && (millis() < 5000)) ;
This will have your sketch wait for up to 5 seconds for the USB Serial port on your linux box to be ready before it starts to output stuff... If this is not near the start of your code execution, you may want to compensate for how for the start time of the wait, something like:
Code:
elapsedMillis em=0;  (!Serial && (em < 5000)) ;

c) if you are outputting lots of stuff quickly, see if you can reduce the output. I will often to do things like add a delay() or only output if something changed, Or with analog changed more than X...
 
@KurtE you got it in one! I put in the delay and it now works fine.

Thank you, I thought I was going to have to buy a new Teensy!

;-)
 
Status
Not open for further replies.
Back
Top