Nextion - setText won't work, buttons are OK

I have a basic display (NX4832T035_011) and so far got a very simple screen with a button and a text on it.

When the button is clicked I turn a led on for 2 seconds, on release event, works fine.

As far as of the text component, I can't get the setText to actually change the text, I tried all possible
setups of the text field in the designer, local, global, etc, etc. Did a google search and tried all ways you
can imagine of converting a string or number to a char array and pass it over to setText, the bloody
doesn't do anything, no errors or compilation warnings, the text simply won't change.

Running on an Arduino Nano, button event with LED turning ON perfectly, just text won't set:

#include "Nextion.h"
SoftwareSerial HMISerial(0,1);

int LEDPIN = 13;
char buffer[100] = {0};

NexButton b0 = NexButton(0, 1, "b0");
NexText t0 = NexText(0, 2, "t0");

NexTouch *nex_listen_list[] = 
{
  &b0,
  NULL
};

void setup() 
{  
  Serial.begin(9600);
  Serial.println("INIT 9600");
  delay(500);
  
  nexInit();
  b0.attachPop(b0PopCallback, &b0);
  
  pinMode(LEDPIN, OUTPUT);
  Serial.print("Loaded");
}

void loop() {
  nexLoop(nex_listen_list);
}

void b0PopCallback(void *ptr)
{
  Serial.println("b0PopCallback");
  
  //Blink
  digitalWrite(LEDPIN, HIGH);
  delay(500);
  digitalWrite(LEDPIN, LOW);
  delay(500);  

  dtostrf(45, 6, 2, buffer);
  
  //Doesn't do anything
  t0.setText(buffer);

  //Doesn't do anything
  t0.setText("50");

  //Doesn't do anything
  t0.setText(50);

  //Doesn't do anything
  t0.setText("Test");

  //Doesn't do anything
  String Msg = "HI";  
  Msg.toCharArray(buffer, 5);
  t0.setText(buffer);
}

Screen attached.

Screen_HMI.zip (3.85 KB)

Nextion003.ino (1012 Bytes)

Hi Paul,

Have a look at https://forum.arduino.cc/index.php?topic=582484.0 , https://forum.arduino.cc/index.php?topic=584540.msg3981861#msg3981861 , https://forum.arduino.cc/index.php?topic=583002.msg3989520#msg3989520

And see if any of that helps.

I have 3 finished Nextion projects and a 4th in development. None of them use any libraries as I didn't like the look of the libaries I found and anyway, Nextion isn't that hard to drive.

Good luck,
Perry

PerryBebbington:
Hi Paul,

Have a look at https://forum.arduino.cc/index.php?topic=582484.0 , https://forum.arduino.cc/index.php?topic=584540.msg3981861#msg3981861 , https://forum.arduino.cc/index.php?topic=583002.msg3989520#msg3989520

And see if any of that helps.

I have 3 finished Nextion projects and a 4th in development. None of them use any libraries as I didn't like the look of the libaries I found and anyway, Nextion isn't that hard to drive.

Good luck,
Perry

That looks pretty neat, do I need any special setup on the serial code above? I tried this:

 Serial.print("t0.txt=\"eric\"");
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);

and it just outputs to the serial monitor without updating the text in the screen:

t0.txt="eric"⸮⸮⸮

Hi Paul,
If it's sending it to the serial monitor then you are sending to the wrong serial port. This is where my knowledge of Arduino gets a bit shaky. I don't have a Nano, so I can't try it on one, but you are sending to 2 serial ports, one for the serial monitor and one for the Nextion. If you are seeing on the serial monitor what should be on the Nextion then you are sending to the wrong one. I'm afraid you'll have to play as I don't know the correct one, but maybe Serial1.write etc. Don't know. Play and see what happens, you can't break it.

PerryBebbington:
Hi Paul,
If it's sending it to the serial monitor then you are sending to the wrong serial port. This is where my knowledge of Arduino gets a bit shaky. I don't have a Nano, so I can't try it on one, but you are sending to 2 serial ports, one for the serial monitor and one for the Nextion. If you are seeing on the serial monitor what should be on the Nextion then you are sending to the wrong one. I'm afraid you'll have to play as I don't know the correct one, but maybe Serial1.write etc. Don't know. Play and see what happens, you can't break it.

I ended up using the ITEAD library and this command which I figured after checking their source code:

sendCommand("t0.txt=\"eric\"");

I also noticed that if I use Serial.print right before sendCommand then sendCommand will not work, Serial.print has to be after.

Thanks Perry!

Glad to help Paul :slight_smile: