Arduino UNO R4 Minimaでセンサ・インターフェーシング ⑪ 温度センサ TMP117
Adafruitから入手した半導体温度センサTMP117(テキサス・インスツルメンツ)を利用します。
●AdafruitのStemma QT/Qwiicボード
Stemma QT/Qwiic(JST SH 4ピン)コネクタは2か所に装着されていて、どちらにつないでもかまいません。このコネクタを使ってI2Cで制御する場合、特に、ジャンパ線をつなぐなどは不要です。
コネクタは、表と裏のどちらも差し込めそうですが、ピンが内部の上部に並んでいるので、差し込める方向は一意です。ロック機構はないですが、すぐに抜けるということはありません。
●温湿度センサTMP117のおもなスペック
- 動作電圧 1.8~5.5V
- 分解能 16ビット、LSBは0.007812℃
- 動作温度範囲 -55~150℃
- 確度
- -20~+50℃ の範囲で±0.1℃ (最大値)
- -40~+100℃ の範囲で±0.2℃ (最大値)
- -55~+150℃ の範囲で±0.3℃ (最大値)
- 消費電流 1Hzの変換サイクルで3.5uA
- インターフェース I2C(1~400kHz)
- データ長 2の補数形式の16ビット
- 平均化出力が可能
- 温度設定のアラートあり
●使用環境
- Arduino UNO R4 Minima
- Arduino IDE 2.1.1
- Windows10 22H2
●接続
Arduino UNO R4 MinimaのI2C信号とセンサをJSTコネクタでつなぎます(Stemma QT/Qwiicボードの写真の比率は異なる)。
●スレーブ・アドレスを確認
従来からよく使われているi2cScanner.inoを動かしてスレーブ・アドレスを確認します。電源は3.3Vです。
0x48を見つけてきました。
ボードの裏面にあるADDRジャンパをショートすると、スレーブ・アドレスを0x49に変更できます。
●ライブラリの用意
TMP117で検索して、見つかったAdafruit TMP117ライブラリをインストールします。
インストールを始めたとき、関連のライブラリや依存関係をインストールするかというパネルが出た場合は、全てをインストールを選びます。
●サンプル・スケッチ
メニューのファイル->スケッチ例から、Adafruit TMP117 のbasic_test.inoを選択し、
コンパイル、実行します。
●4桁の7セグメントLED表示をつないで測定結果を表示する
連載の第4回目の記事を参照しながら表示器を接続します。
Arduino UNO R4 Minimaでセンサ・インターフェーシング ④ 温湿度センサSi7021の測定結果を7セグメントLEDに表示
スケッチです。
// @author Bryan Siepert for Adafruit Industries
// @copyright Copyright (c) 2020
#include <Wire.h>
#include <Adafruit_TMP117.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"
Adafruit_TMP117 tmp117;
Adafruit_7segment matrix = Adafruit_7segment();
void setup(void) {
Serial.begin(115200);
while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("TMP117 + 7segment LED");
if (!tmp117.begin()) { // Try to initialize!
Serial.println("Failed to find TMP117 chip");
while (1) { delay(10); }
}
Serial.println("TMP117 Found!");
matrix.begin(0x70);
matrix.setBrightness(0x05); // default 0x0
}
void loop() {
sensors_event_t temp; // create an empty event to be filled
tmp117.getEvent(&temp); //fill the empty event object with the current measurements
float tempC = temp.temperature;
Serial.print("Temperature "); Serial.print(tempC,4);Serial.println(" degrees C");
Serial.println("");
matrix.print(tempC,2);
matrix.writeDisplay();
delay(5000);
}
実行例です。
●グラフィック・ディスプレイに測定結果を表示
次の記事を参考に、グラフィック・ディスプレイに測定した温度を表示します。
Arduino UNO R4 Minimaでセンサ・インターフェーシング ⑤ 温湿度センサSi7021の測定結果をグラフィック・ディスプレイに表示
スケッチです。
// @author Bryan Siepert for Adafruit Industries
// @copyright Copyright (c) 2020
#include <Wire.h>
#include <Adafruit_TMP117.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_TMP117 tmp117;
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3D ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup(void) {
Serial.begin(115200);
while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("TMP117 + SSD1306");
if (!tmp117.begin()) { // Try to initialize!
Serial.println("Failed to find TMP117 chip");
while (1) { delay(10); }
}
Serial.println("TMP117 Found!");
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
display.clearDisplay();
display.drawRect(0, 0, display.width(), display.height(), SSD1306_WHITE);
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(4,3);
display.println("Temperature:");
display.display();
delay(200);
}
void loop() {
sensors_event_t temp; // create an empty event to be filled
tmp117.getEvent(&temp); //fill the empty event object with the current measurements
float tempC = temp.temperature;
Serial.print("Temperature "); Serial.print(tempC,4);Serial.println(" degrees C");
Serial.println("");
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(10,17);
display.fillRect(10, 17, 90, 16, SSD1306_BLACK);
display.println(tempC,4);
display.display();
delay(5000);
}
実行例です。