Go Down

Topic: Too much serial output crashes Yún? (Read 565 times) previous topic - next topic


Aug 11, 2015, 09:42 am Last Edit: Aug 11, 2015, 10:15 am by vanhavirta
Without all my serial output commented out, my sketch has stopped crashing. Let me elaborate on that a bit more...

For a couple of months now I've been working on figuring out why the AtMega side of my Yún stops working after a day or less, i.e. my sketch ceases to run while I can (often) still connect to the Yún's Linux side. I'm running the latest Open-WRT firmware.

It's a simple script that uses the AdaFruit TCS34725 color sensor to report its output in the void loop() via the serial monitor using Console.println. The strange thing is, that I'm finding a strong correlation with my Serial.println and Console.println commands inside the loop.

The sketch started out quite heavy on the amount of serial output it did, i.e. about fifty lines per five seconds or so. Essentially, I would output the HEX color code that the sensor reported. It was a lot of lines, and that way the sketch ran overnight, but I would always find it frozen the next day. I'd estimate that 12h was the maximum. I was troubleshooting my WIFI connection, and even tried a script that reconnects in case the connection is lost. I thought there might be a connection timeout of sorts, but that didn't seem to be the case.

At times I could see slowing down of the serial output printing, but I couldn't tell if it was due to me working on my laptop or the Yún slowing down. Restarting the sketch, however, made the board pick up speed again.

I then reduced the amount of lines printed to a single line per about 3 seconds or so using the Console.println command (I'm reading the output via WIFI). I could reliably run the sketch for about a day and nine hours. After that the Yún would fall silent and require a complete restart (plug it off the wall). The behaviour seems to be consistent and reproduceable.

Today, however is the third day of continuous, successful running of my script, and it seems it will just keep on going. The reason seems to be that I commented out all serial output. Otherwise the code has remained unchanged.

To my ultimate question: Does all the Serial.print and Console.print output get stored somewhere, eventually filling up the memory and causing the Arduino to crash? Do I have a limited amount of lines at my disposal, one line taking up about 6 to 8 characters of data? And ultimately: is this how it should work?


EDIT: If this is not supposed to be the way Console.print and Serial.print work, I can paste in some of my code or perhaps try to upload a sketch that just prints something in the serial monitor to see how long it'll run. As of now I'm too happy to see the sketch running and would love to let it run as long as it can.


Post your code. Without that we are flying blind.

One guess is that you are running out of SRAM.

Two or three hours spent thinking and reading documentation solves most programming problems.


One guess is that you are running out of SRAM.

Yun, ATmega32u4 SRAM:2.5 KB
Yun Shield +Mega, ATmega2560 SRAM:8 KB


Thanks guys for the offer, I'm now away from my laptop, but will look into it if necessary. In the meanwhile, I did some reading about SRAM and printing strings in the serial monitor, and it indeed seems that all my HEX strings are accumulating in the SRAM which in turn flows over:


Thanks for the educated guesses, they steered me towards a probable answer! Cheers ...!

Go Up