#13 4chアナログ入力(12bitADC)
Tibbitの配置
Tibbit #13を使うにはTibbit #12が必要ですので2つ挿入します。
Tibbit #12は任意のスロットに挿入してください。
ノードの配置
chを指定するために、functionノードを使用します。
以下のようにフローを配置します。
functionノードの編集を開き、コードに以下を記述します。
デジタル値を取得したいchを指定します。
1 2 |
msg.payload = [{ch: 1}]; return msg; |
複数chの値を同時に取得することもできます。
1 2 |
msg.payload = [{ch: 1}, {ch: 2}, {ch: 3}, {ch: 4}]; return msg; |
ノードの設定を開き、スロットを選択します。
Node-REDデプロイ後、injectノードをクリックすると値を取得することができます。
サンプルフロー
1 |
[{"id":"ede1d1b1.c55d98","type":"Tibbit-#13","z":"3c31dc44.0e66fc","name":"","tpSlot":"S01","communication":"I2C","connectedStatus":"start","host":"","x":460,"y":440,"wires":[["6a2cbc88.7ccc44"]]},{"id":"6a2cbc88.7ccc44","type":"debug","z":"3c31dc44.0e66fc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":480,"wires":[]},{"id":"e389d830.3e302","type":"inject","z":"3c31dc44.0e66fc","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":400,"wires":[["c56b8978.43701"]]},{"id":"c56b8978.43701","type":"function","z":"3c31dc44.0e66fc","name":"ch指定","func":"msg.payload = [{ch: 1}];\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":400,"wires":[["ede1d1b1.c55d98"]]}] |
電圧値(mV)に変換
取得した値を電圧値(mV)に変換する方法です。
先程のフローに「電圧値変換」というfunctionノードを追加します。
functionノードの編集を開き、コードに以下を記述します。
1 2 3 4 |
var val = msg.payload[0]; val = (val*488281-1000000000)/100000; msg.payload = val; return msg; |
Node-REDデプロイ後、injectノードをクリックすると電圧値(mV)を取得することができます。
サンプルフロー
1 |
[{"id":"ede1d1b1.c55d98","type":"Tibbit-#13","z":"3c31dc44.0e66fc","name":"","tpSlot":"S01","communication":"I2C","connectedStatus":"start","host":"","x":460,"y":440,"wires":[["40a87cf2.282164"]]},{"id":"6a2cbc88.7ccc44","type":"debug","z":"3c31dc44.0e66fc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":670,"y":520,"wires":[]},{"id":"e389d830.3e302","type":"inject","z":"3c31dc44.0e66fc","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":400,"wires":[["c56b8978.43701"]]},{"id":"c56b8978.43701","type":"function","z":"3c31dc44.0e66fc","name":"ch指定","func":"msg.payload = [{ch: 1}];\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":400,"wires":[["ede1d1b1.c55d98"]]},{"id":"40a87cf2.282164","type":"function","z":"3c31dc44.0e66fc","name":"電圧値変換","func":"var val = msg.payload[0];\nval = (val*488281-1000000000)/100000;\nmsg.payload = val; \nreturn msg;","outputs":1,"noerr":0,"x":570,"y":480,"wires":[["6a2cbc88.7ccc44"]]}] |