Go Down

Topic: Using Nextion displays with Arduino (Read 15973 times) previous topic - next topic

orion555

Got a bit 'side tracked' in the endless world of coding... especially as a newbie, sometimes it can be quite humbling and overwhelming looking at all those doors opening up in front of one's continuously growing eyes...

In a severe fit of megalomania I tried to write, well, re-write the NexNumber lib to a NexFloat and ended up in a very deep rabbit hole. took me a while to find my way out again, but got it from an endless list of errors down to a couple... and slowly a slightly broader spectrum of to this never ending subject.

But it 's definitely my turn to pass the flowers to you, Perry, for the help you are providing here. Nice little hints you are passing on, especially the last ones I found quite interesting, since it sort of unlocked a whole lot of new possibilities and you deserve every bit of Karma you can get for things like that...

Was using the Nex's own libraries and was a bit too lacy to re-write all the work I finished so fart, with your sample code in your first postings (nicely done, by the way). But I came to the conclusion, well better rephrase that, I was lucky enough to get my fit under control... ;), and now I'm humbly going to use your code and hope I can get back to you, in case I don't get it straight...but all in all work is progressing, even if it isn't 'quite' as fast as I first thought it might happen...but I find if always very satisfying if things slowly start to do the things they should.

Knowing now that I'm at least capable of asking reasonable intelligent questions, I'm glad I found somebody who is helpful  enough to answer them. Thanks a lot for that. Hope I won't have to bother you too much.

I presume that other people on the 'big search' are passing by here as well, so I thought I might pass on a little helper to the Serial.print subject, simple enough that even I could have thought of it... :D, well, I didn't...but going to pass it on anyway, since it safes time and memory...

Code: [Select]


void nexDataSend() {
  Serial2.write(0xff);       // We always have to send this three lines after each command sent to the nextion display.
  Serial2.write(0xff);       //use the Serial(x) you are communicating with your Nex
  Serial2.write(0xff);
}



...and I find it quite handy, maybe it helps someone else as well.

will try my best to surface once in a while and pop by... ;)

kind regards

PerryBebbington

Thank you Orion, that makes helping you and others worthwhile :)

PerryBebbington

I have added to part 4 'Nextion additional features', which brings several different things together in one place. Enjoy!

altitudeap

@PerryBebbington et. all.  I posted this in another section but not sure it will get attention there.

I have not yet been successful in understanding the communication from the Nextion.  I have a few pages that are set up and I only need to capture the string that is sent when pages changes.  from this I will create a CASE statement and execute accordingly . 

For instance, when I am viewing the debug, and I am moving from page0 to page1, I get an simulator output (I am assuming I will see this as a serial string?) of  "65 00 02 01 FF FF FF"
So I have recorded all of these strings associated with the page movements and created a table of string, pulse and direction.  This will not be a high frequency event. (it is a shifter for a car)

Can I just use a simple serial program to read the string and then act upon the string in a CASE Statement? 
Thank you for any assistance you may be able to render.  I have some pictures but dont know how to or if I can post them


PerryBebbington

#49
Sep 15, 2019, 12:34 pm Last Edit: Oct 04, 2019, 05:07 pm by PerryBebbington
Hello altitudeap,
Sorry for the late reply, I have been on holiday :)


Quote
For instance, when I am viewing the debug, and I am moving from page0 to page1, I get an simulator output (I am assuming I will see this as a serial string?) of  "65 00 02 01 FF FF FF"
Yes, what you see in the simulator window is what is sent to the Nextion serial port. I would hesitate to call it a 'string' as that words has specific meaning in the C and C++ languages, and I don't think this data qualifies. Those bytes, as shown in the simulator window, will be sent to the serial port.

It is clear from the rest of your question that you have not tried my examples as set out in this tutorial, the answers are in there. Try the examples, then come back when you need further explanation.


orion444

Hi Perry,

Misplaced my PW for orion555 and I'm still waiting for the recovery mail...well, I guess waiting a week or two longer won't make the difference either anymore...

...in the meantime I thought it might be nice to let you know that finally, by using your idea, my first project is almost done and worked out far better than expected.

After a few initial hickups (by adapting your code to my personal needs) it's working really nicely now and, what's most important, it handles the data flow from and to HMI in a very simple way and all that without the Nextion library.

Thanks a lot for your effort. Deserves Karma...

PerryBebbington

Hello Orion444,

