Go Down

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

Redpiperbob

#60
Nov 22, 2019, 04:17 pm Last Edit: Nov 22, 2019, 04:26 pm by Redpiperbob
Hi Perry
I have just started with the Nextion Displays and I am trying to your demo pro to work without much success. I am using an Arduino Mega and an Enhanced  Nextion  NX4024K032-011
First of all with your sketch as it is on the web site and the nextion library config.h file modified as :-

Code: [Select]
//#define DEBUG_SERIAL_ENABLE
//#define dbSerial Serial
#define nexSerial Serial1

And the Mega to Nextion linked as:-
Nextion RX (yellow) to TX1 (pin18) on the Mega
Nextion TX (yellow) to RX1 (pin19) on the Mega

I can get the page buttons to swop pages and the + and - buttons to change colour when pressed and the slider to slide. But that all.  No time.

If I change the the config.h to :-
Code: [Select]
#define nexSerial Serial
and change your sketch to serial
and the mega to Pins 0 and 1 (TX0)

and open the serial monitor I can see the time , if I press the + or - on the display the digits alter in the serial monitor and I get a message if I move the slider.
Can you help please?
thanks
Bob

PerryBebbington

Hi Bob,
The code you have posted is not from the code I use in the demonstration.
Quote
First of all with your sketch as it is on the web site and the nextion library config.h file modified as :-
My code does not use the Nextion library.

Go back, remove all references to any Nextion libraries and use my code exactly as provided.

Nothing in my code should change the colour of anything. The + and - buttons set the time on the first page.

Redpiperbob

Ok Perry gone back to the start downloaded the hmi and ino and uploaded to Nextion and Mega. Run nothing comes out on the display.. The buttons seem to work and the slider moves.
If I change  all the "Serial1" in the ino to "Serial" then move the display leads to the pin 0 and 1 fo the Mega and open the serial monitor i can alter the time in the monitor by pressing buttons and i get a message if i move the slider.
which proves your program is working fine.
I just dont know what I am dooing wrong
Thanks
Bob

PerryBebbington

Hi Bob,
Don't connect the Nextion to 0 and 1, these are used by the serial monitor. On a Mega you should have blue on 19 (RX1) and yellow on 18 (TX1).

Can you confirm that the Arduino code you are using is the code in:
Using Nextion displays with Arduino part 3 ?
The code there is both shown in code tags in the main message and as a downloadable file at the end of the post.
Also confirm that you have selected Board: Arduino / Genuino Mega or Mega 2560 under Tools in the IDE.

Also confirm that the Nextion HMI file you are using is the one in 2019-07-25 Arduino Nextion demo 43.zip , which can be found at the end of the first part of the tutorial.

In order to check that I've not made any mistakes with my code I have just downloaded both the Arduino code in part 3 and the HMI file from part 1 and uploaded them to a Mega and my Nextion and checked they work.

When you reset the Mega you should see the initial message on the Nextion at the bottom, which reads:

Quote
Nextion demonstration by Perry Bebbington. For support go to https://forum.arduino.cc/index.php?board=7.0
And the clock in the middle should start running from 00:00:00




Redpiperbob

#64
Nov 22, 2019, 09:16 pm Last Edit: Nov 22, 2019, 09:19 pm by Redpiperbob
Hi Perry
I tryied all four TX/RX positions. but i knew that the correct two were 18/19.
Yes I am using the HMI from part one and the INO from part three.
After pluging in and reseting the display does not change.
I think I may have a fualty display. I only have the one I will order a new one tomorrow.

Thanks
Bob

twiereng

Is it possible to send the Nextion a command from an Arduino to set the page?  Sending something like "page 3" doesn't work, although it does work locally on the Nextion.

Thanks,
Theron Wierenga

PerryBebbington

#66
Dec 04, 2019, 02:46 pm Last Edit: Dec 04, 2019, 09:13 pm by PerryBebbington
Hi Theron,
Here is some demonstration code for a Nextion with 5 pages, this changes the pages 0, 1, 2, 3, 4 then back to 0. You can change the number of pages by changing pageCount to however many pages you have. I have set the baud rate to 9600 as that is the default for a Nextion.

Code: [Select]

