Unofficial Nextion/TJC User Forum

Read/writing data from/to Nextion with arduino

Hi,
I’m really new at all this so bear with me. In a nutshell, I need to control a motor in a timed fashion. I started out using millis() on the Arduino to create a timer --rather than using delay().
But now that I’ve got a Nextion display, with its built in timers, I’d like to use them instead.
So now I’ve got a nice GUI interface on the screen with a slider that sets the timer from 1-60 seconds and once enabled with a button, you see the slider position stepping down towards 0 every second.
It’s beautiful. What is NOT beautiful is the fact that I can’t figure out how to get the current value of the timer into the arduino sketch. Nor do I know how to send data from the Arduino to any of the controls on the Nextion.
I understand that this is basic stuff, but I’ve yet to find anything that has worked. Probably because I don’t understand the fundamentals of read/writing to a Nextion. Any help would be most welcome. Keep it as simple as possible.

Do you want to send to the arduino what you set the nextion timer to, or send a signal when the nextion timer reaches zero?
Wouldn’t advise sending every second from the nextion to arduino

No I’m not looking to send FROM the Nextion TO the Arduino but I am planning on reading the value of the timer, every time through loop(). But if you also don’t think that that’s a good idea, how would I get the timer to tell the Arduino when it’s hit “0”? That seems like a much more efficient way to do it.
Thanks for your help.

Have put together sample nextion and arduino code which has been tested.
From the code you should be able to adapt for your project

Nextion
start a new project.
create button (named b0), text box (named t0), String variable (named sendmess), Timer (named tm0)
in ‘timer attribute’ ensure ‘en’ = 0 not 1 otherwise the timer will auto start when powered up.
in b0 touchPressEvent put following from between the rows of dots

tm0.en=1 // starts the timer
t0.txt=“Timer started” //updates text box
sendmess.txt=“TIMER1” // changes sendmess variable
get sendmess.txt //sends the variable to Arduino (start of timer)

in tm0 Event put following from between the rows of dots

t0.txt=“Timer stopped” // updates text box
tm0.en=0 // stops the timer
sendmess.txt=“TIMER0” // changes sendmess variable
get sendmess.txt //sends the variable to Arduino (end of timer)

You can now test this - click Debug (top of nextion editor)
Click button and look at ‘Simulator Return’ box at the bottom. Suggest you also click the ‘S’ on that box header for String not Hex
You should see this each time you press the button (with a 3 second delay):
pTIMER1ÿÿÿ
pTIMER0ÿÿÿ
Every message always starts with a single character - then your text - then ends with ÿÿÿ (hex 0xFF 0xFF 0xFF)

Arduino
Tested on Arduino UNO
copy paste this code between rows of dots into new sketch then look at serial monitor once uploaded.

#include <SoftwareSerial.h>
SoftwareSerial nex(A0, A1); // RX | TX
String getNex, preNex, nextionData;

void setup() {
Serial.begin(115200);Serial.println();
nex.begin(9600); //start nextion comms
}

void loop() {
checkNex(); //are there any messages from nextion
if(getNex!="") {// message received
preNex=getNex.substring(0,5);
if(preNex==“TIMER”) nextionData=getNex.substring(5,6);
if(preNex==“TIMER” && nextionData==“0”) { // timer ended
Serial.print(LINE);Serial.print(" > “);Serial.println(“Nextion: ended\n”);
}
if(preNex==“TIMER” && nextionData==“1”) { // timer ended
Serial.print(LINE);Serial.print(” > ");Serial.println(“Nextion: started”);
}
}
delay(500);
}

void checkNex() { //receive data from nextion
getNex="";
if(nex.available()) {
getNex = nex.readStringUntil(’\xFF\xFF\xFF’);
getNex=getNex.substring(1,100);// throw away 1st character
}
}

Hope this helps

Thanks for all your hard work Bobj.
I’m getting a bunch of errors and don’t know what they mean. Am I doing something wrong?
When/if you have a chance, take a look. It’ll probably be obvious to someone who has a clue ; )
–John

Arduino: 1.8.18 (Windows 8.1), Board: “Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)”

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\John new\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\John new\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\John new\Documents\Arduino\libraries -fqbn=arduino:avr:mega:cpu=atmega2560 -vid-pid=2341_0042 -ide-version=10818 -build-path C:\Users\JOHNNE~1\AppData\Local\Temp\arduino_build_699991 -warnings=default -build-cache C:\Users\JOHNNE~1\AppData\Local\Temp\arduino_cache_428028 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=C:\Users\John new\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\John new\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avr-gcc.path=C:\Users\John new\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\John new\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.arduinoOTA.path=C:\Users\John new\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\John new\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -verbose C:\Users\John new\Documents\Arduino\sketch_jan25a_1-25-22–937a\sketch_jan25a_1-25-22–937a.ino

