Teensy 4.1 Serial RX/TX Send & Receive with Nextion Display

Peterschnecke

New member
Hi everyone,

I've got a problem, trying to get my Teensy 4.1 and my Nextion NX8048K070-011C Display to communicate.

The Nextion Display gets programmed with a GUI. In this GUI is a debug Mode, that virtualizes the Display on the PC. This virtual Display can use the USB-Serial Port of the Teensy to communicate with it.
The virtual software display can communicate flawlessly with the Teensy via the USB serial interface.

But when I try to use the actual hardware display, the serial communication between display and Teensy does not work.

The display is powered by a USB powerbank with 5V.
The TX and RX are connected to port 0 and 1 with Serial1 or to 7 and 8 with Serial2.

If I'm not mistaken both the Display and the Teensy use 3,3V on the Serial Connection
Nextion.PNG
https://nextion.tech/datasheets/nx8048k070/#6

Code:
String BefehlENDE = String (char(0xff)) + String (char(0xff)) + String (char(0xff));       // This is the "EndOfCommand" so that the Display knows the Command ended
char Befehl;                                                                                                     // Variable that takes the Display input
#define HWSERIAL Serial2                                                                                   // Serial=SoftwareUSB  Serial1=Pin0&1  Serial2=7&8



void setup() {
  HWSERIAL.begin(9600);                       // Serial with 9600 Baud
  }

void loop() {
 while(HWSERIAL.available() < 1){}         
  Befehl = HWSERIAL.read();
 if( Befehl == 'A')
 {
  HWSERIAL.print("AusgabeTXT.txt=\"AN\"");         //If Display sends an 'A' , Send Command to print "AN" in the Textbox
  HWSERIAL.print(BefehlENDE);
 }
  if( Befehl == 'U')
 {
  HWSERIAL.print("AusgabeTXT.txt=\"AUS\"");       //If Display sends an 'U' , Send Command to print "AUS" in the Textbox
  HWSERIAL.print(BefehlENDE);
 }
  if( Befehl == 'N')
 {
  HWSERIAL.print("ZahlIN.val=0");                       //If Display sends an 'N' , Send Command to set the Number variable to 0
  HWSERIAL.print(BefehlENDE);
 }
  if( Befehl == '5')
 {
  HWSERIAL.print("ZahlIN.val=ZahlIN.val+5");        //If Display sends an 5 , Send Command to add +5 to the Number variable
  HWSERIAL.print(BefehlENDE);
 }
 }

I guess it is some kind of Hardware Problem, as it works when it's virtualized and uses the USB-Serial of the Teensy?


Thanks in advance
 
I have written a library to communicate with the Nextion.
It has most of the I/O conditions covered but is in reality a skeleton Library which is intended to be expanded by the user.
You can see it here, In includes an example .ino file and an .hmi file.
 
Thank you for your reply. The Library looks great.

I also figured out my Problem, like stated, it worked in the simulation, but not on the actual device.
I simply misplaced the common ground on the breadboard. Stupid user error. Reconnected the common ground and everything worked.
 
The Library looks great.
Thanks for that, I was trying to make it as flexible as possible and also easy to use.
I simply misplaced the common ground on the breadboard.
I did a similar thing in the past! Was spending so much time and attention at RX/TX orientation that I completely forgot about the earth return. What made investigation frustrating was that it would work, but intermittently, returning good then bad then good etc.
 
Back
Top