Go Down

Topic: Using Nextion displays with Arduino (Read 10207 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.

mikastrup

How do I make a logical AND gate so the satment is true when j0.val is between 50 and 75 in the nextoin software?

This is not the right way:
if(j0.val>50&&j0.val<75)
{
  j0.pco=63488
}


Go Up