C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\John new\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\John new\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\John new\Documents\Arduino\libraries -fqbn=arduino:avr:mega:cpu=atmega2560 -vid-pid=2341_0042 -ide-version=10818 -build-path C:\Users\JOHNNE~1\AppData\Local\Temp\arduino_build_699991 -warnings=default -build-cache C:\Users\JOHNNE~1\AppData\Local\Temp\arduino_cache_428028 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=C:\Users\John new\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\John new\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avr-gcc.path=C:\Users\John new\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\John new\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.arduinoOTA.path=C:\Users\John new\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\John new\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -verbose C:\Users\John new\Documents\Arduino\sketch_jan25a_1-25-22–937a\sketch_jan25a_1-25-22–937a.ino

Using board ‘mega’ from platform in folder: C:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4

Using core ‘arduino’ from platform in folder: C:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4

Detecting libraries used…

“C:\Users\John new\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10818 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR “-IC:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\cores\arduino” “-IC:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\variants\mega” “C:\Users\JOHNNE~1\AppData\Local\Temp\arduino_build_699991\sketch\sketch_jan25a_1-25-22–937a.ino.cpp” -o nul

Alternatives for SoftwareSerial.h: [SoftwareSerial@1.0]

ResolveLibrary(SoftwareSerial.h)

→ candidates: [SoftwareSerial@1.0]

“C:\Users\John new\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10818 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR “-IC:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\cores\arduino” “-IC:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\variants\mega” “-IC:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\libraries\SoftwareSerial\src” “C:\Users\JOHNNE~1\AppData\Local\Temp\arduino_build_699991\sketch\sketch_jan25a_1-25-22–937a.ino.cpp” -o nul

“C:\Users\John new\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10818 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR “-IC:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\cores\arduino” “-IC:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\variants\mega” “-IC:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\libraries\SoftwareSerial\src” “C:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\libraries\SoftwareSerial\src\SoftwareSerial.cpp” -o nul

Generating function prototypes…

“C:\Users\John new\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10818 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR “-IC:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\cores\arduino” “-IC:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\variants\mega” “-IC:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\libraries\SoftwareSerial\src” “C:\Users\JOHNNE~1\AppData\Local\Temp\arduino_build_699991\sketch\sketch_jan25a_1-25-22–937a.ino.cpp” -o “C:\Users\JOHNNE~1\AppData\Local\Temp\arduino_build_699991\preproc\ctags_target_for_gcc_minus_e.cpp”

“C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags” -u --language-force=c++ -f - --c+±kinds=svpf --fields=KSTtzns --line-directives “C:\Users\JOHNNE~1\AppData\Local\Temp\arduino_build_699991\preproc\ctags_target_for_gcc_minus_e.cpp”

Compiling sketch…

“C:\Users\John new\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++” -c -g -Os -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10818 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR “-IC:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\cores\arduino” “-IC:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\variants\mega” “-IC:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\libraries\SoftwareSerial\src” “C:\Users\JOHNNE~1\AppData\Local\Temp\arduino_build_699991\sketch\sketch_jan25a_1-25-22–937a.ino.cpp” -o “C:\Users\JOHNNE~1\AppData\Local\Temp\arduino_build_699991\sketch\sketch_jan25a_1-25-22–937a.ino.cpp.o”

sketch_jan25a_1-25-22–937a:14:12: error: stray ‘\342’ in program

if(preNex==“TIMER”) nextionData=getNex.substring(5,6);

        ^

sketch_jan25a_1-25-22–937a:14:13: error: stray ‘\200’ in program

if(preNex==“TIMER”) nextionData=getNex.substring(5,6);

         ^

sketch_jan25a_1-25-22–937a:14:14: error: stray ‘\234’ in program

if(preNex==“TIMER”) nextionData=getNex.substring(5,6);

          ^

