For anyone who wants to use it, here are three modified files that fix the serial communications handling in the v0.9.0 Nextion library so that events actually work. The serial code in the Nextion library is atrocious - it discards messages at random, throws in long delays, and does other stupid things, so that GUI events and timers are basically unusable. This modification fixes all that, so events work AFAICT, perfecty.
There is one (optional) change in the API - I've added an optional baud rate argument to the nexInit function, to make it easier to change from the default 9600 baud to anything you want.
I'm just tossing these files out there for anyone who wants them, but make no claims it is 100% correct, though I've been using it for weeks with zero problems. If you find a problem, let me know, and I will try to correct it, but no guarantees.
Just copy the three files to your Nextion library folder, and, if you want a different baud rate, add the baud rate as an argument to your nexInit() call. Everything else should work just as before.
All - I've updated the nexHardware.cpp file in the first post of this thread. The one I originally attached was using printf, and doing other things that won't work for some people.
I am also using the numbers to get the font color of a text (pco).
In case the font color is e.g. 65534 which is white it will not get this number because it comes as 0xFF
And the counter for 0xFF starts (but will be read as the 3 times 0xFF at the end.
Any idea how to update this and get the Font Color PCO value as a number?
Thank you for the awesome fix to this library. I'm no expert, but reading the serial from the display once and then parsing it out seems so much better than the way itead was doing it. I can communicate both ways now.
However, I'm encountering a problem. When I send data to the display, for example updating a slider value, it seems like the code is waiting for a response from the nextion and not getting it. I get these messages in my debug window.
getResp timeout
recvRetCommandFinished err
This ends up slowing down the refresh rate of my sliders by the timeout delay. Can you please point me in the right direction?
Hi There can someone help please i went use the nextion libary with the modified files from post 1 and all I get is the following message.
Multiple libraries were found for "Nextion.h"
Used: C:\Users\Bob\Documents\Arduino\libraries\ITEADLIB_Arduino_Nextion-master
Multiple libraries were found for "SPI.h"
Used: C:\Program
Multiple libraries were found for "SD.h"
Used: C:\Program
Multiple libraries were found for "SoftwareSerial.h"
Used: C:\Program
exit status 1
Error compiling for board Arduino/Genuino Uno
I dont know what is happening
thanks
Bob
Since I'm using the nextion Intelligent screen my serial comm is completely rubbish. (way worse than on the enhanced one's i used.
So I am really desperate to get this working.
I hoped that this would fix my problems, but when I tried your files I can't compile anymore. I'm getting errors from the NexHardware.cpp
Any idea how i can fix this?
Arduino: 1.6.5 (Windows 8.1), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
C:\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexHardware.cpp:69:19: error: 'parseTargets' is not a class or namespace
int parseTarget = parseTargets::PARSE_MSG;
^
C:\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexHardware.cpp: In function 'void readDataMsg()':
C:\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexHardware.cpp:117:35: error: 'parseTargets' is not a class or namespace
parseTarget = parseTargets::PARSE_MSG;
^
C:\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexHardware.cpp:148:23: error: 'parseTargets' is not a class or namespace
parseTarget = parseTargets::PARSE_MSG;
^
C:\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexHardware.cpp: In function 'void parseRx(byte*, int)':
C:\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexHardware.cpp:164:25: error: 'parseTargets' is not a class or namespace
if ((parseTarget == parseTargets::PARSE_STRING) ||
^
C:\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexHardware.cpp:165:25: error: 'parseTargets' is not a class or namespace
(parseTarget == parseTargets::PARSE_NUMBER) ||
^
C:\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexHardware.cpp:166:25: error: 'parseTargets' is not a class or namespace
(parseTarget == parseTargets::PARSE_DISCARD))
^
C:\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexHardware.cpp:184:35: error: 'parseTargets' is not a class or namespace
parseTarget = parseTargets::PARSE_STRING;
^
C:\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexHardware.cpp:189:35: error: 'parseTargets' is not a class or namespace
parseTarget = parseTargets::PARSE_DISCARD;
^
C:\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexHardware.cpp:202:35: error: 'parseTargets' is not a class or namespace
parseTarget = parseTargets::PARSE_NUMBER;
^
C:\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexHardware.cpp:206:35: error: 'parseTargets' is not a class or namespace
parseTarget = parseTargets::PARSE_DISCARD;
^
Error compiling.
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Thanks for your work on the library. I have been using it for some time and stumbled across a problem with the getValue function. When returning a number that contained the HEX bytes 'FF', the function fails with message getNumber timeout. It can be replicated by simply writing:
ndspSerial is a number variable in my HMI. I have repeated this with FF in the first, second, third, and fourth positions, values 255, 65280, 16711680, and -16777216. Other values fail as well, 65281 for example. Until the FF byte clears the function errors.
Thank you for these changes. I wanted to let you know that your changes also make SofwareSerial work properly with a Nextion display and the Nano. Very useful!
Could you please send/post the hardware.cpp file that does not use printf? You noted that you updated the original post, but the downloaded file still uses printf for the the serial debug statements.
Thanks Ray! I'm new at using Nextion, and have been struggling with nexLoop missing button pushes. Replaced the 3 files in the Nextion library that you provided, recompiled my code, and everything works great. Also nice that those annoying debugging messages don't scroll through when using the Serial Monitor. Now I only see debug messages that I embedded in my code.
I know this is old, but updating the library files worked great for me without having to change my code. I have a constant countdown timer updating on the display and that seemed to bogg down the send/receive comms and cause button presses and other events to be missed. Using these updated library files seemed to help clear up those issues and I no longer get lost events.
Initially had some issues when using the Nextion Simulator in Debug mode not communicating. Had to modify the NexHardware.cpp file to use "Serial" as communication to display, rather than "Serial2". Hope this helps anyone else that has this issue.