├── .gitignore ├── LICENSE ├── README.md ├── client.js └── client.py /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | *.publishproj 131 | 132 | # NuGet Packages Directory 133 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 134 | #packages/ 135 | 136 | # Windows Azure Build Output 137 | csx 138 | *.build.csdef 139 | 140 | # Windows Store app package directory 141 | AppPackages/ 142 | 143 | # Others 144 | sql/ 145 | *.Cache 146 | ClientBin/ 147 | [Ss]tyle[Cc]op.* 148 | ~$* 149 | *~ 150 | *.dbmdl 151 | *.[Pp]ublish.xml 152 | *.pfx 153 | *.publishsettings 154 | 155 | # RIA/Silverlight projects 156 | Generated_Code/ 157 | 158 | # Backup & report files from converting an old project file to a newer 159 | # Visual Studio version. Backup files are not needed, because we have git ;-) 160 | _UpgradeReport_Files/ 161 | Backup*/ 162 | UpgradeLog*.XML 163 | UpgradeLog*.htm 164 | 165 | # SQL Server files 166 | App_Data/*.mdf 167 | App_Data/*.ldf 168 | 169 | ############# 170 | ## Windows detritus 171 | ############# 172 | 173 | # Windows image file caches 174 | Thumbs.db 175 | ehthumbs.db 176 | 177 | # Folder config file 178 | Desktop.ini 179 | 180 | # Recycle Bin used on file shares 181 | $RECYCLE.BIN/ 182 | 183 | # Mac crap 184 | .DS_Store 185 | 186 | 187 | ############# 188 | ## Python 189 | ############# 190 | 191 | *.py[cod] 192 | 193 | # Packages 194 | *.egg 195 | *.egg-info 196 | dist/ 197 | build/ 198 | eggs/ 199 | parts/ 200 | var/ 201 | sdist/ 202 | develop-eggs/ 203 | .installed.cfg 204 | 205 | # Installer logs 206 | pip-log.txt 207 | 208 | # Unit test / coverage reports 209 | .coverage 210 | .tox 211 | 212 | #Translations 213 | *.mo 214 | 215 | #Mr Developer 216 | .mr.developer.cfg 217 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Grégory 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Nextion for Raspberry 2 | Little program that let you use a Nextion screen with Node.js or Python. 3 | ## Node.js 4 | ### Dépendance 5 | **[Serialport](https://www.npmjs.com/package/serialport)** 6 | 7 | ### Utilisation 8 | #### write.uart 9 | ```javascript 10 | write.uart('page 0'); 11 | ``` 12 | #### write.setPage 13 | Changer la page actuelle 14 | 15 | *Change actual page* 16 | ```javascript 17 | write.setPage(0); 18 | ``` 19 | #### write.setText 20 | Changer le texte d'un composant 21 | 22 | *Update component text* 23 | ```javascript 24 | write.setText('t0', "Hello world!"); 25 | ``` 26 | #### write.setVis 27 | Rendre un composant invisible 28 | 29 | *Set a component not visible* 30 | ```javascript 31 | write.setVis('t0', false); 32 | ``` 33 | #### write.setColor 34 | Changer la couleur background d'un composant 35 | 36 | *Update background color of component* 37 | ```javascript 38 | write.setColor('t0', '01234'); 39 | ``` 40 | #### write.getPage 41 | L'écran renverra le numéro de page quand l'utilisateur change de page 42 | 43 | *The screen will send page number when user change page* 44 | ```javascript 45 | write.getPage(); 46 | ``` 47 | 48 | Pour écrire des données brutes il suffit d'utiliser ```write.uart(commande);``` 49 | 50 | *To write raw data you can use ```write.uart(command);```* 51 | ## Python 52 | ```bash 53 | sudo python client.py commande 54 | ``` 55 | 56 | # License 57 | ``` 58 | Copyright (c) 2016 Grégory 59 | 60 | Permission is hereby granted, free of charge, to any person obtaining a copy 61 | of this software and associated documentation files (the "Software"), to deal 62 | in the Software without restriction, including without limitation the rights 63 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 64 | copies of the Software, and to permit persons to whom the Software is 65 | furnished to do so, subject to the following conditions: 66 | 67 | The above copyright notice and this permission notice shall be included in all 68 | copies or substantial portions of the Software. 69 | 70 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 71 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 72 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 73 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 74 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 75 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 76 | SOFTWARE. 77 | ``` 78 | -------------------------------------------------------------------------------- /client.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | Nextion.js for Raspberry Pi / Node.js 5 | 6 | Grégory G. 7 | 8 | */ 9 | 10 | var serialport = require('serialport'); 11 | var SerialPort = serialport.SerialPort; 12 | 13 | var port = new SerialPort('/dev/ttyAMA0', { 14 | baudrate: 9600 15 | }); 16 | 17 | function init(){ 18 | port.on('open', function() { 19 | console.log('Port ouvert sur /dev/ttyAMA0 @ 9600 bds'); 20 | write.setPage(0); 21 | }); 22 | 23 | port.on('data', function(byte){ 24 | var data = byte.toString('hex').match(/.{1,2}/g); 25 | readUart(data); 26 | }); 27 | } 28 | 29 | // write.uart("any command"); 30 | // write.setPage(0); 31 | // write.setText("t0", "hey"); 32 | // write.setVis("t0", true); 33 | // write.getPage(); return actual page on nextion (sendme command) 34 | 35 | var write = { 36 | uart: function(cmd){ 37 | writeUart(cmd); 38 | }, 39 | setPage: function(num){ 40 | writeUart('page '+num); 41 | }, 42 | setText: function(cmp, txt){ 43 | writeUart(cmp+'.txt="'+txt+'"'); 44 | }, 45 | setVis: function(cmp, value){ 46 | var val = value ? "1":"0"; 47 | writeUart('vis '+cmp+','+val); 48 | }, 49 | setColor: function(cmp, bco){ 50 | writeUart(cmp + ".bco=" + bco); 51 | writeUart("ref " + cmp); 52 | }, 53 | getPage: function(){ 54 | writeUart('sendme'); 55 | } 56 | }; 57 | 58 | function writeUart(cmd){ 59 | port.write(hex(cmd)); 60 | } 61 | 62 | function readUart(data){ 63 | console.log(data.join(" ")); 64 | } 65 | 66 | function hex(str) { 67 | var arr = []; 68 | for (var i = 0, l = str.length; i < l; i ++) { 69 | var ascii = str.charCodeAt(i); 70 | arr.push(ascii); 71 | } 72 | arr.push(255); 73 | arr.push(255); 74 | arr.push(255); 75 | return new Buffer(arr); 76 | } 77 | 78 | init(); 79 | -------------------------------------------------------------------------------- /client.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import time 3 | import serial 4 | 5 | ser = serial.Serial( 6 | port='/dev/ttyAMA0', 7 | baudrate = 9600, 8 | parity=serial.PARITY_NONE, 9 | stopbits=serial.STOPBITS_ONE, 10 | bytesize=serial.EIGHTBITS, 11 | timeout=1 12 | ) 13 | 14 | EndCom = "\xff\xff\xff" 15 | ser.write(sys.argv[1]+EndCom) 16 | --------------------------------------------------------------------------------