Why does Arduino auto-restart?

I'm debugging my app with several Serial.print().
I've noticed Arduino periodically restarts when running on (it seems) random points of execution...

Does it restart on errors/exceptions? Is it a correct supposition?

No, the Arduino doesn't restart on errors. It may be a serial issue with the auto-reset, usually to do with communications software toggling the DTR liine, or it could be a power or electrical noise problem.

thank you, but it resets in a loop at the same execution point.
other sketches are running correctly...

what could it be?

uhm... i used the available memory function

int availableMemory()
{
int size = 8192;
byte *buf;
while ((buf = (byte *) malloc(--size)) == NULL);
free(buf);
return size;
}

and i get 30 :stuck_out_tongue: is it a RAM issue?

i'm going crazy...
i run the availableMemory() function in an ad-hoc sketch and i get

free memory = 1785 - memory used = 6407
:-?

6407 used??? i have the ATmega328p!

Well, starting from 8192...

marioquark:

Check out this thread for some ideas: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1262180529

Don

so, you think is my pc who resets arduino...
mmm could i use arduino on battery (so disconnected from USB) + manual reset, instead of cutting the hardware trace?

another question: why it doesn't happen with other sketches?

thank you for the answer!

I think it's the serial.print that you are using for debugging (mentioned in your original post) that is resetting your Arduino.

If you disconnect your Arduino from your usb (mentioned in reply #7) you won't be able to do the debugging.

another question: why it doesn't happen with other sketches?

Do they use serial.print?

Don

yes, the do.

ok so i could try to comment as Serial.print as possible and see what happens...

thank you.

yes, now it works... very weird Serial.print() make this happen...
anyway thank you! :wink:

yes, now it works...

You're welcome! Thanks for letting us know that it worked - it will help us help others in the future.

Don

If you're arduino resets or auto-restarts all by itself, it is caused by a program crash, usually because a memory buffer or array is being written beyond the size of the array or buffer size.

JoeJ:

If you're (sic) arduino resets or auto-restarts all by itself, it is caused by a program crash, usually because a memory buffer or array is being written beyond the size of the array or buffer size.

Are you saying that Serial.print() was not the cause of his problem or are you pointing out what may be wrong within Serial.print()?

Don

Your ram stack was being overflowed, if you remove the serial.prints, all the messages that are to be printed through serial.print occupies space in ram, so if you remove then your ram as more free space.

1 Like

so it happened because too serial.prints went out of buffer, is it? less prints would have been ok.