/* Demonstrates changing pages with the Arduino telling the Nextion which page to change to */
/* Uses the Nextion configuration 'Nextion_additional_features', which can be found in part 4 of this tutorial */
/* Tested on a Mega using serial port 1 connected to a NX4827T043_11 */

#define waitTime 1000       // Delay between each change of page
#define pageCount 5         // Number of pages on the Nextion
#define serialBaud 9600     //Baud rate for serial monitor
#define NextionBaud 9600    //Baud rate for Nextion

void setup() {
  Serial.begin(serialBaud);       // For the serial monitor
  Serial1.begin(NextionBaud);     // For the Nextion
}

void loop() {
  change_page();
}

void change_page() {
  static uint8_t page = 0;    //Current page on the Nextion
  static uint32_t previousMillis;
  uint32_t currentMillis = millis();
  if (currentMillis - previousMillis >= waitTime) {
    previousMillis = currentMillis;
    Serial.print("Page changing to ");      // Prints onto the serial monitor
    Serial.println(page);
    Serial1.print("page ");                 // Tells the Nextion to change pages
    Serial1.print(page);
    Serial1.print("\xFF\xFF\xFF");
    page = ++page % pageCount;
  }
}

vagos21

Hello Perry and everyone else, this has been an amazing useful chunk of info packed for everyone to start using the Nextion :)

I've been playing around with a 4.3" and an arduino for an audio project, and yes it does generate some noise. Does the 470uF capacitor help with the noise, or is it for smoother run of the LCD? Have you investigated further into the noise thing?

Thank you,
Vangelis

PerryBebbington

#68
Dec 13, 2019, 12:01 pm Last Edit: Jan 18, 2020, 05:31 pm by PerryBebbington
Quote
Does the 470uF capacitor help with the noise, or is it for smoother run of the LCD? Have you investigated further into the noise thing?
When I first used Nextion displays I noticed they were interfering with things. Most notable I had a GPS receiver that would only work if I put it a long way from the Nextion. I put a 1 Ohm resistor in series with the supply and used it to monitor the current with an oscilloscope, you can see the result below. As this is measured across a 1 Ohm resistor the peak of the spikes is about 930mA. The second image is the exact same set up but with a 470μF capacitor soldered across the connector on the Nextion. 470μF was the smallest value capacitor that completely eliminated the spikes.





chrisplusian

Thanks for the tutorial! I am just getting started with the Nextion display and I have a question about how you are changing data sent from the display to the screen. You said:

"Unlike the displays, I chose not to use 0xff 0xff 0xff as a terminator for the data sent to the Arduino. Instead I use 0xa5 0xa5 0xa5 as a start indicator followed by 5 bytes. Sometimes the last byte or 2 is just padding to bring the total to 5. You can modify the code to expect more or fewer bytes, or use a different start sequence. The 5 bytes are the page number, the type, the index of the type and 2 data bytes."

 I am trying to understand how you accomplish this? I read through the tutorial and I may have missed it. Could you explain how you are doing so?

Also, I tried to open your .HMI file and  am getting the error message "Wrong Resource file or resource file has been damaged". It could be my computer, but I did go download the Visual studio files you suggested.

If you feel like the issue is my computer ok, but I am able to open other HMI files and create my own without issue, so I thought it may have something to do with the file?


My main question is how to change the serial output from the display to the arduino. Thanks in advance!

mazellan

#70
Jan 13, 2020, 12:45 am Last Edit: Jan 13, 2020, 09:57 pm by mazellan
Hi Perry.

I'm successfully using your method to drive 3 displays. They are set to sleep after 30 seconds and wake on touch. I want to only update one display when it wakes  (It's mainly a clock and temperature display).

On wake, they send :
68 xx xx yy yy 01 FF FF FF  -> touch coordinate
68 xx xx yy yy 00 FF FF FF  -> release coordinate
0x87 0xFF 0xFF 0xFF

They don't register the wake touch as a touch/release event, so I can't use your 8 byte sequence.

Is it possible to integrate reading 0x87 0xFF 0xFF 0xFF  into your read code?

PerryBebbington

#71
Jan 13, 2020, 09:43 am Last Edit: Jan 13, 2020, 09:48 am by PerryBebbington
Hello Chrisplusian

