This library could help you control you nextion-display over UART.
First, define an object with the class nextion(tx_pin, rx_pin, baudrate)
This could look like this now:
from nextion import nextion
display = nextion(13, 12, 9600)
Now you can control the device with different commands.
nextion.WRITE_ONLYnextion.READ_AND_WRITEnextion.DECODEnextion.RAW
You can send a command over serial to the device using display.cmd(command[ , flags=nextion.READ_AND_WRITE])`
command: Required. The command to send to the deviceflags: Optional. You can insertnextion.WRITE_ONLY, when you don't want to read the reply from UART. By default, the function is waiting 100 ms and then, the function returns the reply. Default isnextion.READ_AND_WRITE.
To enter or exit sleep mode of the nextion device, use the command display.sleep(state)
state: Required. Set the parameter to 1 for enter sleep mode. Set the parameter to 0 for exit sleep mode.
To load a page on the nextion device, use the command display.page(pageid)
pageid: Required. ID of the page or name of the page.
You can reset the device using the command display.reset()
To set the display brightness use the command display.brightness(brightness)
brightness: Required. Brightness to set in percent
You can read bytes from serial with the command display.read([flags=nextion.RAW])
flags: Optional. You can set theflagsparameter tonextion.DECODE, if you want the function to decode the output of the displays. If you don't want to have the data ASCII encoded, you can insertnextion.RAW. Default isnextion.RAW.
Note that this returns None if nothing is there to be read.