Refresh rate issue Arduino -> Nextion

Hello,

I'm working on a Nextion (NX8048P050-011) and Arduino Mega project. I'm receiving data from a Honda ECU via RX and TX at a baud rate of 38,400 and sending it to my Arduino Mega. Each value coming from the ECU is stored in a variable, which is then sent to the Nextion display at a baud rate of 9,600.

Everything works perfectly, but unfortunately, the refresh speed is too slow. To improve it, I tried changing the baud rate in my Arduino code from 9,600 to 38,400. I also added baud=38400 in the Preinitialize Event of the Nextion. However, the screen no longer receives any data.

Can you help me pls....

Your question does not relate to any particular version of the IDE, so I will move your post to a more suitable forum section.

Please read the sticky post at the top of each form section before you post, so you know if it's a suitable section for your question.

@PerryBebbington you know about Nextion displays, can you help?

I'm not going to have access to my PC for a couple of weeks so I can't run any code or check your HMI file.

Have you tried putting the baud rate change in the post initialisation event? It's a long time since I've configured a Nextion and I can't remember exactly where it goes.

Have you tried other baud rates?

Have you tried the examples in my tutorial? Use one of those and try changing the baud rate, get that working then use what you learn on your code.

My advice is to write something simple that sends simple data to your Nextion at the baud rate you want.

I'm reluctant to ask for your complete code because I imagine it's complex making finding the problem difficult. Even if I could run it I can't simulate the ECU data.

Try setting the baud rate in the program.s tab.

Looking at the schematic you forgot to post it appears you have two serial ports in use. Looking at the non posted code you confused the consol with the target. If I am wrong post the needed information.

That seems good enough for me that he has the two serial ports worked out correctly.

Hello, thank you for your responses. Below is the Arduino code used. For confidentiality reasons, I will only show you part of the code: #include "EasyNextionLibrary.h"


 #include <math.h>

// Constants and variables
const int baudrate = 38400;
const int REFRESH_TIME = 1; // Refresh time in milliseconds
unsigned long refresh_timer = millis();
unsigned long last_datalog_time = 0;
unsigned long current_time;
const int Timeout = 40;

EasyNex myNex(Serial1);

bool IsAvailable = false;

// Variable pour éviter les envois répétitifs à Nextion
static int lastValue = -1;

void setup() {
    Serial2.setTimeout(20);
    Serial2.begin(38400);
    Serial.begin(baudrate);
    Serial1.begin(baudrate);
    myNex.begin(baudrate);





Tonight, I will make an example in Nextion Editor. I tried setting `baud=38400` in Preinitialize and in each timer event, but nothing is displayed. You will have everything as soon as I get back from work. Thanks in advance for your help!

When I display only one variable on the Nextion with 9600 baudrate, the refresh rate of the variable is very good. Could it be due to the baud rate speed or the capacity of my Arduino? :thinking:

Did you read post #4 about the baud rate in the Program.s tab.

When you first open your project in the Nextion editor you should see a Display and a Program.s tab. What is the information in the Program.s tab?

Yes, I tried doing the different tests from this tutorial. In the Nextion Editor, under the 'Program' tab, I set the baud rate to the desired frequency. I tested at 115200 and 38400.

I also added a rule that changes the values only if the previous one is different. It improves things a bit, but it doesn't completely solve the problem.

But for you my code is Exact ?

I also noticed that setting an image as the background slows down the refresh time by a factor of 10.

I think you are writing to the Nextion every pass through loop. I think you need to slow this down even with the faster baud rate. What happens if you send data to the Nextion every 100 ms?

Yes, that's right. My mistake might have been setting 50 ms for all the variables. Knowing that for some variables like ECT or IAT, I can easily set 200 ms. :wink:

I solved the refresh rate issue using the following two approaches:

  • I moved the Nextion background to another page and set it as global to prevent constant refreshing.
  • In the Arduino code, I made sure the value is updated only if it differs from the previous one.
  • I increased the delay from 50ms to 200ms for variables with less impact.

Thank you for your help! I changed the title so that it better matches the issue. Thanks, everyone!