ESP32 with Nextion display

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
stijns
Posts: 3
Joined: Tue Feb 20, 2018 10:40 am

ESP32 with Nextion display

Post by stijns » Tue Feb 20, 2018 10:47 am

Hello,

I'm new to micropython and I'm having some problems with my Nextion Display connected to my ESP32.
I already connected a BME280 sensor to the ESP32. From this sensor I'm able to read the values. I want to display these values on my Nextion Display.
The RX port of the display is connected to the TXD0 port of the ESP32.
I use the following code to connect to the display:

uart = UART(1, 9600)
uart.init(9600, bits=8, parity=None, stop=1, timeout=1000)
uart.write('temperature.txt=20')
uart.write('\xFF')
uart.write('\xFF')
uart.write('\xFF')

But nothing is happening. Any ideas? Maybe someone with experience with the nextion display and micropython?
I'm probably missing something simple, but I can't seem to find it.
Thanks in advance for the help.

Stijn

loboris
Posts: 318
Joined: Fri Oct 02, 2015 6:19 pm

Re: ESP32 with Nextion display

Post by loboris » Tue Feb 20, 2018 4:44 pm

Have you uploaded your HMI project to the Nextion display?
I don't think the uart.write("temperature.txt=20\xFF\xFF\xFF") will produce an output on the display.

You can test first on your PC, if it works, it will work with MicroPython too.

Nextion Editor Quick Start Guide
Nextion Instruction Set

stijns
Posts: 3
Joined: Tue Feb 20, 2018 10:40 am

Re: ESP32 with Nextion display

Post by stijns » Wed Feb 21, 2018 7:52 am

Yes, the HMI is uploaded to the Nextion display with an SD-card.

I'm now testing this by connecting the ESP32 to my pc and executing this code. But the display doesn't change.
If I debug the nextion with the nextion editor. And I execute this to the simulator it works. To the COM device (my ESP32, it doesn't work)

loboris
Posts: 318
Joined: Fri Oct 02, 2015 6:19 pm

Re: ESP32 with Nextion display

Post by loboris » Thu Feb 22, 2018 10:41 am

I've tested it, and it works as expected.
Here is the simple example code:

Code: Select all

>>> import machine
>>> uart=machine.UART(1,tx=25,rx=26,baudrate=9600)

>>> end_cmd=b'\xFF\xFF\xFF'

>>> def send(cmd):
...     uart.write(cmd)
...     uart.write(end_cmd)
...     time.sleep_ms(100)
...     print("Response:", uart.read())
... 

>>> send("get 65")
Response: b'qA\x00\x00\x00\xff\xff\xff'
>>> send('get "123"')
Response: b'p123\xff\xff\xff'
>>> send('get "Returned string"')
Response: b'pReturned string\xff\xff\xff'

>>> send("page 1")
Response: b'\x01\xff\xff\xff'
>>> send("sendme")
Response: b'f\x01\xff\xff\xff'
>>> send("page 2")
Response: b'\x01\xff\xff\xff'
>>> send("sendme")
Response: b'f\x02\xff\xff\xff'
Use the bytearray for the end command sequence.

Tested with my MicroPython port.

stijns
Posts: 3
Joined: Tue Feb 20, 2018 10:40 am

Re: ESP32 with Nextion display

Post by stijns » Tue Feb 27, 2018 7:24 am

Thanks. But I decided to use arduino and not micropython.

robbyatbln
Posts: 3
Joined: Tue Mar 13, 2018 7:36 pm

Re: ESP32 with Nextion display

Post by robbyatbln » Sat Jul 28, 2018 6:10 am

[quote=loboris post_id=25654 time=1519296117 user_id=923]
I've tested it, and it works as expected.
Here is the simple example code:

[code]>>> import machine
>>> uart=machine.UART(1,tx=25,rx=26,baudrate=9600)

>>> end_cmd=b'\xFF\xFF\xFF'

>>> def send(cmd):
... uart.write(cmd)
... uart.write(end_cmd)
... time.sleep_ms(100)
... print("Response:", uart.read())
...

>>> send("get 65")
Response: b'qA\x00\x00\x00\xff\xff\xff'
>>> send('get "123"')
Response: b'p123\xff\xff\xff'
>>> send('get "Returned string"')
Response: b'pReturned string\xff\xff\xff'

>>> send("page 1")
Response: b'\x01\xff\xff\xff'
>>> send("sendme")
Response: b'f\x01\xff\xff\xff'
>>> send("page 2")
Response: b'\x01\xff\xff\xff'
>>> send("sendme")
Response: b'f\x02\xff\xff\xff'
[/code]
Use the [b]bytearray[/b] for the end command sequence.

Tested with [url=https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo]my MicroPython port[/url].
[/quote]

Hey did it work with a wemos d1 mini? It freeze by my try?!

scls19fr
Posts: 1
Joined: Mon Sep 10, 2018 7:02 pm

Re: ESP32 with Nextion display

Post by scls19fr » Mon Sep 10, 2018 8:34 pm

On my side

[code]
MicroPython v1.9.3 on 2017-11-01; PYBv1.1 with STM32F405RG
Type "help()" for more information.
>>> import machine
>>> uart=machine.UART(1,tx=25,rx=26,baudrate=9600)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: extra keyword arguments given
[/code]

Maybe my firmware is too old?
What is your firmware version?

Post Reply