'NexText does not name a type

I'm testing a Nextion NX4832K035 and have taken an example from the web. I had it working a couple of months ago and coming back to it I find that it doesn't work anymore. The Nextion is connected to a MEGA2560 and I'm using IDE 1.8.13. The error code is "'NexText' does not name a type".

Code:

#include "Nextion.h"
#include "DHT.h"

#define DHTPIN 4       // what digital pin we're connected to
#define DHTTYPE DHT11   // DHT 11
// Initialize DHT sensor.
DHT dht(DHTPIN, DHTTYPE);

// LED pins
const int led1 = 8;
const int led2 = 9;

// Declare Nextion objects - Example (page id = 0, component id = 1, component name = "b0") 
NexText tLedState = NexText(0, 6, "tLedState"); 
NexButton bOn = NexButton(0, 2, "bOn");
NexButton bOff = NexButton(0, 3, "bOff");
NexSlider hSlider = NexSlider(0, 4, "hSlider");
NexText tPosition = NexText(0, 5, "tPosition");
NexText tTempC = NexText(1, 4, "tTempC");
NexText tTempF = NexText(1, 5, "tTempF");
NexProgressBar jHumidity = NexProgressBar(1, 6, "jHumidity");
NexText tHumidity = NexText(1, 3, "tHumidity");
NexButton bUpdate = NexButton(1,7, "bUpdate");

// Register a button object to the touch event list.  
NexTouch *nex_listen_list[] = {
  &bOn,
  &bOff,
  &hSlider,
  &bUpdate,
  NULL
};
 
/*
 * Button bOn component pop callback function. 
 * When the ON button is released, the LED turns on and the state text changes. 
 */
void bOnPopCallback(void *ptr) {
  tLedState.setText("State: on");
  digitalWrite(led1, HIGH);
}

/*
 * Button bOff component pop callback function. 
 * When the OFF button is released, the LED turns off and the state text changes. 
 */
void bOffPopCallback(void *ptr) {
  tLedState.setText("State: off");
  digitalWrite(led1, LOW);
}

/*
 * Slider hSlider component pop callback function. 
 * When the slider is released, the LED brightness changes and the slider text changes. 
 */
void hSliderPopCallback(void *ptr) {
  uint32_t number = 0;
  char temp[10] = {0};
  // change text with the current slider value
  hSlider.getValue(&number);
  utoa(number, temp, 10);
  tPosition.setText(temp);
  // change LED brightness
  analogWrite(led2, number); 
}

/*
 * Button bUpdate component pop callback function. 
 * When UPDATE button is released, temperature and humidity readings are updated. 
 */
void bUpdatePopCallback(void *ptr)
  {
  float h = dht.readHumidity();         // Reading temp/humidity takes ~ 250mS. Slow sensor.
  float t = dht.readTemperature();      // Read temperature as Celsius (the default)
  float f = dht.readTemperature(true);  // Read temperature as Fahrenheit (isFahrenheit = true)
  
  if (isnan(h) || isnan(t) || isnan(f)) // Check if any reads failed and exit early (to try again).
  {
    tTempC.setText("DH11 error");
    return;
  }
  
  // Update humidity percentage text and progress bar
  char hTemp[10] = {0}; 
  utoa(int(h), hTemp, 10);
  tHumidity.setText(hTemp);
  jHumidity.setValue(int(h));

  // Update temperature in Celsius
  static char temperatureCTemp[6];
  dtostrf(t, 6, 2, temperatureCTemp);
  tTempC.setText(temperatureCTemp);

  // Update temperature in Fahrenheit
  static char temperatureFTemp[6];
  dtostrf(f, 6, 2, temperatureFTemp);
  tTempF.setText(temperatureFTemp);
}

void setup(void) {    
  dht.begin();
  Serial.begin(9600);
    
  // You might need to change NexConfig.h file in your ITEADLIB_Arduino_Nextion folder
  // Set the baudrate which is for debug and communicate with Nextion screen
  nexInit();

  // Register the pop event callback function of the components
  bOn.attachPop(bOnPopCallback, &bOn);
  bOff.attachPop(bOffPopCallback, &bOff);
  hSlider.attachPop(hSliderPopCallback);
  bUpdate.attachPop(bUpdatePopCallback, &bUpdate);
    
  // Set LEDs as outputs
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
}

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.
   */
  nexLoop(nex_listen_list);
}

Errors:

Nextion_test1:14:1: error: 'NexText' does not name a type
 NexText tLedState = NexText(0, 6, "tLedState");
 ^~~~~~~
