Serial vs Serial1

gonzales

Active member
Hello!
I have some problems with Teensy 4.1. I using Serial1 to communicate with Nextion display, and Serial for debug.
My code is
C++:
HardwareSerial& Touch = Serial1;

FLASHMEM void StartDebug() {
#ifdef MASTERDEBUG
  Serial.begin(256000);
  SerialMode = COMMANDMODE;
#endif
}

FLASHMEM void InitTouch() {
  Touch.begin(9600);
  SendToTouchPercent(0);
}

FLASHMEM void comandEnd() {
  for (int i = 0; i < 3; i++) {
    Touch.write(0xff);
  }
  Touch.flush();
}

FLASHMEM void SendToTouchPercent(byte Percent) {
  Touch.print("page0.inft.txt=\"" + String(Percent) + "%\"");
  comandEnd();
}

My problem is, when Touch.print executed i see what is being sent in Serial monitor, despite the fact that i dont send anything to Serial.
Something like this
Code:
11:00:44.792 -> page0.h1.pic=1���page0.h2.pic=1���page0.m1.pic=0���page0.m2.pic

The display also receives these commands, it's just not clear how they get into Serial. With Teensy 3.5 it work fine
 
Without a complete program to compile/test it is not very easy to see what your problem is.
If it's of any use to you I have written a Library for the Nextion with complete examples and a UTube video.
You can find it here.
 
I tried running your program here on a Teensy 4.0. Because your code is incomplete, I added these to get it to compile:

Code:
void setup() {
  InitTouch();
}

void loop() {
  SendToTouchPercent(50);
  delay(100);
}

It is printing nothing to the Arduino Serial Monitor.

Here is the waveform my oscilloscope sees on pin 1 (TX1):

file.png



This is the complete program I ran for this test.

Code:
HardwareSerial& Touch = Serial1;

FLASHMEM void StartDebug() {
#ifdef MASTERDEBUG
  Serial.begin(256000);
  SerialMode = COMMANDMODE;
#endif
}

FLASHMEM void InitTouch() {
  Touch.begin(9600);
  SendToTouchPercent(0);
}

FLASHMEM void comandEnd() {
  for (int i = 0; i < 3; i++) {
    Touch.write(0xff);
  }
  Touch.flush();
}

FLASHMEM void SendToTouchPercent(byte Percent) {
  Touch.print("page0.inft.txt=\"" + String(Percent) + "%\"");
  comandEnd();
}

void setup() {
  InitTouch();
}

void loop() {
  SendToTouchPercent(50);
  delay(100);
}
 
Hmm, very interesting!
this is a piece of code showing an error on my Mother-board (Teensy soldered on an additional board)
Code:
HardwareSerial& Touch = Serial1;

unsigned long OneMinuteTimer;

FLASHMEM void StartDebug() {
#ifdef MASTERDEBUG
  Serial.begin(256000);
  SerialMode = COMMANDMODE;
#endif
}

FLASHMEM void InitTouch() {
  Touch.begin(9600);
  SendToTouchPercent(0);
}

FLASHMEM void comandEnd() {
  for (int i = 0; i < 3; i++) {
    Touch.write(0xff);
  }
  Touch.flush();
}

FLASHMEM void SendToTouchPercent(byte Percent) {
  Touch.print("page0.inft.txt=\"" + String(Percent) + "%\"");
  comandEnd();
  Serial.println("SendToTouchPercent");
}


FLASHMEM void CheckTouch() {
  int i = 0;
  char Touchbuffer[100];
  char typestring[10];
  char valuestring[20];
  if (Touch.available()) {
    delay(100);
    while (Touch.available() && i < 99) {
      Touchbuffer[i++] = Touch.read();
    }
    Touchbuffer[i++] = '\0';
    Serial.println(Touchbuffer);
  }
}

void setup() {
  StartDebug();
  delay(2000);
  Serial.println("START");
  InitTouch();
}

void loop() {
  if (millis() - OneMinuteTimer > 1000) {
    OneMinuteTimer = millis();
    SendToTouchPercent(50);
  }
  CheckTouch();
 
}
In serial monitor i see
Code:
17:01:19.012 -> page0.inft.txt="50%"���
17:01:19.913 -> SendToTouchPercent
17:01:20.031 -> page0.inft.txt="50%"���
17:01:20.952 -> SendToTouchPercent
17:01:21.031 -> page0.inft.txt="50%"���
17:01:21.957 -> SendToTouchPercent
17:01:22.049 -> page0.inft.txt="50%"���
17:01:22.955 -> SendToTouchPercent
17:01:23.047 -> page0.inft.txt="50%"���
17:01:23.940 -> SendToTouchPercent
17:01:24.033 -> page0.inft.txt="50%"���

But on clean Teensy (without Mother-board) this code work fine. It turns out that the problem is mine Mother-board....
 
Back
Top