Go Down

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

kn4ud

Perry, thank you very much for taking your time to share your knowledge and ability of using the Nextion with Arduino. I have a project I have been struggling with and I am finding this a big help.

PerryBebbington

Perry, thank you very much for taking your time to share your knowledge and ability of using the Nextion with Arduino. I have a project I have been struggling with and I am finding this a big help.
My pleasure! Glad to be of help and I appreciate the feedback :)

jtbennett

#32
Jul 19, 2019, 08:09 pm Last Edit: Jul 19, 2019, 08:42 pm by jtbennett
Nextion has just released a new update for their editor - I downloaded it and it's actually a decent improvement, not what I expected from them. They've added font anti-aliasing - you have to regenerate your fonts again with their generator tool, but it looks fine so far. Just about to do some testing.

Anyway, thought you'd be interested to know if you hadn't seen it yet - I'm wondering what else they've added...will have to google it now.

e: https://nextion.itead.cc/instruction-set/ has been updated

kn4ud

I updated from 53 yesterday. So far no problems other than the ones I cause for myself. I am glad to know I will need to regenerate my fonts. In my older files they appear as they did. some seem to have irregular spacing as they did. I am going to regenerate them and see if they look better.

PerryBebbington

#34
Jul 20, 2019, 09:52 am Last Edit: Jul 20, 2019, 10:06 am by PerryBebbington
Thanks for the info JT. I had been concerned that ITEAD were neglecting the Nextion product as there have not been any updates to the IDE for ages. I've updated the link for downloading the editor at the start of this tutorial.

PerryBebbington

Well, it didn't take me long to find a bug in it! When I close it, instead of it closing gracefully I get the Windows warning message 'HMI has stopped working'. Does anyone else get this?

Watcher

Well, it didn't take me long to find a bug in it! When I close it, instead of it closing gracefully I get the Windows warning message 'HMI has stopped working'. Does anyone else get this?
No. I have closed the application with no warning message.

kn4ud

Well, it didn't take me long to find a bug in it! When I close it, instead of it closing gracefully I get the Windows warning message 'HMI has stopped working'. Does anyone else get this?
So far I have not had this happen.

orion555

Well, it didn't take me long to find a bug in it! When I close it, instead of it closing gracefully I get the Windows warning message 'HMI has stopped working'. Does anyone else get this?
I have the same problem. Doesn't seem to affect the file, but is a bit annoying. But I'm glade the came along with a reasonable update, since the fonts were, to phrase it polite and politically correct, not quite up to standard...

Since I'm already posting here, I have got a couple of questions as well. To mention it up front, I'm a hobbyist programmer (but an extremely stubborn one though ;-)) and relatively new to Arduino (couple of month) and an absolute beginner with Nextion (two weeks). Was a very stony way so far with partly rather blank nerves but I slowly start getting the desired results...

So here are the questions:

Do you, or anybody else out there, know how to address the new xFloat function (sending a float number to the Display)? Couldn't find anything in their instruction set and NexNumber doesn't seem to work. (solved it for now by converting it to .txt)

Sending data to the  MCU with a button function followed by a page change isn't working. Had to place two buttons, one to send the data and the second one to change the page. Almost drove me nuts before I figured out what the problem was. If I remember it correctly did you have the same or a similar problem. What was your solution. Preinitialize? If so, how does it work?

Regards

orion555

If you mean you want to send new line to a Nextion text box then I think you are wasting your time, I don't think they support it. (If I am mistaken and you know for sure that they do support it then I'd like to know). As far as I know the text boxes treat all text as a single line. Where I have needed multiple lines of text I have used multiple text boxes.
I'm not sure if this answer is what you are looking for, but there is a function right below txt_maxl called 'isbr'. Set to true, it allows, if you expand the text box down,  at least text wrap. Not sure (haven't tried it myself) if it can be addressed directly from the MCU with a line break. Also not sure on how to address the new 'multiline' function from the outside.

PerryBebbington


Quote
Do you, or anybody else out there, know how to address the new xFloat function (sending a float number to the Display)? Couldn't find anything in their instruction set and NexNumber doesn't seem to work. (solved it for now by converting it to .txt)
I cannot help with anything related to the Nextion libraries, although there are others on here who might be able to help with them.

I tried:

Code: [Select]
x0.val=4567
Which works.


