This is one of those moments where I have just been looking at the same piece of code too long and can't see the error which must be right in front of me. I even slept on it and came back to it this morning...
Here's my code snippet:
// Read temperature & humidity
fTemp = dht.readTemperature();
fHum = dht.readHumidity();
Serial.print(F(" - H: "));
// Format output
sprintf(cInfo, "%02u/%02u/%4u,%02u:%02u:%02u,%.2f,%.2f", day(), month(), year(), hour(), minute(), second(), fTemp, fHum);
// Output info to file
Normally this code should be used to print out the current date, time, temperature and humidity as a comma-separated list to a file. But when I looked at the file the temperature and humidity values were question marks. That's when I started adding the debug serial outputs to see. The problem happens just after the sprintf call.
The result of the above code looks like this:
T: 18.90 - H: 34.70
The first line confirms, to me, that the temperature and humidity values are being read properly and stored in their float variables.
The second line shows me what was just written to the file.
The problem appears to be in the sprintf conversion. I have tried using "%f", "%2.2f", "%2f" and "%d". That last one was a desperate measure and produced spurious numbers.
I'm sure this is something simple I'm missing... but I just can't see it.
Thank you in advance for any suggestions or directions you may point me in.