Using Nextion displays with Arduino

I draw the backgrounds in manually using fill commands.

2 suggestions:

If you want to draw stuff, or do anything that would require a lot of data to be sent over the serial port, create a button and put all the code to do the drawing or whatever under touch release event for the button. Make the button 1 pixel * 1 pixel and give it the same colour as the background, and place it somewhere on the display where it is out of the way. Then you can use something like:

void HMI_draw_background() {
  Serial.print("click b0,1");
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.print("click b0,0");
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
}

To click the button and the Nextion will execute all the code under the button and do the drawing or whatever.

Alternatively, have a look in part 4 of this tutorial at 'using background images', you can create a background with whatever you like on it. Create 2 almost identical backgrounds with one showing, for example, buttons not pressed, the other showing pressed, and use the cropped image feature to select which one shows when you press the button.

Hello, thank you very much for this tutorial Perry Bebbington, it is excellent. I see that these screens consume a lot of energy (you said that the NX4827T043 consumes 235mA). Do you have any way to decrease its brightness? Or leave it in sleep mode? To try to reduce your consumption. Thank you very much again. A greeting.

Hello, thank you very much for this tutorial Perry Bebbington, it is excellent.

Thank you :slight_smile:

Do you have any way to decrease its brightness?

Look in the Nextion instruction set for 'dim' and 'dims', they control the brightness, and as you expect, lower brightness means lower current consumption. Unfortunately, what does not lower the current consumption is putting dark things on the display, you can make the background black or white and it will consume the same amount of power.

I've modified the HMI files to include automatic display dimming, which happens after 10 seconds of no pressing any buttons.

PerryBebbington:
I've modified the HMI files to include automatic display dimming, which happens after 10 seconds of no pressing any buttons.

Nextion needs to put you on the payroll for figuring out how to make their screens useful.

jtbennett:
Nextion needs to put you on the payroll for figuring out how to make their screens useful.

That would be nice :slight_smile:

For some reason, I cannot find the HMI file. The zip file only has the TFT file.

Hello chuckhager,

Apologies, I uploaded the wrong file when I made some changes a few days ago. Hopefully you will get the correct file now if you download again. If not, please let me know.

Thanks,
Perry

it is really good for me. :o

In 'Using Nextion displays with Arduino part 4' I have added a demonstration of using a scrollable text list. This includes new HMI and ino files for you to download and try.

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.

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.

My pleasure! Glad to be of help and I appreciate the feedback :slight_smile:

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: Instruction Set - Nextion has been updated

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.

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.

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?

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?

No. I have closed the application with no warning message.

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?

So far I have not had this happen.

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?

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

PerryBebbington:
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.