Quote
I tried to open your .HMI file and  am getting the error message "Wrong Resource file or resource file has been damaged". It could be my computer, but I did go download the Visual studio files you suggested.
As a test I have downloaded 2019-07-27 Arduino Nextion demo 43.zip from this tutorial, extracted the HMI file and opened it with V0.59 of the Nextion editor without difficulty, so I am confident that the file on this web site is not corrupted. The Visual studio files are required for V0.59 of the Nextion editor to run. If you have managed to open the editor then it working. If you can't open the HMI file then the problem is elsewhere, but I don't know what to suggest. I am assuming you extracted it from the zip file before trying to open it and that you are using V0.59 (V0.58 works too).


Quote
"Unlike the displays, I chose not to use 0xff 0xff 0xff as a terminator for the data sent to the Arduino. Instead I use 0xa5 0xa5 0xa5 as a start indicator followed by 5 bytes. Sometimes the last byte or 2 is just padding to bring the total to 5. You can modify the code to expect more or fewer bytes, or use a different start sequence. The 5 bytes are the page number, the type, the index of the type and 2 data bytes."
Everything I send from the Nextion is sent using printh, which sends a single hexadecimal byte, giving me complete control over what is sent. When you manage to open the HMI file take a look at touch release event under the buttons, you will see the code I use to send from the Nextion to the Arduino. Note that in the direction Arduino to Nextion the terminator is 0xff 0xff 0xff as there is no way that I know of to change this.





PerryBebbington

Hi Perry.

I'm successfully using your method to drive 3 displays. They are set to sleep after 30 seconds and wake on touch. I want to only update one display when it wakes  (It's mainly a clock and temperature display).

On wake, they send :
68 xx xx yy yy 01 FF FF FF  -> touch coordinate
68 xx xx yy yy 00 FF FF FF  -> release coordinate
0x87 0xFF 0xFF 0xFF

They don't register the wake touch as a touch/release event, so I can't use your 8 byte sequence.

Is it possible to integrate reading 0x87 0xFF 0xFF 0xFF  into your read code?
I've never used sleep in any of my project, so not considered how to use it.
If you look at part 4 of the tutorial (reply #3) there is Nextion_additional_features.zip, download that. In the function HMI_read() (in the tab _01_Middle) I have added code to save Nextion return codes ending with 0xff 0xff 0xff so they can be sent to the serial monitor. You could use this as a way to capture the 'wake' messages and then do whatever you need to with them.

On 2 of my projects I dim the display to a low level if it is not touched for 30 seconds or so, then it goes back to full brightness when touched. I realise this is not the same as sleep, but it does mean I have full control over what happens when the display is touched.

chrisplusian

Hello Chrisplusian
As a test I have downloaded 2019-07-27 Arduino Nextion demo 43.zip from this tutorial, extracted the HMI file and opened it with V0.59 of the Nextion editor without difficulty, so I am confident that the file on this web site is not corrupted. The Visual studio files are required for V0.59 of the Nextion editor to run. If you have managed to open the editor then it working. If you can't open the HMI file then the problem is elsewhere, but I don't know what to suggest. I am assuming you extracted it from the zip file before trying to open it and that you are using V0.59 (V0.58 works too).

Everything I send from the Nextion is sent using printh, which sends a single hexadecimal byte, giving me complete control over what is sent. When you manage to open the HMI file take a look at touch release event under the buttons, you will see the code I use to send from the Nextion to the Arduino. Note that in the direction Arduino to Nextion the terminator is 0xff 0xff 0xff as there is no way that I know of to change this.





I was finally able to open the .HMI screen. I previously had verison 53, and I did the update and apparently it didn't work. I uninstalled and re-installed the nextion editor and for some reason it still installed V53. I used my wifes laptop and installed V59 with no problem. So I couldn't open the .hmi as a result of an older version. Thanks for the tutorial and quick responses!

chrisplusian

I have finally had the chance to sit down with the Code you provided and the HMI. I don't know why, but the display is not actually showing the clock value, however I am able to see the functionality of all the buttons, the slider, and the page concepts. I am guessing it has something to do with the fact I have an Arduino Uno, and am using one of the Basic displays, but I am not positive.

This tutorial has the tools necessary to allow me to develop the application I am creating.

One side note: The Nextion website lists print to be depreciated and it looks like it will add a length attribute, but it seems you can limit the number of bytes sent as well.

Thanks  again for taking the time to put this demo together.

Go Up