Issue with Nextion DSButton combined with SetValue

I am working on a project to monitor and control some things for my motorhome.
I am using an Arduino Mega 2560 and a Nextion NX4827P043-011C-Y 4.3 Inch Resistive Touch Screen.
I now have a problem that if I combine some DSButton functions (to read push buttons on the Nextion) and some Setvalue functions for (Progress bars) and/or SetValue functions (to change values on the display.

The DSbuttons work fine when I don’t use the SetValue fucnties.
The Setvalue functions work fine if I don’t use the DS Buttons.
If I combine the code then the DSButton no longer work.

Anyone have an idea what could be causing this problem and how I can fix it?

The relevant part of the programme:

NexText tT1Header = NexText(1, 11, “tT1Header”);
NexDSButton bT1 = NexDSButton(1, 13, “bT1”);
NexProgressBar jTank1Level = NexProgressBar(1, 3, “jTank1Level”);
NexText tTank1 = NexText(1, 6,“tTank1”);

NexText tT2Header = NexText(1, 12, “tT2Header”);
NexDSButton bT2 = NexDSButton(1, 14, “bT2”);
NexProgressBar jTank2Level = NexProgressBar(1, 4, “jTank2Level”);
NexText tTank2 = NexText(1, 7,“tTank2”);

NexText tTimer = NexText(1, 9, “tTimer”);
NexText t1 = NexText(1, 10, “t1”);

NexText tT3Header = NexText(2, 10, “tT3Header”);
NexDSButton bT3 = NexDSButton(2, 9, “bT3”);
NexProgressBar jTank3Level = NexProgressBar(2, 3, “jTank3Level”);
NexText tTank3 = NexText(2, 6,“tTank3”);

NexText tBoilerHeader = NexText(2, 12, “tBoilerHeader”);
NexDSButton bT4 = NexDSButton(2, 11, “bT4”);
NexProgressBar jBoilerTemp = NexProgressBar(2, 5, “jBoilerTemp”);
NexText tBoilerTemp = NexText(2, 7, “tBoilerTemp”);

char bufferT1[100] = {0};
char bufferT2[100] = {0};
char bufferT3[100] = {0};
char bufferT4[100] = {0};

  • Register a dual state button object to the touch event list.
    NexTouch nex_listen_list[] =


  • Dual state button component pop callback function.

  • In this example,the button’s text value will plus one every time when it is released.
    void bT1PopCallback(void *ptr)
    uint32_t dual_state;
    NexDSButton *btn = (NexDSButton *)ptr;
    memset(bufferT1, 0, sizeof(bufferT1));

    /* Get the state value of dual state button component . */
    digitalWrite(led1, HIGH);
    digitalWrite(led2, LOW);
    TankSelect = RELAYT1;
    digitalWrite(RELAYT1, LOW);
    digitalWrite(RELAYT2, HIGH);
    // }
    digitalWrite(led1, LOW);
    digitalWrite(RELAYT1, HIGH);

void setup(void)
/* Set the baudrate which is for debug and communicate with Nextion screen. */

/* Register the pop event callback function of the dual state button component. */
bT1.attachPop(bT1PopCallback, &bT1);
bT2.attachPop(bT2PopCallback, &bT2);
bT3.attachPop(bT3PopCallback, &bT3);
bT4.attachPop(bT4PopCallback, &bT4);
dbSerialPrintln("setup done");

void loop(void)
* When a pop or push event occured every time,
* the corresponding component[right page id and component id] in touch event list will be asked.

// Update Tank1 percentage text and progress bar
jTank1Level.setValue(int(100 * (VolumeT1 / TankinhoudT1)));

Water Douche
Water Keuken