Arduino (0022) problems coming from String and Serial libraries
When you start working with Arduino, you can find all the official libraries available at Arduino home page, the String and Serial are some of them.
In my last project (see my past posts Like Box or Boards are ready), I was using Arduino alpha version 0022. At the beginning everything was ok but when I started doing more complex stuff such as: concatenating strings, reusing string objects, assigning one string to another and overall leaving my app working for few hours…then serious memory leaks and corruption problems were happening. Programming with Arduino processing is particularly sensible to memory problems mainly because the loop() function is continuously running, so string objects are continuously being reused, resized, etc..
In order to have a more precise control of memory usage in my Arduino application I decided to use classic C language dynamic char arrays. For a programmer with extensive background in C language this was the shortest solution. Searching on google I realized I was not the only one having this problem so hopefully next Arduino releases fix this bug.
Another problem that I experienced while running my Arduino application is that the execution stopped at some point for no reason. After a while I realized that doing many Serial.println(..) was causing it, so I removed some and everything was working again. I suppose having a lot of debugging information going through the serial port could be interfering with the rest of operations.
Tips when using Arduino Libraries:
- Better do not use the String Library, implement dynamic char arrays instead.
- Limited Use of Serial.println(..).
And one last tip for debugging your Arduino Application: measure how much memory is free with the following code Free Memory!.