Closed Mangulomx closed 4 years ago
Someone say me something. What can I modify? Regards
@mangulomx You are over writing your temp display buffer.
"=%0.2f" creates "=-127.00"+NULL. Eight characters plus null is NINE.
Use svnprintf()
@stickbreaker could you put me an example?. I am very novice
void readTemps()
{
tempC = sensors.getTempC(tempSensor);
if((tempC > 85.0)||(tempC < -40.0)) { // invalid temperature reading
Serial.printf("invalid temp reading %0.2fC\n",tempC);
tempC = -127.0;
return;
}
Serial.printf("Read Temps = %0.2fC\n", tempC);
#define BUFFMAX 8 // this will fail if tempC is out of range, but it will not crash program,
// just print error messages. if overflow error message prints, just increase this value.
char buf[BUFFMAX];
int len = snprintf(buf, BUFFMAX,"=%0.2f", tempC); //len will be length of resultant string.
// if len <0 then error, if >= BUFFMAX then would have overflowed storage location (buf)
if( len<0) { // invalid conversion
snprintf(buf,BUFFMAX,"ERR CONV");
Serial.printf("Conversion Error\n");
}
else if ( len>=BUFFMAX) { // conversion exceeded buffer length
snprintf(buf,BUFFMAX,"ERR OF");
Serial.printf("temp Won't fit in buffer[%d] =%0.2f\n",BUFFMAX,tempC);
}
u8x8.drawString(0, 0, buf);
}
Chuck.
Very thanks by your effort. help me very much!
Hardware:
Board: TTGO-LORA32-V2.0 Core Installation version:
IDE name: Arduino IDE Flash Frequency: 80 MHZ PSRAM enabled: no Upload Speed: 15200 Computer OS: Mac OSX
Description:
My board rebooting code output error stack smashing. I am trying mesasure temperature with sensor DS18b20.
Sketch: (leave the backquotes for code formatting)
Debug Messages: