spirilis 1,265 Posted January 22, 2014 Share Posted January 22, 2014 Good work! I usually like to allocate at least 16 bytes for any sprintf type of stuff like that. (even on MSP430) Quote Link to post Share on other sites
jcR 6 Posted February 2, 2014 Share Posted February 2, 2014 Hello all Mikal Hart has developed two libraries for arduino that are easily portable to the platform Stellaris / Tiva.They are called PString and Streaming, and are available on its website: http://arduiniana.org/libraries/pstring/PString solves with a very smart way the floating point conversion to characters string, following this example: #include "PString.h"#include "Streaming.h" char buffer[10]; double pi=3.141592; void setup(){ PString str(buffer, sizeof(buffer));// create the string str in buffer Serial.begin(115200); Serial << "PI in a string: "; // Print PI to a string with 6 decimals // sprintf(buffer, "%.6f", pi); // Print the string to the serial terminal //Serial.println(buffer); str.begin();// reset str str.println (pi,6);// store pi to str with 6 decimals Serial << str << endl; // print à la C++} The advantage is that the memory consumption is lower by more than 20 kbytes over the sprintf function and in addition there is no risk of having a memory overflow with dynamic strings I use these two libraries in all my programs without any problem Cordially. Quote Link to post Share on other sites
Rickta59 589 Posted February 2, 2014 Share Posted February 2, 2014 [edit] ... heh .. never mind .. I had the wrong board selected [/edit] The advantage is that the memory consumption is lower by more than 20 kbytes over the sprintf function and in addition there is no risk of having a memory overflow with dynamic strings I've not seen a 20kbyte overhead associated with Energia's sprintf and floating point. Can you explain how you see that? -rick Quote Link to post Share on other sites
jcR 6 Posted February 2, 2014 Share Posted February 2, 2014 As exemple you can compile the simple WebServer.ino exemple for the CC3000 Wifi module (exemple in Energia IDE). The binary sketch size is 42828 bytes . If you remove the printHex(num,precision) wich use the sprintf routine, you have the Binary sketch wich down to 22656 bytes. this is exactly what I describe in the above example. Do you have read the exemples on the Mikal Hart web site for the PString usage. I think this is the most elegant of solutions, with the advantage of not using sprintf. Cordially JC Compiled with Energia 0101E0011 on W7 OS. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.