Go Down

Topic: Arduino 15 & sprintf memory footprint increase? (Read 706 times) previous topic - next topic

uh

did something change in Arduino 15 that would alter the memory footprint of sprintf or other functions?

i have some demo pachube code for the ethernet shield (http://community.pachube.com/?q=node/112) which works fine up till Arduino 14, but on Arduino 15 i start getting errors that i presume are caused by running out of RAM.

working with an Arduino Diecimila on Arduino 15 i observed the following:

- if i include the following line
Code: [Select]
sprintf(pachube_data,"%d,%d,%d,%d,%d,%d",analogRead(0),analogRead(1),analogRead(2),analogRead(3),analogRead(4),analogRead(5));
then the board will constantly freeze/reset, etc.
- if i replace pachube_data with something static no problem.
- if i try to do a hack using itoa same problems as sprintf
- if i use the original code, incl. sprintf, in Arduino 14 i have no problems.

however, the following code does work fine, so sprintf is definitely OK in A15:

Code: [Select]

#include <stdio.h> // for function sprintf

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

void loop(){
 char pachube_data[128];
 sprintf(pachube_data,"%d,%d,%d,%d,%d,%d",analogRead(0),analogRead(1),analogRead(2),analogRead(3),analogRead(4),analogRead(5));  
 Serial.println(pachube_data);
}


of course it might be some other function in my code that has expanded, but since sprintf is usually so hungry i'm presuming it's the culprit.

incidentally, i have not been able to get the Mega to work with the basic Ethernet shield examples, and so have not yet been able to see how it works with larger RAM.

gabebear

#1
Jul 05, 2009, 04:42 pm Last Edit: Jul 05, 2009, 04:47 pm by gabebear Reason: 1
If you aren't sending long strings to the arduino, you could shrink the size of the incoming USART buffer to save some RAM. Change RX_BUFFER_SIZE in HardwareSerial to some low power of 2. It defaults to 128.

You might just want to send all the data separately, it will save some RAM and probably be faster.
Code: [Select]

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

void loop(){
           Serial.print(analogRead(0), DEC);
           Serial.print(",");
           Serial.print(analogRead(1), DEC);
           Serial.print(",");
           Serial.print(analogRead(2), DEC);
           Serial.print(",");
           Serial.print(analogRead(3), DEC);
           Serial.print(",");
           Serial.print(analogRead(4), DEC);
           Serial.print(",");
           Serial.println(analogRead(5), DEC);
}


Go Up