I am new Raspberry, ...
I want to use a Nextion-Display communicate over the UART pins, ...
Well, for Rpi UART newbies I highly recommend using python. If you don't insist on C++, you might like to read some of my old posts on Rpi serial.
I check that Nextion instruction is simple:
1. All instructions over serial: are terminated with three bytes of 0xFF 0xFF 0xFF
2. All instructions and parameters are in ASCII
3. All instructions are in lowercase letters
I don't understand what you mean below.
I made sure that the start sequence of the pi is not showing up over TX.
Do you mean that you did not see what you expected to see over Tx? You might like to read my newbie tutorial to first make sure you serial port is working properly.
tlfong01's Rpi UART notes #1 - Serial to Arduino totally non-responsive
tlfong01's Rpi UART notes #2 - Data packet of hex values sent over serial
The test program included in my post is a complete python program. You just copy and paste and off you go, no library necessary :)
References
Nextion Basic HMI Display - Niextion
How to use Nextion with Rpi - Nextion
WireingPi Serial Library - WiringPi
Update 2019apr10hkt2028
I tried my UART delay loop back function with the following call.
serialPortLoopBack(serialPort0, b'wept 30,20\0xff\0xff\0xff\r\n', 32, 0.030)
So the string b'wept ..." is sent over Tx, and after a delay (you set it to Nextion's 5ms) Rx loops back (I shorted Tx to Rx) the same string.
I pasted the complete listing below. You can just copy, paste and run it.
In case you have problem reading my program, here is a penZu backup.
https://penzu.com/p/1fc7a139
# uart_test16 tlfong01 2019apr10hkt2021 ***
# Computer = Rpi3B+
# Linux = $ hostnamectl = raspberrypi Raspbian GNU/Linux 9 (stretch) Linux 4.14.34-v7+ arm
# Python = >>> sys.version = 3.5.3 Jan 19 2017
# Test 1 - repeatWriteBytes() - UART port repeatedly send out bytes.
# Function - Repeat many times sending bytes, pause after each bytes.
# Test 2 - loopBackTest() - UART port send and receive bytes.
# Function - Send one bytes to TX, wait some time (Note 1), then read bytes back from RX.
# Setup - Connect Tx pin to Rx pin to form a loop.
# Test 3 - serialBlinkLed() - blink LED many times
# Function - Send b'(/0xff) many times, then '(/0x00) many times
# Setup - Insert (1k + LED) between Tx and Ground
# Note 1
# Bolutek BlueTooth BC04 needs at least 10mS to respond
from time import sleep
import serial
serialPort0 = serial.Serial(port = '/dev/serial0',
baudrate = 9600,
parity = serial.PARITY_NONE,
stopbits = serial.STOPBITS_ONE,
bytesize = serial.EIGHTBITS,
timeout= 1)
def setSerialPortBaudRate(serialPort, baudrate):
serialPort.baudrate = baudrate
return
def serialPortWriteBytes(serialPort, writeBytes):
serialPort.write(writeBytes)
return
def serialPortReadBytes(serialPort, maxBytesLength):
readBytes = serialPort.read(maxBytesLength)
return readBytes
def serialPortWriteWaitReadBytes(serialPort, writeBytes, maxBytesLength, waitTime):
serialPort.flushInput()
serialPort.flushOutput()
serialPort.write(writeBytes)
sleep(waitTime)
readBytes = serialPortReadBytes(serialPort, maxBytesLength)
print(' bytes written = ', writeBytes)
print(' bytes read = ', readBytes)
return readBytes
def repeatWriteBytes(serialPort, writeBytes, pauseTimeBetweenBytes, repeatCount):
print(' Begin repeatWriteOneByte(), ...')
for i in range(repeatCount):
serialPortWriteBytes(serialPort, writeBytes)
sleep(pauseTimeBetweenBytes)
print(' End repeatWriteBytes().')
return
def serialPortLoopBack(serialPort, writeBytes, maxBytesLength, waitTime):
print(' Begin serialPortLoopBack() [Remember to connect Tx to Rx!] , ...')
serialPortWriteWaitReadBytes(serialPort, writeBytes, maxBytesLength, waitTime)
print(' End serialPortLoopBack(), ...')
return
def serialBlinkLED(serialPort, repeatCount):
print(' Begin serialBlinkLed(), ...')
for i in range(repeatCount):
repeatWriteBytes(serialPort0, b'\xff', 0, 200)
repeatWriteBytes(serialPort0, b'\x00', 0, 200)
print(' End serialBlinkLed().')
return
# *** Main ***
setSerialPortBaudRate(serialPort0, 9600)
#serialBlinkLED(serialPort0, 100)
serialPortLoopBack(serialPort0, b'AT\r\n', 32, 0.030)
serialPortLoopBack(serialPort0, b'wept 30,20\0xff\0xff\0xff\r\n', 32, 0.030)
''' Sample output tlfong01 2019apr10hkt2020
=== RESTART: /home/pi/Python_Programs/test1193/uart_test10_2019apr0901.py ===
Begin serialPortLoopBack() [Remember to connect Tx to Rx!] , ...
bytes written = b'AT\r\n'
bytes read = b'AT\r\n'
End serialPortLoopBack(), ...
Begin serialPortLoopBack() [Remember to connect Tx to Rx!] , ...
bytes written = b'wept 30,20\x00xff\x00xff\x00xff\r\n'
bytes read = b'wept 30,20\x00xff\x00xff\x00xff\r\n'
End serialPortLoopBack(), ...
>>>
'''
# End
One thing I usually remind python UART newbies is to disable serial console, see picture below.