Start a new topic

Arduino Mega, no text on t0


 anything I do, I cannot read text on t0  Nextion,

if I change serial port to Serial 1 and there I have usb 2 RS232 adapter I can read the text with putty, so is the "t0" problem, I not declare it well or something missing, please some tips or help, to finish my project


#include "Nextion.h"

NexText t0 = NexText(0, 1, "t0");
char buffer[20] = {0};

const byte numChars = 18;
char receivedChars[numChars];

boolean newData = false;

void setup() {
  // initialize serial ports:
  Serial.begin(9600);   // USB 
  Serial2.begin(9600);  //Nextion display
//  Serial3.begin(9600);


  dbSerialPrintln("setup done");
  t0.getText(buffer, sizeof(buffer));

void loop() {

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx =0;
    char startMarker ='FF FF FF 32';
    char endMarker ='FD';
    char rc;
 // if (Serial.available() > 0) {
    while (Serial.available() > 0 && newData == false) {
        rc =;

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                if (ndx >= numChars) {
                    ndx = numChars;
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;

        else if (rc == startMarker) {
            recvInProgress = true;         

void showNewData() {


    if (newData == true) {
        Serial2.print("FX =");
        newData = false;

        //   read from port 1, send to port 0:
     if (Serial2.available())
    int inByte =;



 Thank you !


To print to a different text box, just change the address in the print statements.




If you need different information going to different text box, we need to code a function to do that.

Please let me know your requirements.

1 person likes this
my fist code was modified in according with Steve code and is working, with arduino and ftdi, later I try with display
 My appetite for work is returned :)


your sketch is very good, tested with FTDI now and it seems to work. Now

I can not wait to arrive at home to test it on display, but I'm sure is work. In the first phase not working, also now when I tested, because on SoftwareSerial.cpp pin-outs it was on 11 and 13, not  11 and 10.
 Now if I have two text fields how can to print on t1 box ? That I don't understand, how can be selected to print to one or another field..


I intend to connect Nextion to a hardware serial port, but for testing is good also software.

My board is Funduino Mega and have enough serial ports for that.

 Now I hope to adapt the Steve sketch to mine, what is in first post, to eliminate the string what is not need it.

  Thank you Friends for your precious time taken with my stuff

@ Patrick, font is algerian ,not related but I liked too :)

Oh, that last response was meant for Patrick! haha sorry.


Is your Nextion connected to a hardware serial port or are you actually using a SoftwareSerial port?

Which Arduino are you using?  Is it an actual Arduino, a clone, or a different design which is like Arduino?

I use the Moteino hardware mostly and have found the SoftwareSerial does not function as expected so am forced to use only hardware serial ports.

1 person likes this


To test your set up, run two terminals before you connect Nextion simulator. 


1 person likes this

Hey Alex,

Sorry for delayed response.  Have been super busy at work and my own project.

No need for me to test the software clock on non-rtc model.  That is how I display a clock in my Nextion code.  Other hardware in my project has an RTC so my Nextion requests a time sync (update) from the MCU every hour (whenever the software clock changes it's hour counter). During testing I had the Nex request the update every minute, where I often, but not always, saw the Nex would gain a couple seconds every minute.  That's right, I said gain time.  This, of course, isn't expected to occur in a software clock unless the ms clock runs fast!  I suppose it would occur if a device is overclocked and not compensated for in the ms clock.

My clock timers (one on each page) runs at various times.  Such as page 0 tim=500, page 1 tim=250, page 7 tim=750, etc.  This, of course, is expected to introduce different time creep (+ or -) for each page... not to mention the differences in code executed during and between each clock timer execution.  Page changes will also affect time creep.  I do compensate for differences in clock timer tim values but have no way to compensate for code execution time or amount of time it takes to change to a different page.


Do you have a Usb to Serial adaptor (FTDI or similar) that you can use to reproduce my examples.

Just connect to the Arduino pins 10 and 11, then run the connection in Nextion Debug simulator.

Nice Font too :)

Nothing wrong with the HMI,


1 person likes this

Maybe I missed something, I thought it was the Arduino sketch that needed to be figured out.

Gone back to re-read

Okay - so I am going to have you empty your sketch to just send text to t0 on the Nextion.

If it works, we build up from there.


#include "Nextion.h"

NexText t0 = NexText(0, 1, "t0");
char buffer[20] = {0};

void setup() {
  // initialize serial ports:
  Serial.begin(9600);   // USB 
  Serial2.begin(9600);  //Nextion display
  sendCommand("t0.txt=\"Earth to Nextion\"");
void loop() {



Results are in,

Please open the image as large as practical, you can then see all the settings


1 person likes this

I don't have mine hooked up to esp wifi yet, but my 10 liner on the 3.2" with keyboard. (no buffer)


1 person likes this


As a side note, my current project has a full 10 line vertical scrolling 'Serial Terminal' in the design.

Using some nifty text manipulation the output looks like this on the Nextion.


1 person likes this

Patrick, I tried so many an I don't know now what to send it.  :)

 HMI is simple, one page one text box
 I tested also live on display and on simulator when I not have the display on me.

(133 KB)
Login or Signup to post a comment