Hi,
I recently started testing a Nextion TFT display with my pyboard. I am able to send and receive simple instructions through UART(3). A raspberry pi is connected via uos.dupterm(UART(6)) mainly REPL and file transfers. Occasionally new programming -.tft files - need to be uploaded to the display. This can be done easily from the raspberry pi to the display with a USB to TTL adapter using the python code found here: https://github.com/g4klx/MMDVMHost/blob ... nextion.py. However, it would be nice to avoid all the plugging and unplugging and use a uart to uart pass through instead. There is an example of USB to UART pass through here: https://docs.micropython.org/en/latest/ ... rough.html
Not sure how to tailor this to my needs. Any advice will be appreciated - with examples even more so.
Thanks all.
Pyboard - UART to UART pass through for Nextion
Re: Pyboard - UART to UART pass through for Nextion
You shouldn't need to change the past thru function at all.
Just open a UART rather than USB.
Just open a UART rather than USB.
Re: Pyboard - UART to UART pass through for Nextion
I have exchanged USB for UART as suggested. I am able to send and receive simple messages - like set display brightness or get buttons pressed. My excitement was short lived however. When I try to upload .tft file things hang very quickly.
Output:
Pyboard firmware:
My Pyboard code:
Feels like the timing is off. I suspect me naive rework of the USB to UART pass through example is faulty.
Output:
Code: Select all
pi@raspberrypi:~ $ python /home/pi/DAPLC_PY/Screen/nextion2.py /home/pi/DAPLC_PY/Screen/Controlfreaks-7.tft /dev/ttyUSB1
Trying with baudrate: 9600...
Trying with baudrate: 115200...
Connected with baudrate: 115200...
Status: #���comok
Touchscreen: yes
Model: NX8048T050_011R
Firmware version: 99
MCU code: 61488
Serial: E466A0018F3E3822
Flash size: 167772
Downloading, 0.1%...()
Could not transfer file
pi@raspberrypi:~ $
Code: Select all
MicroPython v1.9.3-558-ga60efa82 on 2018-04-23; PYBv1.1 with STM32F405RG
Code: Select all
import pyb
import select
uart1 = UART(1)
uart1.init(115200, timeout=0)
uart3 = UART(3)
uart3.init(115200, timeout=0)
while True:
select.select([uart1, uart3], [], []) # select line seems to make no difference
if uart3.any():
uart1.write(uart3.read(256))
if uart1.any():
uart3.write(uart1.read(256))
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Pyboard - UART to UART pass through for Nextion
I would try something along these lines (note I haven't actually tested this):
If you want to use uselect I suggest you read this part of the docs. However in this simple example I don't think it brings much to the party.
Code: Select all
import pyb
uart1 = UART(1)
uart1.init(115200, read_buf_len = 256)
uart3 = UART(3)
uart3.init(115200, read_buf_len = 256) # Try higher values if necessary
while True:
nrx = uart3.any() # Count available characters
if nrx:
uart1.write(uart3.read(nrx)) # Only read what's available: it should never time out
nrx = uart1.any()
if nrx:
uart3.write(uart1.read(nrx))
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Pyboard - UART to UART pass through for Nextion
Success - I can now communicate remotely with my Pyboard and Nextion display (ESP8266 controls communications, as well a few i/o pins on Pyboard including reset). The Pyboard can boot up in one of two ways: Dupterm enabled or UART to UART pass through enabled.
When booted into dupterm mode, the Pyboard interacts directly with the TFT display.
All help was appreciated. Many thanks pythoncoder.
Code: Select all
# boot.py -- run on boot-up
# i/o A15 switches boot modes from dupterm to UART6 <> UART3 pass through for screen programming.
import pyb
from pyb import UART
import uos
sp = pyb.Pin('A15', pyb.Pin.IN) # Activate input A15 (red led) connected to ESP8266 i/o 14
pyb.delay(10)
if sp.value() == 1:
uart6 = UART(6)
uart6.init(115200, read_buf_len = 256)
uart3 = UART(3)
uart3.init(115200, read_buf_len = 256) # Try higher values if necessary
while True:
nrx = uart3.any() # Count available characters
if nrx:
uart6.write(uart3.read(nrx)) # Only read what's available: it should never time out
nrx = uart6.any()
if nrx:
uart3.write(uart6.read(nrx))
else:
uart6 = UART(6)
uart6.init(115200)
uos.dupterm(uart6) # duplicate repl on UART(6)
pyb.main('main.py') # main script to run after this one
pyb.usb_mode('CDC') # act as a serial (CDC) and not a storage device (MSC)
All help was appreciated. Many thanks pythoncoder.