raspi_iot:ノード機のプログラミング
差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン次のリビジョン両方とも次のリビジョン | ||
raspi_iot:ノード機のプログラミング [2019/03/30 11:13] – [ステップ2] hirohito | raspi_iot:ノード機のプログラミング [2021/07/05 11:12] – hirohito | ||
---|---|---|---|
行 53: | 行 53: | ||
i2c = I2C.create(NODE) | i2c = I2C.create(NODE) | ||
res = i2c.read(ADRS, | res = i2c.read(ADRS, | ||
- | printf " | + | printf " |
</ | </ | ||
行 102: | 行 102: | ||
できたプログラム全体です。 | できたプログラム全体です。 | ||
- | <code ruby device_test.rb> | + | <code ruby device_test2.rb> |
require " | require " | ||
ADRS = 0x5c # LPS25H | ADRS = 0x5c # LPS25H | ||
行 117: | 行 117: | ||
i2c = I2C.create(NODE) | i2c = I2C.create(NODE) | ||
res = i2c.read(ADRS, | res = i2c.read(ADRS, | ||
- | printf " | + | printf " |
i2c.write(ADRS, | i2c.write(ADRS, | ||
sleep 1 | sleep 1 | ||
buf = i2c.read(ADRS, | buf = i2c.read(ADRS, | ||
- | 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 | ||
</ | </ | ||
行 168: | 行 168: | ||
<code ruby worker.rb> | <code ruby worker.rb> | ||
- | # | ||
- | |||
require " | require " | ||
require " | require " | ||
行 287: | 行 285: | ||
- | === デバッグ時 === | + | ==== デバッグ時 |
最初の測定は起動から1分後ですので、少し待たなければなりません。デバッグ時に何度もトライする場合は待ち時間がもったいないので、イニシャライザの、Timer.periodic( 60 ) を60秒から数秒程度に短くして試すのが良いでしょう。 | 最初の測定は起動から1分後ですので、少し待たなければなりません。デバッグ時に何度もトライする場合は待ち時間がもったいないので、イニシャライザの、Timer.periodic( 60 ) を60秒から数秒程度に短くして試すのが良いでしょう。 |
raspi_iot/ノード機のプログラミング.txt · 最終更新: 2021/11/04 14:05 by hirohito