Skip to content

MCP9808

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

MCP9808

温度センサ

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

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

コンストラクタ

MCP9808.new(i2c)

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

example

i2c = I2C.new(22, 21)
mcp9808 = MCP9808.new(i2c)

初期化

MCP9808.begin()

example

if !mcp9808.begin
  puts "Couldn't find MCP9808! Check your connections and verify the address is correct."
else
  ...
end

起動

MCP9808.wake

example

mcp9808.wake

停止

MCP9808.shutdown

example

mcp9808.shutdown

分解能を設定

MCP9808.set_resolution(value)

  • value : 分解能のモードを0〜3で指定
Mode Resolution SampleTime
0 0.5 ℃ 30ms
1 0.25 ℃ 65ms
2 0.125 ℃ 130ms
3 0.625 ℃ 250ms

example

mcp9808.set_resolution(3)

分解能の取得

MCP9808.get_resolution()

example

reso = mcp9808.get_resolution

温度の取得(°C)

MCP9808.read_temp_c()

example

temp_c = mcp9808.read_temp_c

温度の取得(°F)

MCP9808.read_temp_f()

example

temp_f = mcp9808.read_temp_f