Grove:ボリューム(パネルタイプ)
Groveのボリューム(パネルタイプ)を接続し、Tibbo-Piのアナログ入力機能を使って、ボリュームの位置を電圧値として取得します。
(Groveデバイスの詳細は上記リンクから参照願います。)
Tibbitの配置
Tibbit #00-3 と Groveデバイスを接続したTPbit #02を挿入します。
ノードの配置
chを指定するために、changeノードを使用します。
以下のようにフローを配置します。
changeノードのプロパティを開き、アナログ値を取得したいchを指定するために、以下のように設定します。
Tibbit#00ノードの設定を開き、以下のようにスロットとIN_Analogを選択します。
Node-REDデプロイ後、injectノードをクリックすると値を取得することができます。
ボリュームつまみの左端で0、右端で255に近い値が取得できます。
※Tibbo-Piのアナログ入力機能は0~5Vを0~255の値として取得しますが、#00-3内部の回路の影響で、最大255ではなく250付近の値が取得されます。
サンプルフロー
1 |
[{"id":"f9079b23.579368","type":"Tibbit-#00","z":"b6cc6129.81752","name":"","tpSlot":"S01","communication":"GPIO","pinA":"IN_Analog","pinB":"other","pinC":"other","pinD":"other","i2cBaudRateK":"100","spiSpeed":"500","spiMode":"1","spiEndian":"1","serialConf":"","connectedStatus":"start","host":"","x":480,"y":220,"wires":[["2119bbfe.becfb4"]]},{"id":"2119bbfe.becfb4","type":"debug","z":"b6cc6129.81752","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":640,"y":260,"wires":[]},{"id":"97b5b89b.782f88","type":"change","z":"b6cc6129.81752","name":"ch指定","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload[0].line","pt":"msg","to":"A","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":180,"wires":[["f9079b23.579368"]]},{"id":"449387d0.da2678","type":"inject","z":"b6cc6129.81752","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":180,"wires":[["97b5b89b.782f88"]]}] |
電圧値(V)に変換
取得した値を電圧値(V)に変換する方法です。
変換のために、rangeノードを使用します。
先程のフローに以下のようにrangeノードを追加します。
rangeノードのプロパティを開き、以下のように設定します。0~255の取得値を0~5Vの電圧に変換する設定です。
Node-REDデプロイ後、injectノードをクリックすると電圧値(V)を取得することができます。
サンプルフロー
1 |
[{"id":"f9079b23.579368","type":"Tibbit-#00","z":"b6cc6129.81752","name":"","tpSlot":"S01","communication":"GPIO","pinA":"IN_Analog","pinB":"other","pinC":"other","pinD":"other","i2cBaudRateK":"100","spiSpeed":"500","spiMode":"1","spiEndian":"1","serialConf":"","connectedStatus":"start","host":"","x":480,"y":220,"wires":[["4ad3ae48.5803a"]]},{"id":"2119bbfe.becfb4","type":"debug","z":"b6cc6129.81752","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":740,"y":300,"wires":[]},{"id":"97b5b89b.782f88","type":"change","z":"b6cc6129.81752","name":"ch指定","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload[0].line","pt":"msg","to":"A","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":180,"wires":[["f9079b23.579368"]]},{"id":"449387d0.da2678","type":"inject","z":"b6cc6129.81752","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":180,"wires":[["97b5b89b.782f88"]]},{"id":"4ad3ae48.5803a","type":"range","z":"b6cc6129.81752","minin":"0","maxin":"255","minout":"0","maxout":"5","action":"scale","round":false,"property":"payload","name":"電圧値変換","x":610,"y":260,"wires":[["2119bbfe.becfb4"]]}] |
電圧値(V)の小数桁の四捨五入
このままでは、小数の桁数が多すぎて見づらいので、小数点2桁より下を四捨五入します。
四捨五入は、changeノードの「JSONate式」を使用します。
先程のフローに以下のようにchangeノードを追加します。
changeノードのプロパティを開き、対象の値の種類から「JSONate式」を選択します。
その後、以下のように設定します。
Node-REDデプロイ後、injectノードをクリックすると小数2桁までの電圧値(V)を取得することができます。
サンプルフロー
1 |
[{"id":"f9079b23.579368","type":"Tibbit-#00","z":"b6cc6129.81752","name":"","tpSlot":"S01","communication":"GPIO","pinA":"IN_Analog","pinB":"other","pinC":"other","pinD":"other","i2cBaudRateK":"100","spiSpeed":"500","spiMode":"1","spiEndian":"1","serialConf":"","connectedStatus":"start","host":"","x":480,"y":220,"wires":[["4ad3ae48.5803a"]]},{"id":"2119bbfe.becfb4","type":"debug","z":"b6cc6129.81752","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":740,"y":300,"wires":[]},{"id":"97b5b89b.782f88","type":"change","z":"b6cc6129.81752","name":"ch指定","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload[0].line","pt":"msg","to":"A","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":180,"wires":[["f9079b23.579368"]]},{"id":"449387d0.da2678","type":"inject","z":"b6cc6129.81752","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":180,"wires":[["97b5b89b.782f88"]]},{"id":"4ad3ae48.5803a","type":"range","z":"b6cc6129.81752","minin":"0","maxin":"255","minout":"0","maxout":"5","action":"scale","round":false,"property":"payload","name":"電圧値変換","x":570,"y":260,"wires":[["c168668d.4bb878"]]},{"id":"c168668d.4bb878","type":"change","z":"b6cc6129.81752","name":"小数四捨五入","rules":[{"t":"set","p":"payload","pt":"msg","to":"$round(msg.payload, 2)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":260,"wires":[["2119bbfe.becfb4"]]}] |