Serial communication Nextion

#include <WhandallSerial.h>  // https://github.com/whandall/WhandallSerial

// simple handler just prints some infos about the received line

void processLine(const char* buf) {
  Serial.print(F("len = "));
  Serial.print((uint8_t)buf[-1]);
  Serial.print(F(", strlen = "));
  Serial.println(strlen(buf));
  Serial.println(buf);
}

SSerial nextionSerial(Serial1, processLine); // used serial and handler

void setup() {
  Serial.begin(115200);
  Serial1.begin(9600);
  nextionSerial.begin(64, optTripleFF); // buffer size and options, maybe +optKeepDlm
}

void loop() {
  nextionSerial.loop();    // collect chars and call handler for each line
}

But that does not work with SoftwareSerial.

1 Like