Pages: [1]   Go Down
Author Topic: Bug with Serial.print in the new arduino 1.0  (Read 920 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley

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); 
}
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8103
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12483
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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:
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:
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...

Logged

Rob Tillaart

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

0
Offline Offline
God Member
*****
Karma: 24
Posts: 587
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

Pages: [1]   Go Up
Jump to: