#53 絶縁型4-20mA信号変換器(16bitADC)
Tibbitの配置
Tibbit #53を挿入します。
ノードの配置
以下のようにフローを配置します。
ノードの設定を開き、スロットを選択します。
Node-REDデプロイ後、injectノードをクリックするとデジタル値を取得することができます。
サンプルフロー
1 |
[{"id":"55fc995b.0c0d78","type":"Tibbit-#53","z":"3c31dc44.0e66fc","name":"","tpSlot":"S01","communication":"I2C","connectedStatus":"start","host":"","x":340,"y":1500,"wires":[["8a695867.12afc"]]},{"id":"c78e0776.9e51e8","type":"inject","z":"3c31dc44.0e66fc","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":1460,"wires":[["55fc995b.0c0d78"]]},{"id":"8a695867.12afc","type":"debug","z":"3c31dc44.0e66fc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":470,"y":1540,"wires":[]}] |
電流(A)に変換
取得した値を電流(A)に変換する方法です。
先程のフローに「電流値変換」というfunctionノードを追加します。
functionノードの編集を開き、コードに以下を記述します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
var val = msg.payload; var LSB_V = 0.000152587890625; // 5 V / 32768 var mA_On_V = 0.0032; // (20 mA - 4 mA) / 5000 mV // 電圧(V)への変換例 if (val <= 0x7FFF) { rtn_v = val * LSB_V; } else { rtn_v = 0xFFFF - val + 1; rtn_v = -(rtn_v * LSB_V); } if (rtn_v < -0.6) { return; } // 電流(A)への変換例 rtn_a = rtn_v * mA_On_V; rtn_a = rtn_a + 0.004; msg.payload = rtn_a; return msg; |
Node-REDデプロイ後、injectノードをクリックすると電流値(A)を取得することができます。
サンプルフロー
1 |
[{"id":"3a670158.37d4ee","type":"Tibbit-#53","z":"d0a8e665.0b3038","name":"","tpSlot":"S01","communication":"I2C","connectedStatus":"start","host":"","x":340,"y":3020,"wires":[["9baa2f40.9e14d8"]]},{"id":"cf22fd0a.32b35","type":"inject","z":"d0a8e665.0b3038","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":2980,"wires":[["3a670158.37d4ee"]]},{"id":"f024ac88.560ef8","type":"debug","z":"d0a8e665.0b3038","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":590,"y":3100,"wires":[]},{"id":"9baa2f40.9e14d8","type":"function","z":"d0a8e665.0b3038","name":"電流値変換","func":"var val = msg.payload;\n\nvar LSB_V = 0.000152587890625; // 5 V / 32768\nvar mA_On_V = 0.0032; // (20 mA - 4 mA) / 5000 mV\n \n// 電圧(V)への変換例\nif (val <= 0x7FFF) {\n rtn_v = val * LSB_V;\n} else {\n rtn_v = 0xFFFF - val + 1;\n rtn_v = -(rtn_v * LSB_V);\n}\n\nif (rtn_v < -0.6) {\n return;\n}\n\n// 電流(A)への変換例\nrtn_a = rtn_v * mA_On_V;\nrtn_a = rtn_a + 0.004;\n\nmsg.payload = rtn_a;\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":3060,"wires":[["f024ac88.560ef8"]]}] |