Nextion_test1:15:1: error: 'NexButton' does not name a type; did you mean 'Nextion'?
 NexButton bOn = NexButton(0, 2, "bOn");
 ^~~~~~~~~
 Nextion
Nextion_test1:16:1: error: 'NexButton' does not name a type; did you mean 'Nextion'?
 NexButton bOff = NexButton(0, 3, "bOff");
 ^~~~~~~~~
 Nextion
Nextion_test1:17:1: error: 'NexSlider' does not name a type
 NexSlider hSlider = NexSlider(0, 4, "hSlider");
 ^~~~~~~~~
Nextion_test1:18:1: error: 'NexText' does not name a type
 NexText tPosition = NexText(0, 5, "tPosition");
 ^~~~~~~
Nextion_test1:19:1: error: 'NexText' does not name a type
 NexText tTempC = NexText(1, 4, "tTempC");
 ^~~~~~~
Nextion_test1:20:1: error: 'NexText' does not name a type
 NexText tTempF = NexText(1, 5, "tTempF");
 ^~~~~~~
Nextion_test1:21:1: error: 'NexProgressBar' does not name a type
 NexProgressBar jHumidity = NexProgressBar(1, 6, "jHumidity");
 ^~~~~~~~~~~~~~
Nextion_test1:22:1: error: 'NexText' does not name a type
 NexText tHumidity = NexText(1, 3, "tHumidity");
 ^~~~~~~
Nextion_test1:23:1: error: 'NexButton' does not name a type; did you mean 'Nextion'?
 NexButton bUpdate = NexButton(1,7, "bUpdate");
 ^~~~~~~~~
 Nextion
