Start a new topic

Button usage.

I am using a dual state button with

"message == "70 nodered~togbt1=0"


"message == "70 nodered~togbt1=1"

from my nextion to trigger my stepper (Start, Stop), but it just skips the "if" and "while". Am I using the nextion message correctly?

 Below is my Arduino code. Could anyone offer any advice.

    Serial.println("Program #2, Double coil steps");
    mystepper2->step(100, FORWARD, DOUBLE);

 if (message == "70 nodered~togbt1=0");
} while (message == "70 nodered~togbt1=1");   


Iteadlib Arduino Nextion Library has no such "message"

True, but it builds one with this from the "Touch Press Event" in my nextion editor.

//Restrict All Buttons//
  tsw bt2,0
  tsw b0,0
  tsw b2,0
  tsw bt2,1
  tsw b0,1
  tsw b2,1
//Button Output
printh 70
print "nodered~togbt0="
  print "0"
  print "1"
printh ff ff ff


Would this "touch press event" work in a "While" statement? I see it is a Dual-State button I am using, but it appears the message is only momentary?  If I am way off, please correct me.

Thank you.

So, your button press builds a Nextion command to ...

   update another Nextion?

My button press builds a Nextion command to send the "70 nodered~togbt1=0" message to an Arduino.

In the "void loop()" the Arduino in tern listens to any command from the Nextion by means of...

       String message = myNextion.listen();


Thank you again.

Okay, so why build a Nextion command to an Arduino

Nextion command is perhaps only useful for a Nextion, no?

Well, with this method I am able to get my nextion to turn on and off LED's and relays as well as turn ON (Not OFF yet)  steppers when attached to an Arduino. Specifically with a Dual-State button.

If I am over complicating it and there is a FAR simpler way then I missed it.

Thank you

Perhaps over complicating it.

Iteadlib Arduino Nextion Library listens for the Send Component ID 0x65 Nextion Return Data.


// Iteadlib Arduino Nextion Library v0.9.0

#include <Arduino.h>
#include "Nextion.h" // Iteadlib v0.9.0

int dual0; // shadow dualstate value;

// NexComponent localname = NexComponent(pageno,.id, .objname);
NexDualStateButton  mydualstate = NexDualStateButton(0,1,"bt0");

NexTouch *nex_listen_list[] = {
   mydualstate, NULL

void myfunction (void *ptr) {
  dual0 = 1 - dual0;
  if (dual0 == 0) {
    // set pin LOW
  } else {
    // set pin HIGH

void setup(void) {
  dual0 = 0;

void loop(void) {


Ok, that will take me a while to absorb. So, I will study this.  I'll be in touch once I understand that better.

Thank you again for the help!

There are many examples in the Iteadlib Arduino Nextion Library examples folder

Login or Signup to post a comment