Problem using String

Hi there. I googled for a problem concering my little arduino projects.
It would be to complicated to upload my whole program so I take a codepart which I've found in this forum(http://arduino.cc/forum/index.php/topic,95914.30.html) and is pretty much alike my problem:

#include <MemoryFree.h>
void setup() {
  Serial.begin(9600);
}
void loop() {
  int n = 0;
  while(n <=100) {
    int u = 20*n;
    int v = 30*n;
    String str = String(n) + ", " + String(u) + ", " + String(v) + ", " + String(freeMemory());
    Serial.println(str);
    delay(500);
    n++;
  }
  Serial.println("Done");  
}

As far as I understand, its a problem of arduinos memory that's used to store the variables.
I also followed this posts http://arduino.cc/forum/index.php/topic,95914.0.html and I think its dealing with the problem(isnt it?).
To be honest, im not a native english speaker and ive got a difficult time following these solutions.
My question is:
1.Is there a library to download to replace the broken one?
2. If not, is there a workaround(proofed? dont want to destroy my board, saved my pocketmoney for a long time <.<)
3. If nothing helps I have to surrender and stop using String?

Im sorry for creating this new topic but i really didn't get what to do in the mentioned topics above.

J.A.

1.Is there a library to download to replace the broken one?

No. The library isn't broken. The underlying mechanism for dealing with dynamically allocated memory (free()) is.

  1. If not, is there a workaround

There is a patch that can be applied to fix the free() function.

  1. If nothing helps I have to surrender and stop using String?

That would be the best thing to do, given how little memory the Arduino has.

Wow. its awesome to see how fast you answer.
If I use the patch, do I have to implement it then on every single file in which I use String or do I use the "working String" automatically?

If I use the patch, do I have to implement it then on every single file in which I use String or do I use the "working String" automatically?

The patch fixes the free() function that is called by the String destructor. No changes to the String class are needed (Well, they are, but it is not up to you to make them) nor are changes needed to any sketches that use the String class.

Ok. When I'm at home I'll try the patch.(is it a community-made one or a official? Don't want to lose my warranty)
Btw, is here any thank-you-function?

is it a community-made one or a official?

Community made.

Don't want to lose my warranty

You are patching software on the PC, not something on the Arduino hardware.

Btw, is here any thank-you-function?

No, you actually have to type stuff.

Well, so I have to thank u manually :wink:
You gave me hope back! Ty sir.
I'll take this one, its the only one I found :slight_smile:
pjrc.com/teensy/arduino_contrib.html

You could do it "The Arduino Way". :slight_smile:

#include <MemoryFree.h>
void setup() {
  Serial.begin(9600);
}
void loop() {
  for (int n = 0; n <=100; n++) {
    int u = 20*n;
    int v = 30*n;
    Serial.print(n, DEC);
    Serial.print(", ");
    Serial.print(u, DEC);
    Serial.print(", ");
    Serial.print(v, DEC);
    Serial.print(", ");
    Serial.println(freeMemory(), DEC);

    delay(500);
  }
  Serial.println("Done");  
}

well..the string which is shown is the same as in the code above.
but I'm working with serialevent-methods..that wont work..every print will call it another time..i hoped to find a solution to fix the String/free()/what-ever bug.
I haven't found the proper patch yet but if there's one, I'll find it at all cost :slight_smile:
TY though!

but I'm working with serialevent-methods..that wont work..every print will call it another time.

I'm thinking that you don't understand how the serialEvent() method gets called, or serial data processing, then.

Using one Serial.print() or a dozen Serial.print() statements makes no difference to how the data is eventually shifted out the serial port, or how it is received on the other end.

I'm using Java. Every time I print()/println() the event is called in java(I'm using the rxtx library of java and the method is called serialEvent(SerialPortEvent oEvent))
But you are right. I'm a newbie trying to get these things to know by watching examples and trying to find out what everything does. There are easier ways to do that, sure..

unzufrieden:
I haven't found the proper patch yet but if there's one, I'll find it at all cost :slight_smile:
TY though!

I think it may be a "virtual" (vapor?) patch, as in a recent similar String discussion mentioning it, it never appeared.

But...watch post #2..he/she said there's a patch. I don't think that he has thought that out..

Ok. i found the Files. All who have the same problems like me when using Strings:
Follow these instructions:
http://code.google.com/p/arduino/issues/detail?id=857

and download the malloc.c file here:

http://code.google.com/p/arduino/issues/detail?id=468

You have to put them here: arduino-1.0.1/hardware/arduino/cores/arduino

A special Thanks to these guys who have written the code as far as I understand;

Joerg Wunsch
Gerben van den Broeke
Paul Stoffregen