当前位置:   article > 正文

树莓派3b Node-red 控制Nextion_node-red nextion

node-red nextion
  • 注意目前2018年购买得到的Nextion 通信率是115200的,网上很多例子程序是基于9600波特率,如果不做修改是没办法跟Nextion 通讯的。
  • The Nextion project

I made a simple screen with 4 text field to receive data form the RPI.

The text field are named: t0, t1, t2, t3.

nextion_project

Here is the project file (download and rename it as rpi_hmi.HMI)

downlod rpi_hmi.HMI

pi3_gpio

Connect + 5 VDC to pin 2

Connect GND to pin 6

Connect Rx to pin 8

Connect Tx to pin 10

  • To send data to the screen I am using my favorite application: Node-Red.

From Node-Red it is possible to run commands and send them to the serial port.

Before that we should make sure that the serial port is available.

 

显示cup温度+显示hello world节点:

[{"id":"7195d31f.9f00ec","type":"inject","z":"c2a11d2d.b46b08","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":384,"y":82,"wires":[["49e2c69e.acfdb","24c711af.76b236","b1499587.98cd58"]]},{"id":"49e2c69e.acfdb","type":"function","z":"c2a11d2d.b46b08","name":"","func":"s_object = \"t0.txt=\";\ns_text = \"Hello World\";\nvar arr = [];\nfor (var i = 0, l = s_object.length; i < l; i ++) {\n    var ascii = s_object.charCodeAt(i);\n    arr.push(ascii);\n}\narr.push(0x22);\nfor (var i = 0, l = s_text.length; i < l; i ++) {\n    var ascii = s_text.charCodeAt(i);\n    arr.push(ascii);\n}\narr.push(0x22);\narr.push(0xFF);\narr.push(0xFF);\narr.push(0xFF);\nmsg.payload = new Buffer(arr);\nreturn msg;","outputs":1,"noerr":0,"x":544,"y":81,"wires":[["a8bf7e18.a642c8"]]},{"id":"a8bf7e18.a642c8","type":"serial out","z":"c2a11d2d.b46b08","name":"","serial":"1a952e29.669a12","x":892,"y":84,"wires":[]},{"id":"cb2a6f41.8fe8","type":"serial in","z":"c2a11d2d.b46b08","name":"","serial":"1a952e29.669a12","x":368,"y":360,"wires":[["8dca6037.eacae"]]},{"id":"8dca6037.eacae","type":"debug","z":"c2a11d2d.b46b08","name":"","active":true,"console":"false","complete":"false","x":654,"y":363,"wires":[]},{"id":"24c711af.76b236","type":"function","z":"c2a11d2d.b46b08","name":"","func":"s_object = \"t1.txt=\";\ns_text = \"Line 2\";\nvar arr = [];\nfor (var i = 0, l = s_object.length; i < l; i ++) {\n    var ascii = s_object.charCodeAt(i);\n    arr.push(ascii);\n}\narr.push(0x22);\nfor (var i = 0, l = s_text.length; i < l; i ++) {\n    var ascii = s_text.charCodeAt(i);\n    arr.push(ascii);\n}\narr.push(0x22);\narr.push(0xFF);\narr.push(0xFF);\narr.push(0xFF);\nmsg.payload = new Buffer(arr);\nreturn msg;","outputs":1,"noerr":0,"x":544.5,"y":145,"wires":[["a8bf7e18.a642c8"]]},{"id":"b1499587.98cd58","type":"exec","z":"c2a11d2d.b46b08","command":"vcgencmd measure_temp","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"measure temp","x":602.5,"y":241,"wires":[["d3e6fe45.d307f8"],[],[]]},{"id":"d3e6fe45.d307f8","type":"function","z":"c2a11d2d.b46b08","name":"","func":"s_object = \"t2.txt=\";\ns_text = msg.payload;\nvar arr = [];\nfor (var i = 0, l = s_object.length; i < l; i ++) {\n    var ascii = s_object.charCodeAt(i);\n    arr.push(ascii);\n}\narr.push(0x22);\nfor (var i = 0, l = s_text.length; i < l; i ++) {\n    var ascii = s_text.charCodeAt(i);\n    arr.push(ascii);\n}\narr.push(0x22);\narr.push(0xFF);\narr.push(0xFF);\narr.push(0xFF);\nmsg.payload = new Buffer(arr);\nreturn msg;","outputs":1,"noerr":0,"x":805.5,"y":232,"wires":[["a8bf7e18.a642c8"]]},{"id":"1a952e29.669a12","type":"serial-port","z":"c2a11d2d.b46b08","serialport":"/dev/ttyAMA0","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","newline":"500","bin":"bin","out":"time","addchar":false}]

只显示hello 节点流

[{"id":"e3567c31.6e8d1","type":"inject","z":"c2a11d2d.b46b08","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":716,"y":590,"wires":[["6ac0ffcc.190df"]]},{"id":"6ac0ffcc.190df","type":"function","z":"c2a11d2d.b46b08","name":"","func":"s_object = \"t0.txt=\";\ns_text = \"Hello\";\nvar arr = [];\nfor (var i = 0, l = s_object.length; i < l; i ++) {\n    var ascii = s_object.charCodeAt(i);\n    arr.push(ascii);\n}\narr.push(0x22);\nfor (var i = 0, l = s_text.length; i < l; i ++) {\n    var ascii = s_text.charCodeAt(i);\n    arr.push(ascii);\n}\narr.push(0x22);\narr.push(0xFF);\narr.push(0xFF);\narr.push(0xFF);\nmsg.payload = new Buffer(arr);\nreturn msg;","outputs":1,"noerr":0,"x":884,"y":590,"wires":[["9e33653b.84c6a"]]},{"id":"9e33653b.84c6a","type":"serial out","z":"c2a11d2d.b46b08","name":"","serial":"d1ecbcdd.65309","x":1098,"y":589,"wires":[]},{"id":"d1ecbcdd.65309","type":"serial-port","z":"c2a11d2d.b46b08","serialport":"/dev/ttyAMA0","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","newline":"100","bin":"bin","out":"time","addchar":false}]

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/484511
推荐阅读
相关标签
  

闽ICP备14008679号