Thanks very much, much appreciated :)

socalva

Very clear and well explained! Does anyone know if it's possible to move objects during runtime? I'm unable to figure out a way to set X and Y variables dynamically. Any suggestions?

PerryBebbington


Quote
Very clear and well explained!
Thank you :)
Quote
Does anyone know if it's possible to move objects during runtime? I'm unable to figure out a way to set X and Y variables dynamically. Any suggestions?
The basic and enhanced versions do not support moving objects during run time. I'm not sure about the intelligent ones, I have not bought one.

If you look at attributes in the right of the IDE you will see that some of the attributes are in green and some in black. You can change the green ones during run time.

You could create multiple pages with the same objects in different places, or you could create multiple backgrounds with the same images in different places and use the cropped image feature to select the one you want.

PerryBebbington

#54
Oct 20, 2019, 06:28 pm Last Edit: Oct 20, 2019, 06:48 pm by PerryBebbington
Following on from a forum question a few weeks ago I have added to part 4 'Nextion additional features' a method of measuring how long a button has been pressed for. Pressing and releasing a button displays the duration of the press in milliseconds. You could use this to measure the length of a button press, then if it is less than some duration do one thing, it if it more than the duration do something else, giving different responses to short an long presses.
(If it was you who asked the question and you would like credit here then please send me a PM).

I have also identified and fixed the cause of the bug that crashed a Uno or Mega (and possibly others) when the scrolling list page was selected.

Please test these examples and let me know on here if you find any problems or have any suggestions for additional features.

Thank you.

PerryBebbington

I have updated part 4, I have added to Nextion additional features:
  • A simple calculator
  • A means to send the Nextion return codes to the serial monitor.

Enjoy.

Tsjompie

For anyone active in this thread, in particular Perry and Ray: Thanks a million for these details!
This is incredible valuable (as well as the other threads).

Getting the screen to work was a struggle earlier, but now I got the hang of it. In fact I've been building an application containing 5 Nextion pages, communicating from and to the Nextion display successfully.
From the very beginning of my coding I've been using the library Nextion provides.

Question 1:
I noticed Perry and Ray Livingston have alternative approaches, which I'm willing to read and understand.
Unfortunately, I cannot find the alternative library Ray created, some help pointing that out to me is highly appreciated.

Furthermore: I ran into the issue doing everything sequential, using the Arduino loop.
To get around that I'm changing my code into a state machine solution at the moment.
For that to proceed I'd like to get (see) the serial communication content from the Nextion screen to the Arduino. The state machine allows me to read the serial communication, but I need to know what the screen is sending to allow me to filter on incoming data.
My best guess is to use the details the Nextion simulator is giving back, like: 65 00 01 00 FF FF FF or
e\x00\x01\x00ÿÿÿ.

Question 2: Is there a way to change the Nextion.h serial configuration (or elsewhere) in a way my serial window shows the incoming serial data? Or suggest me another way of looking into and understanding the serial communication details the Nextion gives me?

My functionality depends highly on the Nextion screen buttons and sliders. So handing me a suggestion how to filter the serial data solves my showstopper at the moment.

Thank you

PerryBebbington


Quote
For anyone active in this thread, in particular Perry and Ray: Thanks a million for these details!
This is incredible valuable.
Thank you :)

Quote
Unfortunately, I cannot find the alternative library Ray created, some help pointing that out to me is highly appreciated.
I don't understand this, there is a link to Ray's tutorial on the very first post of this tutorial, on the first page of Ray's the files are there, waiting for you to download. I've just checked, the link works, the files are there.


Quote
Is there a way to change the Nextion.h serial configuration (or elsewhere) in a way my serial window shows the incoming serial data?
That (Nextion.h) suggests you are using the Nextion libraries, about which I know next to nothing. Ray might know.

Look at part 4 of this tutorial and download 'Nextion additional features'. In there I've added code to take return data from the Nextion and send it to the serial monitor. This is, of course, designed to work with my methods not the library.


Quote
My functionality depends highly on the Nextion screen buttons and sliders. So handing me a suggestion how to filter the serial data solves my show-stopper at the moment.
That should be simple with my methods; Nextion additional features has 5 pages including buttons and sliders, all working together.

artart

I have found this incredibly helpful:

https://forum.arduino.cc/index.php?topic=634237.0

With it and what I have learned here I have a working project. Thanks Perry!

PerryBebbington


Go Up