Buttons on Nextion not received by controller

Ive been away from esp dev for at least a year. I have a nextion 7inch display with a custom ESP32 board. The issue is that when I press a button, the command does not go to the ESP32. but I do have temp displays that are showing up on the screen. So it seems that the esp can send but not receive. My knowledge tells me that there are 3 things that have to happen to get an ESP/Arduino to listen to the Nextion:

  1. set a serial port for the nextion in NexConfig.h (in this instance it is Serial1
  2. set the list of items to listen to (nex_listen_list)
  3. attach methods to the items in the listen list.

here is my full code:

//#include <ArduinoOTA.h>
//#include <PubSubClient.h>
#include <Adafruit_ADS1015.h>
//#include <TimeLib.h>
#include "Nextion.h"
#include <PID_v1.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//#include <jsonParser.h>
//#include <AWS_IOT.h>
#include <Preferences.h>
#include <WiFi.h>

Preferences preferences;
String wifiSsid;
String wifiPass;
unsigned int isStillPumpEnabled;
unsigned int isHERMSEnabled;
unsigned int isDebugEnabled;
String timezone;

/*
    Control Variables
*/
static int maxCondenserCoolantTempF = 145;
double powerPercentage = 1.0; //1.0 = 100%; 0.25 = 25%
unsigned long lastDutyCycle;
static int dutyCycle;
bool element1Status = false;
bool element2Status = false;
bool pump1Status = false;
bool pump2Status = false;
int dutyTime;
int actualSensorBTemp = 0;
int actualSensorCTemp = 0;
int actualSensorATemp = 0;
unsigned long currentMillis = 0;

/*
   Display Variables
*/
NexDSButton element1Button = NexDSButton(0, 6, "bElement1");
NexDSButton element2Button = NexDSButton(0, 7, "bElement2");
NexDSButton pump1Button = NexDSButton(0, 8, "bPump1");
NexDSButton pump2Button = NexDSButton(0, 9, "bPump2");
NexSlider powerSlider = NexSlider(0, 4, "sliderPower");
NexNumber tempANumber = NexNumber(0, 1, "nTempA");
NexNumber tempBNumber = NexNumber(0, 2, "nTempB");
NexNumber tempCNumber = NexNumber(0, 3, "nTempC");
NexTouch *nex_listen_list[] = {
  &element1Button,
  &element2Button,
  &pump1Button,
  &pump2Button,
  &powerSlider,
  NULL
};

/*
   Ammeter Variables
*/
//Ammeter
char ampDisplay[5];
int adsSampleRate = 5000;
Adafruit_ADS1015 adsLeg1(0x48);
Adafruit_ADS1015 adsLeg2(0x49);
float leg1;
float leg2;
int maxValueLeg1 = 0;
int minValueLeg1 = 0;
int maxValueLeg2 = 0;
int minValueLeg2 = 0;
float multiplier = 0.036;

/*
   Temperature Variables
*/
#define TEMPA_BUS 4
#define TEMPB_BUS 5
#define TEMPC_BUS 23
#define TEMP_PRECISION 9
OneWire oneWireA(TEMPA_BUS);
OneWire oneWireB(TEMPB_BUS);
OneWire oneWireC(TEMPC_BUS);
DallasTemperature sensorA(&oneWireA);
DallasTemperature sensorB(&oneWireB);
DallasTemperature sensorC(&oneWireC);

#define ELEMENT1_CONTACTOR_RELAY 19 //HLT or Still Boiler Element 2
#define ELEMENT2_CONTACTOR_RELAY 18 //Brew Boiler or Still Boiler Element 1
#define PUMP1_RELAY 25 //Main pump or recirculating pump for still
#define PUMP2_RELAY 33 //Herms Pump
#define ERROR_RELAY 15 //Error LED
#define ELEMENT1_SSR_RELAY 14 //HLT or Still
#define ELEMENT2_SSR_RELAY 13 //Boiler 

#define BAUD_RATE 9600

void setup() {
  Serial.begin(BAUD_RATE); //Porgramming
  Serial.println("Programming Port Working");
  Serial1.begin(BAUD_RATE, SERIAL_8N1, 27, 26);
  Serial2.begin(BAUD_RATE, SERIAL_8N1, 17, 16);
  Serial2.println("Display Port Working");
  tempProbesSetup();
  nexSetup();
  Serial.println("Setting Relays to output");

  pinMode(ELEMENT1_CONTACTOR_RELAY, OUTPUT);
  pinMode(ELEMENT2_CONTACTOR_RELAY, OUTPUT);
  pinMode(PUMP1_RELAY, OUTPUT);
  pinMode(PUMP2_RELAY, OUTPUT);
  pinMode(ERROR_RELAY, OUTPUT);
  pinMode(ELEMENT1_SSR_RELAY, OUTPUT);
  pinMode(ELEMENT2_SSR_RELAY, OUTPUT);

  Serial.println("Set Relays to output");

  preferences.begin("BDC", false);
  wifiSsid = preferences.getString("wifissid", "");
  wifiPass = preferences.getString("wifipass", "");
  isStillPumpEnabled = preferences.getInt("pump", 0);
  isHERMSEnabled = preferences.getInt("herms", 0);
  isDebugEnabled = preferences.getInt("debug", 0);
  timezone = preferences.getString("timezone", "-7");
  if (wifiSsid == "" || wifiPass == "") {
    Serial2.println("No values saved for network credentials");
  }
  else {
    // Connect to Wi-Fi
    WiFi.mode(WIFI_STA);
    WiFi.begin(wifiSsid.c_str(), wifiPass.c_str());
    Serial2.print("Connecting to WiFi ..");
    while (WiFi.status() != WL_CONNECTED) {
      Serial.print('.');
      delay(1000);
    }
    Serial2.println(WiFi.localIP());
  }
}

void loop() {
  currentMillis = millis();
  // put your main code here, to run repeatedly:

  sensorC.requestTemperatures();
  sensorB.requestTemperatures();
  sensorA.requestTemperatures();


  if ( sensorC.getTempFByIndex(0) > 0 && sensorC.getTempFByIndex(0) < 212)  actualSensorCTemp = sensorC.getTempFByIndex(0);
  if ( sensorA.getTempFByIndex(0) > 0 && sensorA.getTempFByIndex(0) < 212)  actualSensorATemp = sensorA.getTempFByIndex(0);
  if ( sensorB.getTempFByIndex(0) > 0 && sensorB.getTempFByIndex(0) < 212)  actualSensorBTemp = sensorB.getTempFByIndex(0);
  tempANumber.setValue(actualSensorATemp);
  tempBNumber.setValue(actualSensorBTemp);
  tempCNumber.setValue(actualSensorCTemp);
  if (currentMillis - lastDutyCycle >= dutyCycle)
  {
    lastDutyCycle = currentMillis;
  }
  if (element2Status) {
    if (millis() - lastDutyCycle <= dutyTime)
    {
      if (digitalRead(ELEMENT1_SSR_RELAY) == LOW || digitalRead(ELEMENT2_SSR_RELAY) == LOW)
      {
        Serial2.println("Turning SSR relays on");
        digitalWrite(ELEMENT1_SSR_RELAY, HIGH);
        digitalWrite(ELEMENT2_SSR_RELAY, HIGH);
      }
    }
    //else turn off
    else
    {
      if (digitalRead(ELEMENT1_SSR_RELAY) == HIGH || digitalRead(ELEMENT2_SSR_RELAY) == HIGH)
      {
        Serial2.println("Turning SSR relays off");
        digitalWrite(ELEMENT1_SSR_RELAY, LOW);
        digitalWrite(ELEMENT2_SSR_RELAY, LOW);
      }
    }
    //if current time is outside of cycle time, reset.
    if (millis() - lastDutyCycle >= dutyCycle)
    {
      lastDutyCycle = millis();
      Serial2.print(F("Updated Distilling Duty Cycle to: "));
      Serial2.println(lastDutyCycle);
    }
  }
  else
  {
    if (digitalRead(ELEMENT1_SSR_RELAY) == HIGH || digitalRead(ELEMENT2_SSR_RELAY) == HIGH)
    {
      Serial2.println(F("Turning SSR relays off"));
      digitalWrite(ELEMENT1_SSR_RELAY, LOW);
      digitalWrite(ELEMENT2_SSR_RELAY, LOW);
    }
  }

  nexLoop(nex_listen_list);
}

void tempProbesSetup()
{

  Serial2.println("Setting up onewire devices");

  pinMode(TEMPC_BUS, INPUT);
  pinMode(TEMPB_BUS, INPUT);
  pinMode(TEMPA_BUS, INPUT);

  Serial2.println("Set Pinmode for OneWire");

  sensorC.begin();
  sensorC.setResolution(TEMP_PRECISION);
  sensorC.setWaitForConversion(false);

  Serial2.println("Set Sensor C precision");

  sensorA.begin();
  sensorA.setResolution(TEMP_PRECISION);
  sensorA.setWaitForConversion(false);

  Serial2.println("Set Sensor A precision");

  sensorB.begin();
  sensorB.setResolution(TEMP_PRECISION);
  sensorB.setWaitForConversion(false);

  Serial2.println("Set Sensor B precision");
}
void nexSetup()
{
  Serial2.println("Setting up Display");
  nexInit();
  element1Button.attachPop(ButtonElement1Release, &element1Button);
  element2Button.attachPop(ButtonElement2Release, &element2Button);
  pump1Button.attachPop(ButtonPump1Release, &pump1Button);
  pump2Button.attachPop(ButtonPump2Release, &pump2Button);
  powerSlider.attachPop(SliderRelease, &powerSlider);

}

void SliderRelease(void *ptr)
{
  //Set Power % for boiler
  unsigned int value;
  powerSlider.getValue(&value);
  powerPercentage = value / 100.0;
  dutyTime = dutyCycle * powerPercentage;

  Serial2.print("Value from Slider: ");
  Serial2.println(value);
  Serial2.print("Power Duty Cycle changed to: ");
  Serial2.println(powerPercentage);

}
void ButtonElement1Release(void *ptr)
{
  //Toggle Recirculating Pump
  Serial2.print("Element 1 Pressed");
  element1Status = !element1Status;
  if (element1Status) {
    digitalWrite(ELEMENT1_CONTACTOR_RELAY, HIGH);
    digitalWrite(ELEMENT1_SSR_RELAY, HIGH);
  }
  else {
    digitalWrite(ELEMENT1_CONTACTOR_RELAY, LOW);
    digitalWrite(ELEMENT1_SSR_RELAY, LOW);
  }
  element1Button.setValue(element1Status);
}
void ButtonElement2Release(void *ptr)
{
  Serial2.print("Element 2 Pressed");
  //Toggle Recirculating Pump
  element2Status = !element2Status;
  if (element2Status) {
    digitalWrite(ELEMENT2_CONTACTOR_RELAY, HIGH);
    digitalWrite(ELEMENT2_SSR_RELAY, HIGH);
  }
  else {
    digitalWrite(ELEMENT2_CONTACTOR_RELAY, LOW);
    digitalWrite(ELEMENT2_SSR_RELAY, LOW);
  }
  element2Button.setValue(element2Status);
}
void ButtonPump1Release(void *ptr)
{
  Serial2.print("Pump 1 Pressed");
  pump1Status = !pump1Status;
  if (pump1Status) {
    digitalWrite(PUMP1_RELAY, HIGH);
  }
  else {
    digitalWrite(PUMP1_RELAY, LOW);
  }
  //Toggle Recirculating Pump
  pump1Button.setValue(pump1Status);
}
void ButtonPump2Release(void *ptr)
{
  Serial2.print("Pump 2 Pressed");
  //Toggle Recirculating Pump
  pump2Status = !pump2Status;
  if (pump2Status) {
    digitalWrite(PUMP2_RELAY, HIGH);
  }
  else {
    digitalWrite(PUMP2_RELAY, LOW);
  }
  pump2Button.setValue(pump2Status);
}

in NexConfig.h:

/**
 * @file NexConfig.h
 *
 * Options for user can be found here. 
 *
 * @author  Wu Pengfei (email:<pengfei.wu@itead.cc>)
 * @date    2015/8/13
 * @copyright 
 * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 */
#ifndef __NEXCONFIG_H__
#define __NEXCONFIG_H__

/**
 * @addtogroup Configuration 
 * @{ 
 */

/** 
 * Define DEBUG_SERIAL_ENABLE to enable debug serial. 
 * Comment it to disable debug serial. 
 */
///#define DEBUG_SERIAL_ENABLE

/**
 * Define dbSerial for the output of debug messages. 
 */
//#define dbSerial Serial2

/**
 * Define nexSerial for communicate with Nextion touch panel. 
 */
#define nexSerial Serial1


#ifdef DEBUG_SERIAL_ENABLE
#define dbSerialPrint(a)    dbSerial.print(a)
#define dbSerialPrintln(a)  dbSerial.println(a)
#define dbSerialBegin(a)    dbSerial.begin(a)
#else
#define dbSerialPrint(a)    do{}while(0)
#define dbSerialPrintln(a)  do{}while(0)
#define dbSerialBegin(a)    do{}while(0)
#endif

/**
 * @}
 */

#endif /* #ifndef __NEXCONFIG_H__ */

these are the only ones that I have personally modified.

I do not understand where that button is located, ESP, Nextion hardware, Nextion screen,
and I do not understand what happens, or what should happen.

There are not too many fans of the itead library here, so you will be pretty alone using it.

Sorry,

there are 4 buttons on the screen. they are dual state buttons and I just want the functions to be called. I can work on the rest later. Ultimately they are to turn on relays that are part of the board that the ESP32 is on, but right now, if it just outputs text to the serial monitor, id call that a win.

Send id is checked on the buttons?

yes, on all 4. and I can verify through the debugger that they are actually being sent

With the id numbers you are listening on?
Did you double-check them?

If those are correct,
you are asking about itead behavior, where I can not help, sorry.

I parse the messages myself.

fair enough. I did just double check the IDs and the Page. they still line up.

I just had a thought (ive been out of this dev style for a long time) I think i remember that one of the hardware serial ports on a esp32 is Tx only. no Rx... Maybe I messed up and connected to that?

Could very well be so.

I'm using Serial2 on a Lolin32 to communicate with the Nextion (which I have set to 115200).

Serial2.begin(115200); // 16 rx, 17 tx

Those connections work for me.

More about ESP32's and Serial

BTW, you should use a voltage divider on the Nextions TX pin, The Nextion is hardcore 5V.

this is the schematic for the connector to the Nextion. This worked before... its got to be something silly... All I did was reinstall my dev environment from scratch.

I am using Serial1.
image

also with debugging port enabled, I am getting confirmation that the Nextion is receiving the temperatures. so I know it can send to the MCU.

Did you try to move the RX pin to a different one?
Basically I see no problems with your choice, but I'm only an interested ESP32 user, no expert.

Can you see the signal at the end of the cable?
Behind the level shifter?
It could be a broken wire, a dead FET, bad solder joint, ...