Skip to content
Nishikori Koji edited this page Feb 24, 2022 · 3 revisions

Si7021

温湿度センサ

コードURL: https://github.com/gfd-dennou-club/iotex-esp32-mrubyc/blob/master/mrblib/models/si7021.rb

サンプルコード: https://github.com/gfd-dennou-club/iotex-esp32-mrubyc/blob/master/example/master.rb.si7021

コンストラクタ

Si7021.new(i2c)

  • i2c : I2Cクラスのオブジェクト

example

i2c = I2C.new(22, 21)
si7021 = Si7021.new(i2c)

初期化とセンサの接続確認

Si7021.begin()

example

if !si7021.begin
  puts "Did not find Si7021 sensor!"
else
  ...
end

気温の取得(℃)

Si7021.read_temp()

example

temp = si7021.read_temp

湿度の取得(%)

Si7021.read_humid()

example

humid = si7021.read_humid

ヒーターのレベルを設定

Si7021.set_heater_level()

  • level : ヒーターのレベル(ハッシュHEAT_LEVELに定義)

HEAT_LEVEL

HEAT_LEVEL = {"LOWEST" => 0x00, "LOW" => 0x01, "MEDIUM" => 0x02, "HIGH" => 0x04, "HIGHER" => 0x08, "HIGHEST" => 0x0F }

example

si7021.set_heater_level(Si7021::HEAT_LEVEL["MEDIUM"])

ヒーターの起動と停止

Si7021.heater(sw)

  • sw : ヒーターの起動はtrue、停止はfalse

example

si7021.heater(true)
si7021.heater(false)

ヒーターの状態を取得

Si7021.heater_status()

example

si7021.heater_status ? puts("ENABLED") : puts("DISENABLE")