Go Down

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

PerryBebbington

I've been trying to put \n in my t0.txt command, but it just brings up a strange inline character rather than putting a line break...any ideas?
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.

jtbennett

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.
Yeah I wasted some time searching around and trying things, nothing to be done there. But, the good news is that your method is working out great now. Apart from the graphic interface, I have most of my coding and variables on the Arduino now and it receives all the user-entered data through the keyboard in bytes before being appended into a complete string. Anyway - thanks for figuring this thing out, I was going mental.

PerryBebbington

#17
May 12, 2019, 10:27 pm Last Edit: May 12, 2019, 10:28 pm by PerryBebbington
Quote
Yeah I wasted some time searching around and trying things, nothing to be done there.
That's a shame, I was rather hoping you'd discovered something I'd missed!


Quote
Apart from the graphic interface.
What are you trying to do? In my first draft of this tutorial I had graphics in it, but I ditched them because having any graphics would make it much harder for someone to adapt the tutorial to different size displays, so the instructions I gave for using a different display to the one I wrote the tutorial for would have become more complex, and I didn't think that was a good idea for a tutorial aimed at someone new to Nextion displays, so I left it out.


Quote
Thanks for figuring this thing out, I was going mental.
My pleasure :)



jtbennett

#18
May 13, 2019, 02:18 am Last Edit: May 13, 2019, 03:58 am by jtbennett
What are you trying to do? In my first draft of this tutorial I had graphics in it, but I ditched them because having any graphics would make it much harder for someone to adapt the tutorial to different size displays, so the instructions I gave for using a different display to the one I wrote the tutorial for would have become more complex, and I didn't think that was a good idea for a tutorial aimed at someone new to Nextion displays, so I left it out.
I have to be secretive about the thing I'm building, but I'll make a thread on this forum so I can show off when it's finished. I think if I said it, someone who's much better at programming would make one quicker than me and ruin my chance at being the first :D. It's a machine for manufacturing musical instrument parts.

The graphics I'm using are just bitmap images (actually nextion editor imports PNGs nicely too) to create all the buttons and icons for the UI, but I draw the backgrounds in manually using fill commands. That sort of thing can all be sent over serial from the arduino too using your method (I use it to do vis commands on elements and page changes etc). Theoretically, you could draw all your background UI elements via serial, but I dunno about creating buttons and pages from nothing.

It never occurred to me to control the images from the serial line - the Nextion editor is good enough for creating and navigating through the pages and elements, and you can do a lot of programming on it, but because the serial communication libraries are pretty much useless and there's absolutely no consideration for global variables, complex projects that require a proper MCU board should definitely use your method and store all their code on the board.



I'll post the a QWERTY keyboard code if it'll be useful around here - it's probably not the most attractive looking code, but but you receive all your user-entered data byte by byte and it's assembled into complete variables / strings / integers / floats on the arduino end.


What I'd really like to do with these Nextions though is work out the font issues...they looks so crusty and the sizing/spacing is all over the place, inconsistent, and no antialiasing. The Nextion font generator is absolute garbage, and they charge about $250 USD for a premade font. There's no repository online to download free fonts, and the only project to create proper fonts is still being worked on...who knows how long it'll take.

PerryBebbington


Quote
The Nextion font generator is absolute garbage
Indeed. Search for zi font editor and you should find a tool to edit them to your own liking.

PerryBebbington

#20
May 13, 2019, 10:44 pm Last Edit: May 13, 2019, 10:46 pm by PerryBebbington
Quote
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:


Code: [Select]
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.

rubendargalan

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.

PerryBebbington


Quote
Hello, thank you very much for this tutorial Perry Bebbington, it is excellent.
Thank you :)


Quote
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.

PerryBebbington

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

jtbennett

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.

PerryBebbington

Nextion needs to put you on the payroll for figuring out how to make their screens useful.
That would be nice :)

chuckhager

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

PerryBebbington

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

Fractoggen


PerryBebbington

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.

Go Up