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