Jump to content
43oh

Recommended Posts

  • 2 weeks later...

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.

Link to post
Share on other sites

[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

Link to post
Share on other sites

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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...