Simple Teensy loop hangs - why?

Status
Not open for further replies.

garymq

Member
Hello
I have been using Arduino for some time, but recently started using it on Teensy 3.6.
Arduino 1.8.15
Teensyduino 1.54

All was going well but found that simple loops will just stop after about an hour.
Example:
(Note, my program was a lot more complicated than this, but when I found that it stopped, I kept commenting out different sections to see where the problem line was... until I got down to this very simple code, which still stopped!)

Code:
int readPin = A2; // ADC0
int i1 = 0;

void setup() {
    Serial.begin(9600);
    delay(500);
}

int value1 = 0;

void loop() {   
    Serial.println(i1);
    delay(100);
    i1 = i1+1;
}

This will run normally, printing out the value of i1 on the Serial Monitor as expected.
But then after 165660 loops, it just stops.

Starts again normally after compile/upload, but then just stops again.
Have repeated this many times.

Any ideas?

Thanks
Gary
 
165660 loops at 100ms eash should be about 4.6 hours, right?

I started it running here on a Teensy 3.6. Set it up on a Macbook Air, so I can put it on a table away from my normal workbench. Will check back late tonight (technically early tomorrow morning).
 
Just for fun on a T_3.6 here started the sketch with the loop() " delay(100); " changed to " delay(1); "

It passed the 165660 loops in 165 seconds ?

Now running past 750000 and on no problem.

So not a simple iteration count problem.
 
Very wild guess: PC is trying to go into some sleep mode and trying to power off USB devices?
 
Very wild guess: PC is trying to go into some sleep mode and trying to power off USB devices?

Something odd - likely the PC or USB port or the data coming in

Still running here just passed this:
Code:
5004965
5004966
5004967
5004968
5004969
 
Thanks for suggestions.

Seems like it runs continuously on others' computers. So must be something on my computer.

I changed delay(100) to delay(1), as per defragster. (dumb of me to leave the delay(100) in there).
Still stops, see below, but much quicker now of course:
Code:
.....
.....
165658
165659
165660
165661
165662
165663
165664
1656

Have done this several times - always finishes like this.

luni - I don't think it's anything to do with the PC shutting the USB/serial port.

more info: I previously did another Teensy 3.6 program using the same environment, testing the RTC, reading out the time/date every second and writing it to an LCD.
This worked fine for a couple days continuous running.

Gary
 
I could not reproduce the problem. It didn't stop at 165660.

sc.jpg

I programmed a Teensy 3.6 using the exact code from msg #1, using Teensyduino 1.54-beta10 on a Linux x86-64 machine. Then I plugged it into a Macbook Air (with Teensyduino 1.53) and opened the serial monitor. The Mac didn't upload any code, just open the port and ran for about 5 hours. Even as I write this, it's still printing.
 
Have done this several times - always finishes like this.

When you click the Tools > Ports menu, you should see Teensy listed twice. One is under "Teensy Ports" and the other under "Serial ports". One way uses the Java JSSC library, the other runs a helper program (written in C) which uses native APIs.

Do they both have the same problem?

Also, can you try changing Tools > USB Type to RawHID and upload again. Then you should see different port info, since it's no longer serial. Does it also have the same problem when running in non-serial mode?
 
When you click the Tools > Ports menu, you should see Teensy listed twice. One is under "Teensy Ports" and the other under "Serial ports". One way uses the Java JSSC library, the other runs a helper program (written in C) which uses native APIs.

Do they both have the same problem?

I had been running "Teensy Ports", changed over to "Serial Ports", and the problem seems to go away - it now runs continuously..

Serial Ports.jpg

Thanks!
 
What happens if you use Teensy Ports, but after you've uploaded with USB Type as RawHID (so it's using HID protocol rather than serial)?
 
What happens if you use Teensy Ports, but after you've uploaded with USB Type as RawHID (so it's using HID protocol rather than serial)?

If I set Ports to Teensy Ports, and USB type to Raw HID, it again hangs again at 165664 loops. See below:
Port = Teensy Port   USB Type = Raw HID.jpg

Also, an odd thing, when USB type is set to Raw HID, instead of Port options "Teensy Ports" and "Serial Ports", the Port options change, see above.

When change back to Port = Serial Ports and USB type = Serial, everything works again and the loop runs continuously (ie doesn't hang).
 
Just checked on T_3.6 here - still running at 11.269591388888888888888888888889 hours:
Code:
40570529
That is modified code running 100X faster on prints re p#4.

<EDIT> : over 16 hours @ 58045286 and running away ... at 1/millisecond
 
Last edited:
After changing the port settings, the loop in the original code is now currently looping up to 4million+ and still going, as expected.

Summary:
1. If I set Ports to "Serial ports -> Teensy ports", it hangs at around 165K loops. Setting USB type to "Raw HID" doesn't help.
2. After setting Port to "Serial ports -> COM16 (Teensy)" and USB type to "Serial", it works correctly and loops indefinitely.
So I'll use those settings going forward.
 
Status
Not open for further replies.
Back
Top