Go Down

Topic: Bug with Serial.print in the new arduino 1.0 (Read 1 time) previous topic - next topic

Stigan

The code below does not work the same on the new arduino 1.0 as with the old software. It should continously print longer and longer strings of ones (1111....)

BUT when adding four digits every time it just prints the following:
<
111111
2111111111
31111111111111
411111111111111111
5 1111111111111111111
>
It does however work when adding both three and five ones every time (111)(11111).
I have no explanation but it does represent a huge problem to the code i need to write.
For now I will just go back using the old software, but I guess this can be fixed for v1.1
Wasn't sure who to let know, but now somebody knows at least :)

int cnt=0;
String longstring="1";
void setup() {
Serial.begin(9600);}

void loop() {
  cnt=cnt+1;
  String add="1111";
  Serial.print(String(cnt));
  longstring=longstring+add;
  Serial.println(longstring); 
}

johnwasser

Are you saying that if you add 4 characters at a time it stops at 5 iterations and that if you add 3 or 5 it goes on forever?
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

robtillaart


bug confirmed

code works under 0.22  (up to cnt = 98 and then the longstring resets and continues )
and code stops under 1.0  after cnt = 5

Code: [Select]

int cnt=0;
String longstring="1";

void setup()
{
  Serial.begin(115200);  // to speed up the test a bit
}

void loop()
{
  cnt=cnt+1;
  String add="1111";
  Serial.print(String(cnt));
  longstring=longstring+add;
  Serial.println(longstring);
}



IDE 1.0: 3 & 5 sketch does run until 99 and then locks..
Code: [Select]

int cnt=0;
String longstring="1";

void setup()
{
  Serial.begin(115200);
}

void loop()
{
  cnt=cnt+1;
  String add3="111";
  String add5="11111";
  Serial.print(String(cnt));
  if (cnt %2 ==0) longstring=longstring+add3;
  else longstring=longstring+add5;
  Serial.println(longstring);
}


Should report the bug - http://code.google.com/p/arduino/issues/list -

advice : don't use strings...

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Paul Stoffregen

Do you have access to a Teensy board?  Teensyduino has the original String implementation I tried to contribute to Arduino.

I just ran this and it seems to work fine.  It continues printing forever **, but the string stops getting longer after 162 because available memory has run out.


** ok, forever is still running after a few minutes... but Teensy sends at full USB speed, not 9600 baud.  After only the time I've written this message, it's hit 16 bit numerical overflow and is now printing negative numbers on the beginning of each line!  Oh, now it's rolled back over to positive...

Go Up