Unofficial Nextion/TJC User Forum

Dual State Button issue when running with Serial.begin

I was trying to implement two dual state buttons to my project and i was able to do it . but when i added Serial.begin function with 57600 baudrate. only bt1 is working and bt0 is not responding. can you please assist me. Thank You in advance

#include "Nextion.h"
int RELAY_LED = 13;
int RELAY_THROTTLE = 12;
NexDSButton bt0 = NexDSButton(1, 4, "bt0");
NexDSButton bt1 = NexDSButton(1, 6, "bt1");

uint32_t dual_state0=0;
uint32_t dual_state1=0;

void setup(){
nexInit();
pinMode(RELAY_LED, OUTPUT);
pinMode(RELAY_THROTTLE, OUTPUT);

}
void loop(){  
bt0.getValue(&dual_state0);
bt1.getValue(&dual_state1);
delay(200);
Serial.begin(57600);
delay(10);


if(dual_state0==1) //When pressed dual state button dual_state0 =1
  {
    digitalWrite(RELAY_THROTTLE, HIGH);
    Serial.println("BIG LED ON");
  }
  else if(dual_state0==0)
  {
    digitalWrite(RELAY_THROTTLE,LOW ); 
    Serial.println("BIG LED OFF");
  }

if(dual_state1==1) //When pressed dual state button dual_state1 =1
  {
    digitalWrite(RELAY_LED, HIGH);
    Serial.println("small LED ON");
  }
  else if(dual_state1==0)
  {
    digitalWrite(RELAY_LED,LOW ); 
    Serial.println("small LED OFF");

  }
}```

Do you have this: bauds=57600 as the first line in your page0 Preinitialization event?

Hi @elf .
Thank for the reply. And yes i do have that initiated in the first page of my Nextion

Try moving Serial.begin to Setup or is there a reason you’re starting it every few milliseconds? You can also try moving the delay to between the two .getValue’s.
Note: Communicating between the mcu and the Nextion is really easy without the Nextion.h library.

1 Like

Thanks for the insights . will try that. @elf

actually moving the serial.begin helped .
thank You @elf :pray:


This forum is in no way affiliated with NEXTION®, ITEAD STUDIO®, TJC®, or anyone else really. All product names, logos, and brands are property of their respective owners. All company, product, and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement from the respective rights holder(s).