sketch_jan25a_1-25-22–937a:14:20: error: stray ‘\342’ in program

if(preNex==“TIMER”) nextionData=getNex.substring(5,6);

                ^

sketch_jan25a_1-25-22–937a:14:21: error: stray ‘\200’ in program

if(preNex==“TIMER”) nextionData=getNex.substring(5,6);

                 ^

sketch_jan25a_1-25-22–937a:14:22: error: stray ‘\235’ in program

if(preNex==“TIMER”) nextionData=getNex.substring(5,6);

                  ^

sketch_jan25a_1-25-22–937a:15:12: error: stray ‘\342’ in program

if(preNex==“TIMER” && nextionData==“0”) { // timer ended

        ^

sketch_jan25a_1-25-22–937a:15:13: error: stray ‘\200’ in program

if(preNex==“TIMER” && nextionData==“0”) { // timer ended

         ^

sketch_jan25a_1-25-22–937a:15:14: error: stray ‘\234’ in program

if(preNex==“TIMER” && nextionData==“0”) { // timer ended

          ^

sketch_jan25a_1-25-22–937a:15:20: error: stray ‘\342’ in program

if(preNex==“TIMER” && nextionData==“0”) { // timer ended

                ^

sketch_jan25a_1-25-22–937a:15:21: error: stray ‘\200’ in program

if(preNex==“TIMER” && nextionData==“0”) { // timer ended

                 ^

sketch_jan25a_1-25-22–937a:15:22: error: stray ‘\235’ in program

if(preNex==“TIMER” && nextionData==“0”) { // timer ended

                  ^

sketch_jan25a_1-25-22–937a:15:40: error: stray ‘\342’ in program

if(preNex==“TIMER” && nextionData==“0”) { // timer ended

                                    ^

sketch_jan25a_1-25-22–937a:15:41: error: stray ‘\200’ in program

if(preNex==“TIMER” && nextionData==“0”) { // timer ended

                                     ^

sketch_jan25a_1-25-22–937a:15:42: error: stray ‘\234’ in program

if(preNex==“TIMER” && nextionData==“0”) { // timer ended

                                      ^

sketch_jan25a_1-25-22–937a:15:44: error: stray ‘\342’ in program

if(preNex==“TIMER” && nextionData==“0”) { // timer ended

                                        ^

sketch_jan25a_1-25-22–937a:15:45: error: stray ‘\200’ in program

if(preNex==“TIMER” && nextionData==“0”) { // timer ended

                                         ^

sketch_jan25a_1-25-22–937a:15:46: error: stray ‘\235’ in program

if(preNex==“TIMER” && nextionData==“0”) { // timer ended

                                          ^

C:\Users\John new\Documents\Arduino\sketch_jan25a_1-25-22–937a\sketch_jan25a_1-25-22–937a.ino:16:33: warning: missing terminating " character

Serial.print(LINE);Serial.print(" > “);Serial.println(“Nextion: ended\n”);

                             ^

sketch_jan25a_1-25-22–937a:16:33: error: missing terminating " character

Serial.print(LINE);Serial.print(" > “);Serial.println(“Nextion: ended\n”);

                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

sketch_jan25a_1-25-22–937a:18:12: error: stray ‘\342’ in program

if(preNex==“TIMER” && nextionData==“1”) { // timer ended

        ^

sketch_jan25a_1-25-22–937a:18:13: error: stray ‘\200’ in program

if(preNex==“TIMER” && nextionData==“1”) { // timer ended

         ^

sketch_jan25a_1-25-22–937a:18:14: error: stray ‘\234’ in program

if(preNex==“TIMER” && nextionData==“1”) { // timer ended

          ^

sketch_jan25a_1-25-22–937a:18:20: error: stray ‘\342’ in program

if(preNex==“TIMER” && nextionData==“1”) { // timer ended

                ^

sketch_jan25a_1-25-22–937a:18:21: error: stray ‘\200’ in program

if(preNex==“TIMER” && nextionData==“1”) { // timer ended

                 ^

sketch_jan25a_1-25-22–937a:18:22: error: stray ‘\235’ in program

if(preNex==“TIMER” && nextionData==“1”) { // timer ended

                  ^

sketch_jan25a_1-25-22–937a:18:40: error: stray ‘\342’ in program

if(preNex==“TIMER” && nextionData==“1”) { // timer ended

                                    ^

sketch_jan25a_1-25-22–937a:18:41: error: stray ‘\200’ in program

if(preNex==“TIMER” && nextionData==“1”) { // timer ended

                                     ^

sketch_jan25a_1-25-22–937a:18:42: error: stray ‘\234’ in program

if(preNex==“TIMER” && nextionData==“1”) { // timer ended

                                      ^

sketch_jan25a_1-25-22–937a:18:44: error: stray ‘\342’ in program

if(preNex==“TIMER” && nextionData==“1”) { // timer ended

                                        ^

sketch_jan25a_1-25-22–937a:18:45: error: stray ‘\200’ in program

if(preNex==“TIMER” && nextionData==“1”) { // timer ended

                                         ^

sketch_jan25a_1-25-22–937a:18:46: error: stray ‘\235’ in program

if(preNex==“TIMER” && nextionData==“1”) { // timer ended

                                          ^

sketch_jan25a_1-25-22–937a:19:33: error: stray ‘\342’ in program

Serial.print(LINE);Serial.print(” > ");Serial.println(“Nextion: started”);

                             ^

sketch_jan25a_1-25-22–937a:19:34: error: stray ‘\200’ in program

Serial.print(LINE);Serial.print(” > ");Serial.println(“Nextion: started”);

                              ^

sketch_jan25a_1-25-22–937a:19:35: error: stray ‘\235’ in program

Serial.print(LINE);Serial.print(” > ");Serial.println(“Nextion: started”);

                               ^

C:\Users\John new\Documents\Arduino\sketch_jan25a_1-25-22–937a\sketch_jan25a_1-25-22–937a.ino:19:39: warning: missing terminating " character

Serial.print(LINE);Serial.print(” > ");Serial.println(“Nextion: started”);

                                   ^

sketch_jan25a_1-25-22–937a:19:39: error: missing terminating " character

Serial.print(LINE);Serial.print(” > ");Serial.println(“Nextion: started”);

                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

sketch_jan25a_1-25-22–937a:28:30: error: stray ‘\342’ in program

getNex = nex.readStringUntil(’\xFF\xFF\xFF’);

                          ^

sketch_jan25a_1-25-22–937a:28:31: error: stray ‘\200’ in program

getNex = nex.readStringUntil(’\xFF\xFF\xFF’);

                           ^

sketch_jan25a_1-25-22–937a:28:32: error: stray ‘\231’ in program

getNex = nex.readStringUntil(’\xFF\xFF\xFF’);

                            ^

sketch_jan25a_1-25-22–937a:28:33: error: stray ‘’ in program

getNex = nex.readStringUntil(’\xFF\xFF\xFF’);

                             ^

sketch_jan25a_1-25-22–937a:28:37: error: stray ‘’ in program

getNex = nex.readStringUntil(’\xFF\xFF\xFF’);

                                 ^

sketch_jan25a_1-25-22–937a:28:41: error: stray ‘’ in program

getNex = nex.readStringUntil(’\xFF\xFF\xFF’);

                                     ^

sketch_jan25a_1-25-22–937a:28:45: error: stray ‘\342’ in program

getNex = nex.readStringUntil(’\xFF\xFF\xFF’);

                                         ^

sketch_jan25a_1-25-22–937a:28:46: error: stray ‘\200’ in program

getNex = nex.readStringUntil(’\xFF\xFF\xFF’);

                                          ^

sketch_jan25a_1-25-22–937a:28:47: error: stray ‘\231’ in program

getNex = nex.readStringUntil(’\xFF\xFF\xFF’);

                                           ^

C:\Users\John new\Documents\Arduino\sketch_jan25a_1-25-22–937a\sketch_jan25a_1-25-22–937a.ino: In function ‘void loop()’:

sketch_jan25a_1-25-22–937a:14:15: error: ‘TIMER’ was not declared in this scope

if(preNex==“TIMER”) nextionData=getNex.substring(5,6);

           ^~~~~

C:\Users\John new\Documents\Arduino\sketch_jan25a_1-25-22–937a\sketch_jan25a_1-25-22–937a.ino:14:15: note: suggested alternative: ‘TIMER2’

if(preNex==“TIMER”) nextionData=getNex.substring(5,6);

           ^~~~~

           TIMER2

sketch_jan25a_1-25-22–937a:15:15: error: ‘TIMER’ was not declared in this scope

if(preNex==“TIMER” && nextionData==“0”) { // timer ended

           ^~~~~

C:\Users\John new\Documents\Arduino\sketch_jan25a_1-25-22–937a\sketch_jan25a_1-25-22–937a.ino:15:15: note: suggested alternative: ‘TIMER2’

if(preNex==“TIMER” && nextionData==“0”) { // timer ended

           ^~~~~

           TIMER2

sketch_jan25a_1-25-22–937a:16:14: error: ‘LINE’ was not declared in this scope

Serial.print(LINE);Serial.print(" > “);Serial.println(“Nextion: ended\n”);

          ^~~~

C:\Users\John new\Documents\Arduino\sketch_jan25a_1-25-22–937a\sketch_jan25a_1-25-22–937a.ino:16:14: note: suggested alternative: ‘PINE’

Serial.print(LINE);Serial.print(" > “);Serial.println(“Nextion: ended\n”);

          ^~~~

          PINE

sketch_jan25a_1-25-22–937a:17:1: error: expected primary-expression before ‘}’ token

}

^

sketch_jan25a_1-25-22–937a:18:15: error: ‘TIMER’ was not declared in this scope

if(preNex==“TIMER” && nextionData==“1”) { // timer ended

           ^~~~~

C:\Users\John new\Documents\Arduino\sketch_jan25a_1-25-22–937a\sketch_jan25a_1-25-22–937a.ino:18:15: note: suggested alternative: ‘TIMER2’

if(preNex==“TIMER” && nextionData==“1”) { // timer ended

           ^~~~~

           TIMER2

C:\Users\John new\Documents\Arduino\sketch_jan25a_1-25-22–937a\sketch_jan25a_1-25-22–937a.ino:18:43: warning: invalid conversion from ‘int’ to ‘const char*’ [-fpermissive]

if(preNex==“TIMER” && nextionData==“1”) { // timer ended

                                       ^

In file included from C:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\cores\arduino/Arduino.h:232:0,

             from C:\Users\JOHNNE~1\AppData\Local\Temp\arduino_build_699991\sketch\sketch_jan25a_1-25-22--937a.ino.cpp:1:

C:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\cores\arduino/WString.h:143:16: note: initializing argument 1 of ‘unsigned char String::operator==(const char*) const’

unsigned char operator == (const char *cstr) const {return equals(cstr);}

            ^~~~~~~~

sketch_jan25a_1-25-22–937a:19:14: error: ‘LINE’ was not declared in this scope

Serial.print(LINE);Serial.print(” > ");Serial.println(“Nextion: started”);

          ^~~~

C:\Users\John new\Documents\Arduino\sketch_jan25a_1-25-22–937a\sketch_jan25a_1-25-22–937a.ino:19:14: note: suggested alternative: ‘PINE’

Serial.print(LINE);Serial.print(” > ");Serial.println(“Nextion: started”);

          ^~~~

          PINE

sketch_jan25a_1-25-22–937a:19:37: error: expected primary-expression before ‘>’ token

Serial.print(LINE);Serial.print(” > ");Serial.println(“Nextion: started”);

                                 ^

sketch_jan25a_1-25-22–937a:20:1: error: expected primary-expression before ‘}’ token

}

^

C:\Users\John new\Documents\Arduino\sketch_jan25a_1-25-22–937a\sketch_jan25a_1-25-22–937a.ino: In function ‘void checkNex()’:

sketch_jan25a_1-25-22–937a:28:34: error: ‘xFF’ was not declared in this scope

getNex = nex.readStringUntil(’\xFF\xFF\xFF’);

                              ^~~

Using library SoftwareSerial at version 1.0 in folder: C:\Users\John new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4\libraries\SoftwareSerial

exit status 1

stray ‘\342’ in program

OK - so you have a mega - that is easier as it has more serial ports.
It seems that embedded code cannot be copy/pasted to ino. I had same errors .
Will send you sketch
email me at bob.bj43 AT gmail.com

Problem is with forum software, browser language settings and copy/paste. Arduino does not like typographic double quotes in Unicode. Replace these with standard ASCII double quotes as indicated in the compile/build verbose and the error will be gone.


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).