Nextion_test1:26:1: error: 'NexTouch' does not name a type
 NexTouch *nex_listen_list[] = {
 ^~~~~~~~
E:\Documents\Arduino\Nextion_test1\Nextion_test1.ino: In function 'void bOnPopCallback(void*)':
Nextion_test1:39:3: error: 'tLedState' was not declared in this scope
   tLedState.setText("State: on");
   ^~~~~~~~~
E:\Documents\Arduino\Nextion_test1\Nextion_test1.ino: In function 'void bOffPopCallback(void*)':
Nextion_test1:48:3: error: 'tLedState' was not declared in this scope
   tLedState.setText("State: off");
   ^~~~~~~~~
E:\Documents\Arduino\Nextion_test1\Nextion_test1.ino: In function 'void hSliderPopCallback(void*)':
Nextion_test1:60:3: error: 'hSlider' was not declared in this scope
   hSlider.getValue(&number);
   ^~~~~~~
Nextion_test1:62:3: error: 'tPosition' was not declared in this scope
   tPosition.setText(temp);
   ^~~~~~~~~
E:\Documents\Arduino\Nextion_test1\Nextion_test1.ino: In function 'void bUpdatePopCallback(void*)':
Nextion_test1:79:5: error: 'tTempC' was not declared in this scope
     tTempC.setText("DH11 error");
     ^~~~~~
Nextion_test1:86:3: error: 'tHumidity' was not declared in this scope
   tHumidity.setText(hTemp);
   ^~~~~~~~~
Nextion_test1:87:3: error: 'jHumidity' was not declared in this scope
   jHumidity.setValue(int(h));
   ^~~~~~~~~
Nextion_test1:92:3: error: 'tTempC' was not declared in this scope
   tTempC.setText(temperatureCTemp);
   ^~~~~~
E:\Documents\Arduino\Nextion_test1\Nextion_test1.ino:92:3: note: suggested alternative: 'hTemp'
   tTempC.setText(temperatureCTemp);
   ^~~~~~
   hTemp
Nextion_test1:97:3: error: 'tTempF' was not declared in this scope
   tTempF.setText(temperatureFTemp);
   ^~~~~~
E:\Documents\Arduino\Nextion_test1\Nextion_test1.ino:97:3: note: suggested alternative: 'hTemp'
   tTempF.setText(temperatureFTemp);
   ^~~~~~
   hTemp
E:\Documents\Arduino\Nextion_test1\Nextion_test1.ino: In function 'void setup()':
Nextion_test1:106:3: error: 'nexInit' was not declared in this scope
   nexInit();
   ^~~~~~~
E:\Documents\Arduino\Nextion_test1\Nextion_test1.ino:106:3: note: suggested alternative: 'exit'
   nexInit();
   ^~~~~~~
   exit
Nextion_test1:109:3: error: 'bOn' was not declared in this scope
   bOn.attachPop(bOnPopCallback, &bOn);
   ^~~
Nextion_test1:110:3: error: 'bOff' was not declared in this scope
   bOff.attachPop(bOffPopCallback, &bOff);
   ^~~~
Nextion_test1:111:3: error: 'hSlider' was not declared in this scope
   hSlider.attachPop(hSliderPopCallback);
   ^~~~~~~
Nextion_test1:112:3: error: 'bUpdate' was not declared in this scope
   bUpdate.attachPop(bUpdatePopCallback, &bUpdate);
   ^~~~~~~
E:\Documents\Arduino\Nextion_test1\Nextion_test1.ino: In function 'void loop()':
Nextion_test1:124:11: error: 'nex_listen_list' was not declared in this scope
   nexLoop(nex_listen_list);
           ^~~~~~~~~~~~~~~
Nextion_test1:124:3: error: 'nexLoop' was not declared in this scope
   nexLoop(nex_listen_list);
   ^~~~~~~
Multiple libraries were found for "Nextion.h"
 Used: E:\Documents\Arduino\libraries\Nextion
 Not used: E:\Documents\Arduino\libraries\NeoNextion
exit status 1
'NexText' does not name a type

Double Check that the Nextion library is correctly installed

Multiple libraries were found for "Nextion.h"
 Used: E:\Documents\Arduino\libraries\Nextion
 Not used: E:\Documents\Arduino\libraries\NeoNextion
exit status 1

that might be the issue, it should actually be looking in the sketch folder with the "

Deva_Rishi:

Multiple libraries were found for "Nextion.h"

Used: E:\Documents\Arduino\libraries\Nextion
Not used: E:\Documents\Arduino\libraries\NeoNextion
exit status 1



that might be the issue, it should actually be looking in the sketch folder with the "

Deva_Rishi
I deleted the NeoNextion library but the error is still there

delete both of them and reinstall.

I deleted the NeoNextion library but the error is still there

of course you deleted the one that 'is not used'

delete both of them and reinstall.

I always thought that if you enclose the header file within hyphens, it would search in the sketch folder "Nextion.h"i am a little puzzled by this.

Deva_Rishi:
I always thought that if you enclose the header file within hyphens, it would search in the sketch folder "Nextion.h"i am a little puzzled by this.

it is searching in the sketch folder first, then in the standard locations.

J-M-L:
delete both of them and reinstall.

I deleted both and reinstalled and changed the #includes to using < instead of ". No change.

J-M-L:
it is searching in the sketch folder first, then in the standard locations.

I looked in the Nextion library and couldn't find any of the names NexText, NexButton etc. I found them in another library 'ITEADLIB_Arduino_Nextion' and when you include it you include 26 different sub-libraries. It seems to me to be an odd way of implementing libraries but I'm relatively new to Arduino so I guess there must be a good reason for it. Anyway, the sketch compiles without error so that's it. Thank you all.

it is searching in the sketch folder first, then in the standard locations.

Ah ok, well yeah i have never left it out of the sketch folder but left it available in the libraries folder. Thank you for the clarification.

When I include 'ITEADLIB_Arduino_Nextion' the sketch looks like this:

#include <doxygen.h>
#include <NexButton.h>
#include <NexCheckbox.h>
#include <NexConfig.h>
#include <NexCrop.h>
#include <NexDualStateButton.h>
#include <NexGauge.h>
#include <NexGpio.h>
#include <NexHardware.h>
#include <NexHotspot.h>
#include <NexNumber.h>
#include <NexObject.h>
#include <NexPage.h>
#include <NexPicture.h>
#include <NexProgressBar.h>
#include <NexRadio.h>
#include <NexRtc.h>
#include <NexScrolltext.h>
#include <NexSlider.h>
#include <NexText.h>
#include <NexTimer.h>
#include <Nextion.h>
#include <NexTouch.h>
#include <NexUpload.h>
#include <NexVariable.h>
#include <NexWaveform.h>

void setup() {
  // put your setup code here, to run once:

}

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

}

Is this the way it should be? I haven't seen any sketch on the forum which looks like this. They all use #include <Nextion.h> and that is all that is put into the head of the sketch. I'm puzzled.

I did some testing. If I put in <NexText.h> just before <Nextion.h> then the sketch compiles OK. How the compiler can find NexButton, NexSlider etc I don’t understand. Perhaps someone in this forum can explain how this works.

there is something fishy about your IDE + library installation. A simple #include <Nextion.h>at the start of your code should be enough to include everything you need since that .h includes all the other .h for you.

What happens if you run one of their examples?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.