Nextion Display

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
Posts: 8
Joined: Thu Apr 01, 2021 11:47 am

Nextion Display

Post by » Thu Apr 01, 2021 12:54 pm

I want a Nextion display with the Pico operate and have already found a good lib. ...

Sending commands to the Nextion also works great.
But what I can't do at all is the callback method.

Code: Select all

My code:

import machine
import utime
import nextion
n = nextion.Nextion(1)
def nextion_callback(command, page, id, touch_event):
    print('command: %s page: %s id: %s, touch_event: %s' % (command, page, id, touch_event))
    x1= ('command: %s' % (command))
while True:
    print("Läuft noch")
When I press a button on my Nextion display, the display sends it:

Code: Select all

#Code in the lib:
def check_data (self, callback):
         if self.any ():
             chars = self.readinto (self.read_buffer, 100)
             index = 0
but usually the program in Lib remains with the call:
if self.any (): stand.
Only when I often send commands will I continue to work from time to time.

When I query the content of chars, this is the result:

The correct result is output on my console:
command: 101 page: 1 id: 4, touch_event: 1
From time to time it continues.
but often it depends again on if self.any ():

I'm still a very inexperienced Phyhton newbie, maybe someone can help me.
Maybe also with an improved code:

User avatar
Posts: 2754
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Nextion Display

Post by Roberthh » Thu Apr 01, 2021 2:12 pm

The UART implementation of the PICO is still evolving and different to the standard behavior. Differences:
- uart.any() does not return the number of characters waiting, but just True or False.
- depending on the firmware version, blocking or not. The daily build will not block, but just return the number of bytes present unless you set a timeout. In that case it will at least wait that timeout. That behavior follows the standard build and the documentation. The characters you receive match what you see on the console, since the decimal value of 'e' is 101. So you get the numbers 101 1 4 1, followed by three 255 codes. So it looks like you get the expected 7 response bytes.
Posts: 8
Joined: Thu Apr 01, 2021 11:47 am

Re: Nextion Display

Post by » Thu Apr 01, 2021 3:18 pm

Yes Roberthh,
I get the right answer sometimes.
But most of the time processing stops when the lib is called.
after if self.any ():
And the command:
chars = self.readinto (self.read_buffer, 100)
is no longer executed
Can I let the interruption continue with a call.
Or set the timeout low?
I don't know my way around yet.
How would you enter the command?
Posts: 8
Joined: Thu Apr 01, 2021 11:47 am

Re: Nextion Display

Post by » Thu Apr 01, 2021 5:09 pm

Another riddle?
when I set the buffer to 14.
After the first command from the display, my code stops.
The second command continues my code.
The next time it stops again. etc

(65010401FFFFFF) = length 7
And if I set the (self.read_buffer, 7)
then everything runs through without errors.
The only problem is that the length can change later depending on the situation.

Is there a command how I can query the length sent up to FFFFFF? Without interrupting the UART interface.
I would then insert the length here (self.read_buffer, 7).

Posts: 55
Joined: Thu Apr 29, 2021 9:11 am

Re: Nextion Display

Post by Jackli » Thu May 20, 2021 8:43 am

I think maybe you should consult their aftermarket, I recently bought a new screen similar to the nextion and have completed my first practice project.
Here is the link: viewtopic.php?f=5&t=10537

Post Reply