I’m trying to get the internal temperature of a XIAO_ESP32C6 but I don’t seem to get sensible values from the temperatureRead()
function. The sketch is below.
void setup() {
Serial.begin(115200);
delay(1000); //Take some time to open up the Serial Monitor
}
void loop() {
float temperature = temperatureRead();
Serial.printf("Temp onBoard = %.2f °C\n", temperature);
delay(60000);
}
Mostly it returns a value of 15 or 16, which for a room with an ambient temperature of around 22°C doesn’t make sense. Not to me at least.
So I did a calibration test. First I changed the sketch to take a reading every 5 minutes and then go in to deep sleep to minimise the self-heating of the chip.
#define uS_TO_S_FACTOR 1000000 // Conversion factor for micro seconds to seconds
unsigned long sleepyTime = 300; // Sleep time in seconds
void setup() {
// Configure the serial port
Serial.begin(115200);
delay(1000);
// Read the temperature
float temperature = temperatureRead();
Serial.printf("Temp onBoard = %.2f °C\n", temperature);
// Configure the wake up source and time.
esp_sleep_enable_timer_wakeup(sleepyTime * uS_TO_S_FACTOR);
// Enter hibernation
Serial.println("Going to sleep now\n");
delay(1000);
Serial.flush();
esp_deep_sleep_start();
}
void loop() {}
Results below. Reading is the value returned by temperatureRead()
, Actual is what I measured in the freezer, the fridge and at ambient. The Sensor Output is pretty far from the truth, but it has the signs right.
Actual Reading
-23.2 -36
4.1 -9
21.8 7
To check if the numbers make any sense at all, I plotted one against the other and get a fairly straight line, which hints at a scaling and offset issue.
Finally, I played about with the results and found that by multiplying the readings by 1.0465 and adding 14.474 the two extremes can be aligned and the ambient reading is believable.
So with careful calibration, a result would seem feasible, but I shouldn’t have to go through that much hassle.
Does anyone have any ideas as to what I might be doing wrong?
I’m using Arduino IDE version 2.3.4 and all the libraries appear to be up-to-date.