0

I need to collect a message like: "Temperature: 15.8" to send to UART. For this, I want to use sprintf. I know that this is not supported, but people solved a similar problem by converting the float to another type. I tried several options and as a result, instead of a float, I get "?". Testing at Tinkerkad.

My code:

char msg_buffer[60];
float temperature = 10.5;

void setup()
{
 Serial.begin(9600);
 //snprintf(msg_buffer, sizeof(msg_buffer), "%f", 3.333333);
 //dtostrf(temperature, 4, 3, charVal);
 sprintf(msg_buffer, "Temperature: %.0f", temperature);
 Serial.println(msg_buffer);
 pinMode(13, OUTPUT);
}

void loop() {}

marked as duplicate by Maximilian Gerhardt, Juraj, VE7JRO Aug 27 at 13:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Browse other questions tagged or ask your own question.