Quote
Sending data to the  MCU with a button function followed by a page change isn't working. Had to place two buttons, one to send the data and the second one to change the page. Almost drove me nuts before I figured out what the problem was. If I remember it correctly did you have the same or a similar problem. What was your solution. Preinitialize? If so, how does it work?
Assuming you are using my methods look in the sample '2019-06-08 Arduino Nextion demo 43V1.zip' at the start of this tutorial; there are buttons to change the page. The button itself changes the page. On the new page under post initialisation event is the code to tell the Arduino that you have changed pages. The Arduino then responds with whatever data you want on the page. The reason for this is you have to change the page first, then wait for it to initialise then send whatever data you want on it. Putting the request to the Arduino for the data under post initialisation event guarantees that the page will be ready by the time that the data arrives. You can't have a button on page 0 that puts data on page 1 unless the variables on page 1 are global. The variables on page 1 are otherwise out of scope while page 1 is not displayed, so sending anything to page 1 from another page will not work. Sending data to a page before it has had chance to initialise will result in lost or errored data.


PerryBebbington

#41
Jul 22, 2019, 10:10 pm Last Edit: Jul 22, 2019, 10:11 pm by PerryBebbington
Quote
I'm not sure if this answer is what you are looking for, but there is a function right below txt_maxl called 'isbr'. Set to true, it allows, if you expand the text box down,  at least text wrap. Not sure (haven't tried it myself) if it can be addressed directly from the MCU with a line break.
Yes, thanks, aware of that. I think what was being asked for was something that did new line within a text box. The old version certainly does not respond to anything with a new line, it just allows one long line of text which can scroll across multiple lines in the text box, but it is only a single line of text.


Quote
Also not sure on how to address the new 'multiline' function from the outside.
Me neither, please report back!

Oh, and ++Karma; for being so helpful and asking intelligent questions on your first visit to the forum.

jtbennett

My pleasure! Glad to be of help and I appreciate the feedback :)
I hate to bring back an old issue, but something I've just noticed (maybe the update changed something, or I've just not realized for this whole time):

When I send data in the fourth line of the serial out from the nextion (after index #) using "print t0.txt" or "print h0.val", and then I read it with HMI_read_data[4] and print it back out, I'm getting two digits that appear the same each time.

I have an h0 scrollbar with values from 500 to 5000, yet every time I print the value over the serial on release, I get a number between 41 and 53. Is this part of a hex code I'm not decoding properly? I'd like to convert it to a proper int.

PerryBebbington

#43
Jul 25, 2019, 09:21 am Last Edit: Jul 25, 2019, 09:49 am by PerryBebbington
I've read that several times and I am not clear what you are doing. Can you give me both the code on the scroll bar and the corresponding code on the Arduino please?


Code: [Select]
HMI_read_data[4]
Is 1 byte. You need 2 bytes for a range of 500 to 5000.

My heating controller has sliders to control the temperature setting with a range of 0 to 300. That gives me 30 degrees range in steps of 0.1 degree (yes, I know, I probably should be using 0 to 299). That means that the data sent from the sliders takes 2 bytes. The section of code that takes the slider values and updates the set temperature is this:

Code: [Select]
case 1:
       zone[HMI_read_data[3]].settemp = (HMI_read_data[4] | HMI_read_data[5] << 8) * 0.1; //Note 1
       zone[HMI_read_data[3]].flags_HMI |= HMI_text_settemp_update; //Note 2
       break;

Note 1, this is the update for the temperature setting:
Code: [Select]
(HMI_read_data[4] | HMI_read_data[5] << 8)
Combines 2 bytes into one integer, which is the value of the slider setting. I think you need something similar.

Note 2, this is a flag to tell the rest of the program that there has been an update

Although not the cause of your problem, I suggest you don't use that range. I don't know which Nextion you are using, but the highest number of pixels in one direction is 800, so the maximum possible number of unique values from a slider is 800. Any more than that cannot be resolved on the display, so while you might get meaningful values with a slider with a range of 4500, there must, I presume, be gaps in the numbers.

While 500 to 5000 should work from a software point of view, my suggestion would be to use 0 to 4500 and add the 500 in on the Arduino.

In case you are interested, this is another way to combine 2 or more bytes into and integer, or split an integer into bytes, something like:

Code: [Select]
union {
  struct {
     uint8_t data_0;
     uint8_t data_1;
  }
  uint16_t data;
}


If you write to data_0 and data_1 the two bytes will appear in data as a 16 bit int, if you write a 16 bit int to data then you can read the corresponding 2 byes from data_0 and data_1. You can of course expand this for larger ints and for floats.


jtbennett

I used the version in your demonstration file, it worked perfectly - I don't know why I didn't catch that before - I probably got lucky the first time I did it because that slider only goes from 1 to 6.

Go Up