DAVE 4.5.0 snprintf issue

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
12d6k
Level 1
Level 1
5 sign-ins First reply posted First question asked

Hello, I try to display the temperature (int16_t and float) on my OLED.

 

with int:

 

 

char buff[64];    

rawTemp = ((int32_t)daten[0] << 12) | ((int32_t)daten[1] << 4);
int_16t temp_i = temp_int(rawTemp);
float temp_f = temp_float(rawTemp);

ssd1306_Fill(Black);
snprintf(buff, sizeof(buff), "%02d", temp_i);
ssd1306_SetCursor(30, 26);
ssd1306_WriteString(buff, Font_16x26, White);

ssd1306_UpdateScreen();

 

 

 

and with float:

 

 

char buff[64];

rawTemp = ((int32_t)daten[0] << 12) | ((int32_t)daten[1] << 4);
int_16t temp_i = temp_int(rawTemp);
float temp_f = temp_float(rawTemp);

ssd1306_Fill(Black);
snprintf(buff, sizeof(buff), "%f", temp_f);
ssd1306_SetCursor(30, 26);
ssd1306_WriteString(buff, Font_16x26, White);

ssd1306_UpdateScreen();

 

 

 

I can see the digits on my OLED when I use the int variant. When I use the float variant I can't see. I checked the buff in debug and the buff is empty. Why is it empty? What am I doing wrong?

 

0 Likes
1 Solution
sujatapatil
Moderator
Moderator
Moderator
50 solutions authored 10 likes received 100 sign-ins

Hi , 

snprintf(buff, sizeof(buff), "%f", temp_f);

 replace with 

sprintf(buff, "%f", temp_f)

And also double the size of buffer as float number will be stored different (IEEE standard)

than integer or character. Your buffer size is not enough to store it . try with 1 /2 bit precision and adjust buffer .  

 

View solution in original post

0 Likes
5 Replies
sujatapatil
Moderator
Moderator
Moderator
50 solutions authored 10 likes received 100 sign-ins

Hi ,

Please use sprintf instead snprintf . 

Thanks

Sujata

0 Likes
sujatapatil
Moderator
Moderator
Moderator
50 solutions authored 10 likes received 100 sign-ins

Hi ,

I hope you received my last response. Hope it worked for you.

Thanks

Sujata

0 Likes
12d6k
Level 1
Level 1
5 sign-ins First reply posted First question asked

Hi, sorry for my late reply.

Same result with sprintf 😪

0 Likes
sujatapatil
Moderator
Moderator
Moderator
50 solutions authored 10 likes received 100 sign-ins

Hi , 

snprintf(buff, sizeof(buff), "%f", temp_f);

 replace with 

sprintf(buff, "%f", temp_f)

And also double the size of buffer as float number will be stored different (IEEE standard)

than integer or character. Your buffer size is not enough to store it . try with 1 /2 bit precision and adjust buffer .  

 

0 Likes
sujatapatil
Moderator
Moderator
Moderator
50 solutions authored 10 likes received 100 sign-ins

Hi 

Hi ,

I have not heard from you since my response . I assume that this is because the issue is resolved and you are busy with other important work.

If, however, the issue is not resolved, please do let me know and I shall work with you to ensure that the issue is resolved.

I will wait for another two days to hear from you. If I do not hear from you, I shall go ahead and close this case.

You can always reopen this case or create a new case for any other issue. We will be happy to help you in resolving your issues.

 

Thanks

Sujata

0 Likes