diff --git a/Nextion_EA5SW/EA5SW_24.HMI b/Nextion_EA5SW/EA5SW_24.HMI new file mode 100644 index 0000000..8b36a6d Binary files /dev/null and b/Nextion_EA5SW/EA5SW_24.HMI differ diff --git a/Nextion_EA5SW/EA5SW_24.tft b/Nextion_EA5SW/EA5SW_24.tft new file mode 100644 index 0000000..fcfa3e2 Binary files /dev/null and b/Nextion_EA5SW/EA5SW_24.tft differ diff --git a/Nextion_EA5SW/EA5SW_32.HMI b/Nextion_EA5SW/EA5SW_32.HMI new file mode 100644 index 0000000..5bb2455 Binary files /dev/null and b/Nextion_EA5SW/EA5SW_32.HMI differ diff --git a/Nextion_EA5SW/EA5SW_32.tft b/Nextion_EA5SW/EA5SW_32.tft new file mode 100644 index 0000000..64d8d17 Binary files /dev/null and b/Nextion_EA5SW/EA5SW_32.tft differ diff --git a/Nextion_EA5SW/EA5SW_35.HMI b/Nextion_EA5SW/EA5SW_35.HMI new file mode 100644 index 0000000..492f8b3 Binary files /dev/null and b/Nextion_EA5SW/EA5SW_35.HMI differ diff --git a/Nextion_EA5SW/EA5SW_35.tft b/Nextion_EA5SW/EA5SW_35.tft new file mode 100644 index 0000000..2bee38f Binary files /dev/null and b/Nextion_EA5SW/EA5SW_35.tft differ diff --git a/Nextion_EA5SW/Nextion_config_files/config_files.md b/Nextion_EA5SW/Nextion_config_files/config_files.md new file mode 100644 index 0000000..821873f --- /dev/null +++ b/Nextion_EA5SW/Nextion_config_files/config_files.md @@ -0,0 +1,6 @@ +info.ini +ctrl.ini +tg.ini +prefixA.ini +prefixB.ini +prefixC.ini diff --git a/Nextion_EA5SW/Nextion_config_files/ctrl.ini b/Nextion_EA5SW/Nextion_config_files/ctrl.ini new file mode 100644 index 0000000..a293bdb --- /dev/null +++ b/Nextion_EA5SW/Nextion_config_files/ctrl.ini @@ -0,0 +1,7 @@ +EA5SW +1 +99998 +99999 +99997 +99996 +99995 diff --git a/Nextion_EA5SW/Nextion_config_files/info.ini b/Nextion_EA5SW/Nextion_config_files/info.ini new file mode 100644 index 0000000..db323af --- /dev/null +++ b/Nextion_EA5SW/Nextion_config_files/info.ini @@ -0,0 +1,4 @@ +EA5SW +Valencia-IM99TK +439.9625 +BrandMeister diff --git a/Nextion_EA5SW/Nextion_config_files/prefixA.ini b/Nextion_EA5SW/Nextion_config_files/prefixA.ini new file mode 100644 index 0000000..fc15613 --- /dev/null +++ b/Nextion_EA5SW/Nextion_config_files/prefixA.ini @@ -0,0 +1,10 @@ +EA0 +EA1 +EA2 +EA3 +EA4 +EA5 +EA6 +EA7 +EA8 +EA9 diff --git a/Nextion_EA5SW/Nextion_config_files/prefixB.ini b/Nextion_EA5SW/Nextion_config_files/prefixB.ini new file mode 100644 index 0000000..ebee10b --- /dev/null +++ b/Nextion_EA5SW/Nextion_config_files/prefixB.ini @@ -0,0 +1,10 @@ +EB0 +EB1 +EB2 +EB3 +EB4 +EB5 +EB6 +EB7 +EB8 +EB9 diff --git a/Nextion_EA5SW/Nextion_config_files/prefixC.ini b/Nextion_EA5SW/Nextion_config_files/prefixC.ini new file mode 100644 index 0000000..9b16885 --- /dev/null +++ b/Nextion_EA5SW/Nextion_config_files/prefixC.ini @@ -0,0 +1,10 @@ +EC0 +EC1 +EC2 +EC3 +EC4 +EC5 +EC6 +EC7 +EC8 +EC9 diff --git a/Nextion_EA5SW/Nextion_config_files/tg.ini b/Nextion_EA5SW/Nextion_config_files/tg.ini new file mode 100644 index 0000000..b849dc0 --- /dev/null +++ b/Nextion_EA5SW/Nextion_config_files/tg.ini @@ -0,0 +1,131 @@ +214 +2141 +2142 +2143 +2144 +2145 +2146 +2147 +2148 +2149 +214112 +21401 +21402 +21403 +21404 +21405 +21406 +21407 +21408 +21409 +21410 +21411 +21412 +21413 +21414 +21415 +21416 +21417 +21418 +21419 +21420 +21421 +21422 +21423 +21424 +21425 +21426 +21427 +21428 +21429 +21430 +21431 +21432 +21433 +21434 +21435 +21436 +21437 +21438 +21439 +21440 +21441 +21442 +21443 +21444 +21445 +21446 +21447 +21448 +21449 +21450 +21451 +21452 +91 +92 +914 +202 +204 +206 +208 +213 +216 +219 +220 +222 +226 +228 +230 +231 +232 +234 +240 +242 +244 +250 +254 +255 +260 +262 +268 +272 +294 +297 +302 +310 +330 +334 +425 +441 +450 +460 +466 +502 +505 +515 +530 +655 +712 +714 +724 +730 +732 +734 +748 +2701 +4540 +5351 +5371 +005 +005 +005 +TGP121=005 +TGP122=005 +TGP123=005 +TGP124=005 +TGP125=005 +TGP126=005 +TGP127=005 +TGP128=005 +TGP129=005 +TGP130=005 diff --git a/Nextion_EA5SW/Nextion_files.md b/Nextion_EA5SW/Nextion_files.md new file mode 100644 index 0000000..8d3553d --- /dev/null +++ b/Nextion_EA5SW/Nextion_files.md @@ -0,0 +1,6 @@ +EA5SW_24.HMI source file for Layout Nextion 2.4 +EA5SW_24.tft compiled file for Layout Nextion 2.4 +EA5SW_32.HMI source file for Layout Nextion 3.2 +EA5SW_32.tft compiled file for Layout Nextion 3.2 +EA5SW_35.HMI source file for Layout Nextion 3.5 +EA5SW_35.tft compiled file for Layout Nextion 3.5 diff --git a/Nextion_EA5SW/README.md b/Nextion_EA5SW/README.md new file mode 100644 index 0000000..f0367f5 --- /dev/null +++ b/Nextion_EA5SW/README.md @@ -0,0 +1,66 @@ +# Update Nextion Displays from the Command Line + +This directory contains a simple python script which you can use to update the +Nextion displays. All you need is a compiled .tft file which is written to the +display's flash memory. The precompiled .tft files with the MMDVMHost default +layout are to be found in this directory as well. + +To update the Nextion display you just need to know the serial port the display +is connected to. It could be /dev/ttyUSBx for USB<->Serial adapters or +/dev/ttyAMA0 for the UART on the Raspberry Pi for example. + +# Prerequisites + +You need to have python installed as well as the python-serial package. That can +normally be found in your distro's package manager. + +# File Naming Convention + +There are compiled .tft files in the repo for basic and enhanced Nextion +displays of sizes 2.4", 2.8", 3.2" and 3.5". Please choose depending on the +model number printed on the back of the display. + +The basic displays are denoted by a "T" as 7th character in the filename and +model number whereas enhanced displays have a "K" in that position. The actual +display size can be derived from the last two digits. The four digits in between +the characters refert to the diplay's resolution. + +For example: A model number NX4832T035 represents a display with: + + - a resolution of 320x480 pixels + - basic command set + - a screen size of 3.5" + +# Updating the Display + +Now comes the easy part. Just execute: + +``` +$ python nextion.py NX4832T035.tft /dev/ttyUSB0 +``` + +And the output should be as follows: + +``` +Trying with baudrate: 2400... +Trying with baudrate: 4800... +Trying with baudrate: 9600... +Connected with baudrate: 9600... +Status: comok +Touchscreen: yes +Model: NX4832T035_011R +Firmware version: 68 +MCU code: 61488 +Serial: D2658880C35D2124 +Flash size: 16777216 +Downloading, 100%... +File transferred successfully +``` + +# Known errors + +Especially when using USB<->Serial adapters there are cases in which the scripts +stops at different times. This is known and due to the very simple update +protocol. In this case you have to fix the display by using a SD-Card to update +the display. The /dev/ttyAMAx ports do not seems to suffer from this issue. + diff --git a/Nextion_EA5SW/nextion.py b/Nextion_EA5SW/nextion.py new file mode 100644 index 0000000..b9e501e --- /dev/null +++ b/Nextion_EA5SW/nextion.py @@ -0,0 +1,136 @@ +''' + * Copyright (C) 2016 Alex Koren + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +''' + +import serial +import time +import sys +import os +import re + +e = "\xff\xff\xff" + +def getBaudrate(ser, fSize=None, checkModel=None): + for baudrate in (2400, 4800, 9600, 19200, 38400, 57600, 115200): + ser.baudrate = baudrate + ser.timeout = 3000 / baudrate + .2 + print 'Trying with baudrate: ' + str(baudrate) + '...' + ser.write("\xff\xff\xff") + ser.write('connect') + ser.write("\xff\xff\xff") + r = ser.read(128) + if 'comok' in r: + print 'Connected with baudrate: ' + str(baudrate) + '...' + noConnect = False + status, unknown1, model, fwversion, mcucode, serial, flashSize = r.strip("\xff\x00").split(',') + print 'Status: ' + status.split(' ')[0] + if status.split(' ')[1] == "1": + print 'Touchscreen: yes' + else: + print 'Touchscreen: no' + print 'Model: ' + model + print 'Firmware version: ' + fwversion + print 'MCU code: ' + mcucode + print 'Serial: ' + serial + print 'Flash size: ' + flashSize + if fSize and fSize > flashSize: + print 'File too big!' + return False + if checkModel and not checkModel in model: + print 'Wrong Display!' + return False + return True + return False + +def setDownloadBaudrate(ser, fSize, baudrate): + ser.write("") + ser.write("whmi-wri " + str(fSize) + "," + str(baudrate) + ",0" + e) + time.sleep(.05) + ser.baudrate = baudrate + ser.timeout = .5 + r = ser.read(1) + if "\x05" in r: + return True + return False + +def transferFile(ser, filename, fSize): + with open(filename, 'rb') as hmif: + dcount = 0 + while True: + data = hmif.read(4096) + if len(data) == 0: + break + dcount += len(data) + ser.timeout = 5 + ser.write(data) + sys.stdout.write('\rDownloading, %3.1f%%...'% (dcount / float(fSize) * 100.0)) + sys.stdout.flush() + ser.timeout = .5 + time.sleep(.5) + r = ser.read(1) + if "\x05" in r: + continue + else: + print + return False + break + print + return True + +def upload(ser, filename, checkModel=None): + if not getBaudrate(ser, os.path.getsize(filename), checkModel): + print 'Could not find baudrate' + exit(1) + + if not setDownloadBaudrate(ser, os.path.getsize(filename), 115200): + print 'Could not set download baudrate' + exit(1) + + if not transferFile(ser, filename, os.path.getsize(filename)): + print 'Could not transfer file' + exit(1) + + print 'File transferred successfully' + exit(0) + +if __name__ == "__main__": + if len(sys.argv) != 4 and len(sys.argv) != 3: + print 'usage:\npython nextion.py file_to_upload.tft /path/to/dev/ttyDevice [nextion_model_name]\ + \nexample: nextion.py newUI.tft /dev/ttyUSB0 NX3224T024\ + \nnote: model name is optional' + exit(1) + + try: + ser = serial.Serial(sys.argv[2], 9600, timeout=5) + except serial.serialutil.SerialException: + print 'could not open serial device ' + sys.argv[2] + exit(1) + if serial.VERSION <= "3.0": + if not ser.isOpen(): + ser.open() + else: + if not ser.is_open: + ser.open() + + checkModel = None + if len(sys.argv) == 4: + checkModel = sys.argv[3] + pattern = re.compile("^NX\d{4}[TK]\d{3}$") + if not pattern.match(checkModel): + print 'Invalid model name. Please give a correct one (e.g. NX3224T024)' + exit(1) + upload(ser, sys.argv[1], checkModel)