temperatureRead() Returns nonsense

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.

Hi there,

and Welcome Here…

This may indeed be the problem or issue. Try rolling the BSP to the Alpha 3.0.1 and try it again. They may have been depreciated in move to core 3.0 or the IDF-5.3 ???
HTH
GL :slight_smile: PJ :v:

HI there,

A few Moments later (in that voice)… :smile: :ok_hand:

I asked Santa , he say’s this:
:+1:
Below is an overview of the internal temperature sensor situation on the Xiao ESP32C6 (and ESP32 variants in general), along with options for reading it in Arduino or the ESP-IDF. The short version is:

  1. Yes, the ESP32C6 has an internal temperature sensor.
  2. However, support in Arduino (especially for the C6) may be limited or not yet fully integrated.
  3. The most reliable approach to reading it is through the ESP-IDF APIs (if they exist/are enabled for the C6) or by using an external temperature sensor for better accuracy.

Below are the details.

1. Does the Xiao ESP32C6 Have an Internal Temperature Sensor?

  • Espressif’s ESP32 family chips generally have a built-in temperature sensor. For the newer ESP32-C6 variant, the hardware does include an internal temperature sensor.
  • Accuracy & Range: Typically, these internal sensors are rough at best—they can be off by a few degrees Celsius. They’re mainly intended for internal thermal management or quick readings, not for high-precision measurements.

2. Reading the Internal Temperature Sensor in Arduino

(a) Current State of Arduino Support

  • As of now, many Arduino core releases do not expose the ESP32C6 internal temperature sensor in a straightforward manner.
  • Some older ESP32 Arduino cores (for the original ESP32) supported temperatureRead() or a similar function, but this was not official or was soon deprecated.
  • For the ESP32C6 specifically, the Arduino core may not include the driver for the built-in temperature sensor yet (or it’s disabled by default).

(b) Potential Workarounds in Arduino

  1. Use the ESP-IDF Functions:
    You can sometimes call IDF functions from within Arduino by including the driver headers. For older ESP32 variants, that looked like:

cpp

Copy code

#include "driver/temp_sensor.h"

void setup() {
  Serial.begin(115200);

  // Configure the temperature sensor (example for classic ESP32)
  temp_sensor_config_t temp_conf = TSENS_CONFIG_DEFAULT();
  temp_sensor_set_config(temp_conf);
  temp_sensor_start();
}

void loop() {
  float tempC = 0.0;
  temp_sensor_read_celsius(&tempC);
  Serial.println(tempC);
  delay(1000);
}

2.Caution*: The ESP32C6 might have a different driver name, or the Arduino core might not have these functions compiled in yet. You’ll need to see if driver/temp_sensor.h is present in your installed esp32c6 Arduino platform.
3. Wait for Official Support:
You can watch for updates to the Espressif Arduino core for the ESP32C6. Eventually, they might add a simple function (like temperatureRead()) or re-enable the driver.

3. Using the ESP-IDF Instead (If You Need It Now)

If you’re comfortable with the Espressif IoT Development Framework (IDF) directly (i.e., not the Arduino environment), you can:

  1. Install the ESP-IDF for the ESP32C6.
  2. Check for temp_sensor_* APIs in the driver/ directory.
  3. Write your code in C/C++ using the IDF examples, then flash it to the Xiao ESP32C6.

This approach usually exposes the full set of hardware features, including the temperature sensor, if Espressif has implemented or enabled it in their C6 branch of IDF.

4. Consider an External Temperature Sensor

Given that the internal sensor is not very precise, many makers opt to attach a simple I2C temperature sensor (like an SHT30, BME280, TMP117, etc.) to the Xiao ESP32C6’s I2C pins. my favorite choice… Advantages:

  • Better accuracy (±1 °C or better).
  • Often simpler in Arduino: there are well-documented libraries for these sensors, and they produce more reliable, stable data.

5. Summary

  • Xiao ESP32C6 does have an internal temperature sensor—but official Arduino support may not be fully ready.
  • If you want a quick reading and are OK with limited accuracy, watch for ESP-IDF or updated Arduino support.
  • For reliable temperature measurement, an external sensor is your best bet.

Bottom Line: Check if your Arduino core for the ESP32C6 includes driver/temp_sensor.h. If not, you can either hack it in from the IDF or use an external sensor for accurate, stable readings.

Happy New Year!
GL :slight_smile: PJ & AI :v:

Thank you so much for your help on this.

I tried the sketch you provided. The header file driver/temp_sensor.h is there and the sketch compiles, but the sketch causes a core dump.

I’ve not gone with the external sensor so far because I’m trying to squeeze as much as I can out of a button cell. Maybe I’ll just use an external sensor to calibrate better the internal sensor. That may be a way forward for me while I wait for proper support to be added.

Thanks again and Happy New Year.

Hi there,

Did you try the older BSP 3.0.1 ?

It will probably go with the older LIB only . So give those a try. The current one is not working.
HTH
GL :slight_smile: PJ :v:

Does that mean simply rolling back the Espressif Arduino library to 3.0.1 from the latest which is 3.0.7?

Hi there,

Indeed it does… Check te Boards tab on Arduino IDE , the Pulldown let’s you “roll it” back
HTH
GL :slight_smile: PJ :v:

Ok. I’ve just tried that and unfortunately there was no difference in the response.

On the plus side, plotting the responses of the built-in sensor against that of a BME280 mounted next to it results in a pretty good straight line, so calibration will get me within a couple of degrees. I can work with that until Espressif fixes the library. Thanks.

2 Likes