I have tested several python codes to set up the communication between raspberry pi and nextion touch screen (I used TTL serial GPIO 14 and 15). Unfortunately, the communication is not stable, the manufacturer of this screen provides several libraries for C++, but there is not much support for python. I want to know if there is anyone who has used this screen with the raspberry pi and gets stable communication using python?
This is what I use in Python3 on Raspberry PI4 and Nextion 10" display.
port = serial.Serial( port='/dev/ttyUSB0', baudrate =9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1)
Also important to use correct EOF [End of File] you need three after each "write" e.g.,
eof = struct.pack('B', 0xff) port.write("page 0".encode()) port.write(eof) port.write(eof) port.write(eof)