内蔵温度センサー
ESP32

概要

Arduino core for the ESP32を使った、ESP-WROOM-32開発ボードの内蔵温度センサーについての実験です。

ESP-WROOM-32には、温度センサーが内蔵されています。検索したところ、それらしいコードがあるということがわかったので、試してみました。

結論を先に書くと、「よくわかりません。正式にサポートされるのを待ちましょう。」、です。Arduino(ATmega328)内蔵温度センサに続き、2連敗となりました。

【追記】最近、リポジトリを見たら、temperatureRead()という関数が追加されていたので、追加で試してみました。記事の後半に記載しています。

Arduino core for the ESP32のインストールのページはこちら

実験

オリジナルの関数

Play the onchip Hall sensor and temperature sensorによると、Arduino core for the ESP32の、espressif/esp32/tools/sdk/lib/librtc.a に、温度測定用の関数が入っているようです。

ただし、ヘッダファイルには定義されていなので、自分で定義を書く必要があります。綴りが違っているので少し注意が必要です。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
extern "C" {
  uint8_t temprature_sens_read(); 
}
 
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
}
 
void loop() {
  // put your main code here, to run repeatedly:
  Serial.printf("Temperature: %d\n", temprature_sens_read());
  delay(1000);
}

上記のスケッチを実行した結果です。

数字が少し変化していますが、実際の温度ではなさそうです。変換方法もよくわかりません。APIの中身もブラックボックス状態です。

ESP32 Technical Reference Manualには、以下のように書かれているので、絶対値の取得には注意が必要らしいです。

It should be noted that temperature measurements are affected by heat generated by Wi-Fi circuitry. This depends on power transmission, data transfer, module / PCB construction and the related dispersion of heat. Also, temperature-versus-voltage characteristics have different offset from chip to chip, due to process variation. Therefore, the temperature sensor is suitable mainly for applications that detect temperature changes rather than the absolute value of temperature.

Improvement of accuracy in absolute temperature measurement is possible by performing sensor calibration and by operating ESP32 in low-power modes which reduce variation and the amount of heat generated by the module itself.

なお、上記の情報は、2018年6月に削除されたようです。

Removed the description of the temperature sensor and LNA.

Arduino用関数

temperatureRead()という関数が追加されていたので、試してみました。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
extern "C" {
  uint8_t temprature_sens_read(); 
}
 
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
}
 
void loop() {
  // put your main code here, to run repeatedly:
  Serial.printf("Temperature(temperature_sens_read()): %d\n", temprature_sens_read());
  Serial.printf("Temperature(temperatureRead())      : %f\n", temperatureRead());
  delay(1000);
}

上記のスケッチを実行した結果です。

temperatureRead()の実装は下記のようになっていました。temprature_sens_read()で得られた値を変換していますが、おそらく、華氏を摂氏に変換しているのではないかと思います。

1
2
3
4
5
6
7
8
9
//Undocumented!!! Get chip temperature in Farenheit
//Source: https://github.com/pcbreflux/espressif/blob/master/esp32/arduino/sketchbook/ESP32_int_temp_sensor/ESP32_int_te
mp_sensor.ino
uint8_t temprature_sens_read();

float temperatureRead()
{
    return (temprature_sens_read() - 32) / 1.8;
}

参考サイト

バージョン

Hardware:ESP-WROOM-32
Software:Arduino 1.8.3/Arduino core for the ESP32

最終更新日

March 21, 2022

inserted by FC2 system