Just try a simple program with the mega printing to the serial
Monitor - change the baud rate and print again ( changing the baud rate of the serial monitor too )That will show any problems with the mega side of things .
Then try changing the Nextion board rate with a simple program from the mega - there are examples of doing that , google finds them.
Thanks for the reply Hammy.
I have tried this and the baud changes fine.
I found the problem was with one of the Nextion Arduino library files - it sets the baud to 9600 which is the default for the display.
I have changed the baud rate in the library file and it changes the Arduino rate fine.
I am going to try commenting out the baud in the lib. file and setting it in my programme. This way if I use another display I can use the same library file fo any project and have the speed I want.
Martyn
After read this topic I really unsolved the same problem for my MEGA2560. So here what have I done.
#include "Nextion.h"
#define nexSerial Serial2
void setup {
Serial.begin(9600);
nexSerial.begin(9600); //Nex Default Baud Rate
nexInit();
delay(100); // Wait Nextion Ready
Nextion_BaudRate (115200);
}
void loop {
}
void Nextion_BaudRate (unsigned int baud) {
nexSerial.print("Baud=");
nexSerial.write(baud);
nexSerial.write(0xff);
nexSerial.write(0xff);
nexSerial.write(0xff);
nexSerial.begin(baud);
Serial.begin (baud);
delay(250); //Wait till sending complete
nexInit(); // re-init for new baud rate
}
Hello wucharinton,
Please read 'how to use this forum - please read' (there's a clue in the title), then go back and modify your post in accordance with item #7.
Nextion_BaudRate (115200);
What baud rate have you set your Nextion to in the HMI file?
This code worked for me, but Arduino and Nextion display must be powered at the same time. Bye
Serial.begin(9600);
Serial.print("baud=115200"); //Display nextion prende questo comando solo se acceso in contemporanea con arduino
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
Serial.end();
Serial.begin(115200);
Nextion.txt (249 Bytes)
Cual metodo de subir el baud rate funciono bien?
Buenos Dias danielk20
por favor edita el archivo:= 'NexHardware.cpp'
bool nexInit(void)
{
bool ret1 = false;
bool ret2 = false;
dbSerialBegin(115200); // was 9600 <<<<<<<<<<<<<
nexSerial.begin(115200); // was9600 <<<<<<<<<<<<<
sendCommand("");
sendCommand("bkcmd=1");
ret1 = recvRetCommandFinished();
sendCommand("page 0");
ret2 = recvRetCommandFinished();
return ret1 && ret2;
En el editor 'Nextion' va a 'Preinitialize Event' y entra 'bauds=115200'
Cambia '115200' a su necesario baudio.
Martyn
I know that this is an older thread, but I thought that I'd just share what I do now.
I like to use max baud all the time, 115200.
So, when using the Nextion Editor, on the 1st page, in
PostInitialize Event
I just put
bauds=115200
That forces the display into that baud rate.
When I have a "config" screen for a project, I'll include a number object and on that page's Postinitialize page, I'll update that number object with the current Baud rate:
n0.val=baud // only to display actual current baud rate
I usually put a button there too that when released, executes this code:
bauds=115200
n0.val=baud // only to display actual current baud rate
At one point, on a config screen, I had 4 buttons to cycle through the 3 most used baud rates that I used,
9600
38400
57600
115200
I had done that at one point only because I found that at 115200, I sometimes had communications errors.
I did resolve that as it was a wonky cable.
Now, I always just use 115200 without issue.
Another thing I like to do to always confirm that Arduino is communicating with the Nextion, is I use a small picture object.
I load 3 colored balls (or "LED" images) in 3 different colors.
In my sketches, I always have a timer routine, usually 250ms or 500ms (often 1 second too) so as to not send too much data to the screen at one time and saturate it.
isRunning++; // this is used to only flash the little "running" ball in lower right of screen. This just confirms that there is communications
if(isRunning>2)isRunning=0;
if(currentPage==0) // this counts from 0 to 2. These are the PIC numbers for the indicator
{
Serial2.print((String)currentPageName[0]+".p0.pic=" + String(isRunning) + endChar);
delay(10);
}
I just cycle a counter through the 3 picture numbers and send to the Nextion.
This way, as long as there's communication, the little ball with do its "animation." Any animation or color change is fine, of course.
I should mention that I don't use the Nextion libraries. I used to, but they take up so much memory for nothing.
Anything you can do with their libraries, you can do without.
You just need to use the right syntaxes to send and receive via the Nextion comm channel.
I started doing this when sometimes things didn't go as expected and I wasn't sure if communications broke down again.
Plus, it does add a cute little animation to the screen.
Just some thoughts.
BlondieSL
++Karma; // For the extra information.
I like to use max baud all the time, 115200.
I found that at 57600 Baud I could send enough data to the Nextion to overload the buffer and lose data. At 38400 Baud it's never a problem.
I should mention that I don't use the Nextion libraries.
Sensible! I feel sorry for the people who come here asking questions when they are using the Nextion libraries, pretty much no one offering any help for them here.