ユーザ用ツール

サイト用ツール


raspi_iot:ノード機のプログラミング

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
次のリビジョン両方とも次のリビジョン
raspi_iot:ノード機のプログラミング [2019/03/30 11:30] hirohitoraspi_iot:ノード機のプログラミング [2021/07/05 11:12] hirohito
行 53: 行 53:
 i2c = I2C.create(NODE) i2c = I2C.create(NODE)
 res = i2c.read(ADRS, 1, 0x0f) res = i2c.read(ADRS, 1, 0x0f)
-printf "RESULT: 0x%02x\n", res[0].ord+printf "RESULT: 0x%02x\n", res.getbyte(0)
 </code> </code>
  
行 102: 行 102:
 できたプログラム全体です。 できたプログラム全体です。
  
-<code ruby device_test.rb>+<code ruby device_test2.rb>
 require "i2c" require "i2c"
 ADRS = 0x5c          # LPS25H ADRS = 0x5c          # LPS25H
行 117: 行 117:
 i2c = I2C.create(NODE) i2c = I2C.create(NODE)
 res = i2c.read(ADRS, 1, 0x0f) res = i2c.read(ADRS, 1, 0x0f)
-printf "RESULT: 0x%02x\n", res[0].ord+printf "RESULT: 0x%02x\n", res.getbyte(0)
  
 i2c.write(ADRS, 0x20, 0x90) i2c.write(ADRS, 0x20, 0x90)
 sleep 1 sleep 1
 buf = i2c.read(ADRS, 5, 0xa8) # Read 5 bytes from 0x28 register with cont mode. buf = i2c.read(ADRS, 5, 0xa8) # Read 5 bytes from 0x28 register with cont mode.
-p_cnt = to_uint24(buf[2].ord, buf[1].ord, buf[0].ord)+p_cnt = to_uint24(buf.getbyte(2), buf.getbyte(1), buf.getbyte(0))
 p p_cnt.to_f / 4096 p p_cnt.to_f / 4096
  
-t_cnt = to_int16(buf[4].ord, buf[3].ord)+t_cnt = to_int16(buf.getbyte(4), buf.getbyte(3))
 p 42.5 + t_cnt.to_f / 480 p 42.5 + t_cnt.to_f / 480
 </code> </code>
raspi_iot/ノード機のプログラミング.txt · 最終更新: 2021/11/04 14:05 by hirohito