Arduino UNO R4 Minimaでセンサ・インターフェーシング ⑫ 温湿度センサ SHTC3

 Adafruitから入手した半導体温湿度センサ SHTC3(センシリオン)を利用します。

AdafruitのStemma QT/Qwiicボード

 SHTC3ボード解説のページ

 センシリオンの温湿度センサSHT4xシリーズは、第6回でSHT40第7回でSHT45を取り上げています。何が異なるのでしょうか。SHTC3はモバイル用途がデータシートに書かれているので、アイドル時の消費電流が低めです。

  SHTC3 SHT40
電源電圧[V] 1.62~3.6 1.08~3.6
消費電流[uA] アイドル時45(typ)、測定時430(typ) アイドル時80(typ)、測定時400(typ)
湿度[%RH] 確度±2、分解能0.01 確度±1.8、分解能0.01
温度[℃] 確度±0.2(0~90)、分解能0.01 確度±0.2(0~60)、分解能0.01
外形[mm] 2×2×0.75 1.5×1.5×0.54
I2C 0~1MHz  0x70 0~400kHz  0x44

 Stemma QT/Qwiic(JST SH 4ピン)コネクタは2か所に装着されていて、どちらにつないでもかまいません。このコネクタを使ってI2Cで制御する場合、特に、ジャンパ線をつなぐなどは不要です。

 コネクタは、表と裏のどちらも差し込めそうですが、ピンが内部の上部に並んでいるので、差し込める方向は一意です。ロック機構はないですが、すぐに抜けるということはありません。

温湿度センサSHTC3のおもなスペック

 SHTC3のデータシート

  • 電源電圧  1.62~3.6V
  • 湿度 確度±2%RH、分解能0.01%RH
  • 温度 確度±0.2℃(0~90)、分解能0.01℃
  • インターフェース I2C(0~1MHz)
  • スレーブ・アドレス 0x70(固定)

使用環境

  • Arduino UNO R4 Minima
  • Arduino IDE 2.1.1
  • Windows10 22H2

接続

 Arduino UNO R4 MinimaのI2C信号とセンサをJSTコネクタでつなぎます(Stemma QT/Qwiicボードの写真の比率は異なる)。

スレーブ・アドレスを確認

 従来からよく使われているi2cScanner.inoを動かしてスレーブ・アドレスを確認します。電源は5Vです。

  0x70を見つけてきました。

 以降のスケッチは3.3Vで動作させます。

 

 


ライブラリの用意

 SHTC3で検索して、見つかったAdafruit SHTC3ライブラリをインストールします。

 インストールを始めると次のパネルが出ました。
 全てをインストールを選びました。


サンプル・スケッチ

 メニューのファイル->スケッチ例から、Adafruit SHTC3のSHTC3test.inoを選択し、

コンパイル、実行します。

 

4桁の7セグメントLED表示器をつないで測定結果を表示する

 連載の第4回目の記事を参照しながら表示器を接続します。

Arduino UNO R4 Minimaでセンサ・インターフェーシング ④ 温湿度センサSi7021の測定結果を7セグメントLEDに表示


 スケッチです。


// Designed specifically to work with the SHTC3 sensor from Adafruit
//  ----> https://www.adafruit.com/products/4636

#include <Wire.h>  // Enable this line if using Arduino Uno, Mega, etc.
#include <Adafruit_GFX.h> #include "Adafruit_LEDBackpack.h" #include "Adafruit_SHTC3.h" Adafruit_7segment matrix = Adafruit_7segment(); Adafruit_SHTC3 shtc3 = Adafruit_SHTC3(); void setup() { Serial.begin(115200); while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens Serial.println("SHTC3 + 7segment LED"); Serial.println("SHTC3 test"); if (! shtc3.begin()) { Serial.println("Couldn't find SHTC3"); while (1) delay(1); } Serial.println("Found SHTC3 sensor"); matrix.begin(0x70); matrix.setBrightness(0x05); // default 0x0E } void loop() { sensors_event_t humidity, temp; shtc3.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data float tempC = temp.temperature; float hume = humidity.relative_humidity; Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" degrees C"); Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH"); matrix.print(tempC, DEC); matrix.writeDisplay(); delay(2000); matrix.print(hume, DEC); matrix.writeDisplay(); delay(5000); }


 実行するとエラーになりました。

SHTC3 test
Couldn't find SHTC3

 二つのデバイスのスレーブ・アドレスが0x70でぶつかっています。センサはアドレスが固定なので変更できないので、7セグメントLED表示器の裏面のジャンパA0をショートします。

 i2cScannerを動かします。電源は5Vです。

Scanning...
I2C device found at address 0x70  !
I2C device found at address 0x71  !
done

 0x71に変更され、ぶつからなくなくなりました。

 電源を3.3Vにしてから、次のように、setup{}内のアドレスを変更し、スケッチをコンパイルして動かします。

matrix.begin(0x71);

 実行例です。

グラフィック・ディスプレイに測定結果を表示

 次の記事を参考に、グラフィック・ディスプレイに測定した温度と湿度を表示します。

  Arduino UNO R4 Minimaでセンサ・インターフェーシング ⑤ 温湿度センサSi7021の測定結果をグラフィック・ディスプレイに表示

 スケッチです。


// Designed specifically to work with the SHTC3 sensor from Adafruit
//  ----> https://www.adafruit.com/products/4636
// Written by Limor Fried/Ladyada for Adafruit Industries,

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h> #include "Adafruit_SHTC3.h" #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); Adafruit_SHTC3 shtc3 = Adafruit_SHTC3(); void setup() { Serial.begin(115200); while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens Serial.println("\nSHTC3 + SSD1306"); if (! shtc3.begin()) { Serial.println("Couldn't find SHTC3"); while (1) delay(1); } Serial.println("Found SHTC3 sensor"); 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.setTextSize(1); display.setTextColor(SSD1306_WHITE); display.setCursor(4,34); display.println("Humidity:"); display.display(); delay(200); } void loop() { sensors_event_t humidity, temp; shtc3.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data float tempC = temp.temperature; float humi = humidity.relative_humidity; Serial.print("Temperature: "); Serial.print(tempC); Serial.println(" degrees C"); Serial.print("Humidity: "); Serial.print(humi); Serial.println("% rH"); dispMeasurement(tempC, humi); delay(5000); } void dispMeasurement(float temp, float humi) { display.setTextSize(2); // Draw 2X-scale text display.setCursor(10,17); display.fillRect(10, 17, 70, 16, SSD1306_BLACK); display.println(temp); display.setCursor(10, 46); display.fillRect(10, 46, 70, 16, SSD1306_BLACK); display.println(humi); display.display(); }

 実行例です。

前へ

Arduino UNO R4 Minimaでセンサ・インターフェーシング ⑪ 温度センサ TMP117

次へ

Arduino UNO R4の登場で広がるArduinoの世界(4)i2clcdaqmライブラリの作成