Go Down

Topic: sprintf on Mega 2560 not working (Read 439 times) previous topic - next topic

gamerpaddy

Apr 09, 2013, 07:20 am Last Edit: Apr 09, 2013, 07:22 am by gamerpaddy Reason: 1
Hello, when i use sprintf and Serial stuff at once, everything getting screwed
When i run this code:
Code: [Select]
void setup()
{
 Serial.begin(115200);
}

char* s;

void loop()
{
 
 sprintf(s,"TEST millis %f and Micros %f so 0 is %d",millis(),micros(),0);
 Serial.println(s);
 s = "";

 delay(1000);
}


This output happens (Spam, very fast..  the 1000milliseconds delay will be ignored):



Serial stuff is working without sprintf


Informations:
im using Arduini 1.0.4 IDE
i tested this code on Arduino UNO R2 and on my both  MEGA 2560


A year ago, it worked well (i think it was arduino 1.0 IDE), since 1.0.1 its screwed


And before you think the %f in sprintf causing this problem, i tried to floor/round the millis() and micros() command to use it with %d and/or %i .. no luck


Does anyone have a fix for this?  maybe a working stdio.h?
_____________
||||##########|
||||[] Arduino|
 |[];  Uno____|
|||____|ATmega|
 |__##### ####|

Coding Badly

Code: [Select]
void setup()
{
 Serial.begin(115200);
}

char s[60];  // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

void loop()
{
 
 sprintf(s,"TEST millis %ul and Micros %ul so 0 is %d",millis(),micros(),0);  // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 Serial.println(s);

 delay(1000);
}



You failed to provide an actual buffer.  %f has never worked.  %f never will work when you pass an unsigned long.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy