忘備録-備忘録

技術的な備忘録

node-redでLCD表示 その3

2017-12-12 20:08:00 | raspberry ...

前回のnode-redでLCD表示その2を少し変更しループなしで表示できるようにしました。

image

[{"id":"b9779166.036e5","type":"function","z":"3cd97708.f90178","name":"LCD表示","func":" let lcdData = [\n    [0x00,0x38],\n    [0x00,0x39],\n    [0x00,0x14],\n    [0x00,0x73],\n    [0x00,0x56],\n    [0x00,0x6c],\n    [0x00,0x38],\n    [0x00,0x01],\n    [0x00,0x0c],\n    [0x00,0xc0],\n    ];\nlet outputMsgs = [];\n\nconst LcdI2Caddr = 0x3e;\nlet i;\n\nfor(i=0;i<msg.payload.length;i++) {\n    lcdData.push( [0x40, msg.payload[i] ] );\n}\n\nfor(i = 0;i<lcdData.length;i++) {\n    outputMsgs.push({\"payload\":lcdData[i][1],\"command\":lcdData[i][0],\"address\":LcdI2Caddr});\n} \n\nreturn  [outputMsgs];","outputs":1,"noerr":0,"x":429,"y":1047,"wires":[["c520529.88c45b"]]},{"id":"49091682.df7908","type":"inject","z":"3cd97708.f90178","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":126,"y":1047,"wires":[["1bb76323.a2cccd"]]},{"id":"b5b5d04e.b0892","type":"debug","z":"3cd97708.f90178","name":"","active":true,"console":"false","complete":"false","x":738,"y":1093,"wires":[]},{"id":"82380ed9.41793","type":"i2c out","z":"3cd97708.f90178","name":"","address":"","command":"","payload":"payload","payloadType":"msg","count":"1","x":727,"y":1047,"wires":[]},{"id":"1bb76323.a2cccd","type":"template","z":"3cd97708.f90178","name":"メッセージ","field":"payload","fieldType":"msg","format":"text","syntax":"plain","template":"test message","output":"str","x":277,"y":1047,"wires":[["b9779166.036e5"]]},{"id":"c520529.88c45b","type":"delay","z":"3cd97708.f90178","name":"","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":577,"y":1047,"wires":[["82380ed9.41793","b5b5d04e.b0892"]]}]
コメント
この記事をはてなブックマークに追加

node-redでLCD表示 その2

2017-12-11 20:36:14 | raspberry ...

前回のnode-redでLCD表示を少し変更し任意の文字列を表示できるようにしました。

image

[{"id":"38826655.6c18fa","type":"function","z":"3cd97708.f90178","name":"LCD表示","func":"if (typeof this.times === 'undefined') {\n    this.times = 0;\n}\n\nif( typeof this.lcdData === 'undefined' ) {\n    this.lcdData = [\n    [0x00,0x38],\n    [0x00,0x39],\n    [0x00,0x14],\n    [0x00,0x73],\n    [0x00,0x56],\n    [0x00,0x6c],\n    [0x00,0x38],\n    [0x00,0x01],\n    [0x00,0x0c],\n    [0x00,0xc0],\n    ];\n}\n\nconst initLcdData = 10;\nconst LcdI2Caddr = 0x3e;\n\nif(this.times===0) {\n    for(i=0;i<msg.payload.length;i++) {\n        this.lcdData.push( [0x40, msg.payload[i] ] );\n    }\n}\n\nif(this.times<this.lcdData.length) {\n    msg.address = LcdI2Caddr;\n    msg.command = this.lcdData[times][0];\n    msg.payload = this.lcdData[times][1];\n    this.times++;\n    return msg;    \n} else {\n    return;\n}\nreturn msg;","outputs":1,"noerr":0,"x":535,"y":813,"wires":[["9871647a.f198f8","d10bebd2.0b5d38","9655fadd.ec6138"]]},{"id":"42b20597.19dd7c","type":"inject","z":"3cd97708.f90178","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":175,"y":813,"wires":[["b50affff.3e98"]]},{"id":"9655fadd.ec6138","type":"debug","z":"3cd97708.f90178","name":"","active":true,"console":"false","complete":"false","x":699,"y":857,"wires":[]},{"id":"9871647a.f198f8","type":"i2c out","z":"3cd97708.f90178","name":"","address":"","command":"","payload":"payload","payloadType":"msg","count":"1","x":699,"y":813,"wires":[]},{"id":"d10bebd2.0b5d38","type":"delay","z":"3cd97708.f90178","name":"","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":532,"y":729,"wires":[["38826655.6c18fa"]]},{"id":"b50affff.3e98","type":"template","z":"3cd97708.f90178","name":"メッセージ","field":"payload","fieldType":"msg","format":"text","syntax":"plain","template":"Hello world!!","output":"str","x":354,"y":812,"wires":[["38826655.6c18fa"]]}]
コメント
この記事をはてなブックマークに追加

node-redでLCD表示

2017-12-09 18:20:00 | raspberry ...

raspberry piとnode-red上で秋月電子通商製のI2C接続小型キャラクタLCDモジュール に文字を出力するflowを作成しました。最初に[パレットの管理]で[node-red-contrib-i2c]を追加します。

image

設定は

msg.address : I2C機器のアドレス

msg.command : 機器に送るコマンド(最初の1byte)

msg.payload : 機器に送るデータ(2byte目以降 最大32byte)

となります。

LCDに表示するflowは次のようになります。

image

複数回コマンドを出力する必要があったため、[delay]を使いループを組みました。[LCD表示]ではreturnを工夫して無限ループを終了しています。

ループは”return msg;”で値返し回ります。”return;”のみだとメッセージがないのでループを回らなくなります。

全体を次に置いておきます。

[{"id":"1c3ab761.76a7e9","type":"function","z":"3cd97708.f90178","name":"LCD表示","func":"// context.set('変数名',値); グローバル変数の設定\n// var val = context.get('変数名')||0;グローバル変数の読み込み\n// ||0; の部分は初期化指定 \n// 変数が設定されていない場合内は0に初期化\n\n//プロパティの追加\n//静的変数のように使用できる\n//注意: 外部からの参照も可能\nif (typeof this.times === 'undefined') {\n    this.times = 0;\n}\n\nvar lcdData = [\n    [0x00,0x38],\n    [0x00,0x39],\n    [0x00,0x14],\n    [0x00,0x73],\n    [0x00,0x56],\n    [0x00,0x6c],\n    [0x00,0x38],\n    [0x00,0x01],\n    [0x00,0x0c],\n    [0x00,0xc0],\n    [0x40,'H'],\n    [0x40,'e'],\n    [0x40,'l'],\n    [0x40,'l'],\n    [0x40,'o'],\n    [0x40,' '],\n    [0x40,'w'],\n    [0x40,'o'],\n    [0x40,'r'],\n    [0x40,'l'],\n    [0x40,'d'],\n    ];\n\nif(times<lcdData.length) {\n    msg.address = 0x3e;\n    msg.command = lcdData[times][0];\n    msg.payload = lcdData[times][1];\n    this.times++;\n    return msg;    \n} else {\n    return;\n}\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":567,"wires":[["b6f9485b.c4d978","a4a8e74f.f796a8","39ea46fa.df3bfa"]]},{"id":"d6d6c364.b56ee","type":"inject","z":"3cd97708.f90178","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":254,"y":567,"wires":[["1c3ab761.76a7e9"]]},{"id":"39ea46fa.df3bfa","type":"debug","z":"3cd97708.f90178","name":"","active":true,"console":"false","complete":"false","x":584,"y":611,"wires":[]},{"id":"b6f9485b.c4d978","type":"i2c out","z":"3cd97708.f90178","name":"","address":"","command":"","payload":"payload","payloadType":"msg","count":"1","x":584,"y":567,"wires":[]},{"id":"a4a8e74f.f796a8","type":"delay","z":"3cd97708.f90178","name":"","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":417,"y":483,"wires":[["1c3ab761.76a7e9"]]}]
コメント
この記事をはてなブックマークに追加

Raspberry PiのchromiumでProxyサーバを使う

2017-11-10 20:33:00 | raspberry ...

Raspberry PiのchromiumでProxyサーバ越しにWebサイトにアクセスするにはコマンドラインで次のように入力します。

$ chromium --proxy-server="proxy-server:port"


環境変数CHROMIUM_FLAGSに設定しておくことで省略することが可能です。また、HTTP_PROXY,HTTPS_PROXY,FTP_PROXY環境変数も参照するようです。メニューエディタでコマンドの内容を書き換えればGUIから起動することもできます。

コメント
この記事をはてなブックマークに追加

Raspberry piのネットワーク設定をGUIで行う

2017-11-10 19:15:45 | raspberry ...

Raspberry Piのネットワーク設定をGUIで行えるようにするには次のようにします。

$ sudo apt-get install network-manager
$ sudo apt-get install network-manager-gnome
$ sudo mv /etc/network/interfaces /etc/network/interfaces.bkup 
$ sudo touch /etc/network/interfaces

この後、再起動するとタスクバーにネットワークの設定が加わります。

コメント
この記事をはてなブックマークに追加