Using Perry's Nextion commands where I can (Thanks chap).
Anyone worked out how to prevent the screen flashing white as it changes images?
When I change pages, you get a brief white flash. Tried dimming before changing pages etc (which slow everything down).
Also, I want to show a progress/bar graph horizontally across the screen with a value 0-255.
At first I though of a a slider, but then I could not find the command to move the slider remotely (from the code).
Progress bar maybe. Can't find the command of that either. I'll keep looking.
I tried drawing a coloured box:
This works fine and draws a coloured rectangle: Serial7.print("fill 81,17,81,84,GREEN"); Serial7.print("\xFF\xFF\xFF");
But you can't change the values to be variables... this doesn't work: Serial7.print("fill pos,17,pos,84,GREEN"); Serial7.print("\xFF\xFF\xFF");
Have not managed to get rid of the biblically slow page loading yet...
Changed the baud rate from 9600 to 115200, but can't get it to work above 115200
Serial7.begin(9600); // Comms to the Nextion screen (Nextion screen default boot baud rate)
Serial7.print("baud=115200");Serial7.print("\xFF\xFF\xFF"); // Change the Nextion screen comms baud (Baud= is only a temp change of baudrate. Bauds = Permanently changes it until changed again)
Serial7.end();
Serial7.begin(115200); // Change the proccessor baud rate to match the Nextions new speed
Not sure why. The Nextion datasheet says it can go all the way up to 921600.
They also don't recommend changing it in the Editor now.
Should mention I am currently running it off a Teensy 4.1, hence Serial7
Don't try changing the baud rate by sending to the Nextion the new baud rate, you are asking for trouble. I'm not saying it can't be done, of course it can, but it's one more thing to go wrong. Can you be sure that:
Well I put 'baud=11500' in the Postinitalize Event box in the Nextion editor and that didn't change it (contrary to online advice). Tried the Preinitialization box too.
How do you successfully change it then? You can send bauds=115200 apparently and that will change it forever until you change it back. Baud=115200 is only a temp change that power up.
But... that sounds like an avenue for locking myself out of my own screen
Have to say, not all that impressed with these Nextion screens. REALLY wish there was a better solution out there but there isn't really (that I have found).
Still cannot get rid of this white screen flash and I am pretty sure its the delay of is loading the screen graphic.
Most of my screens are made up of a single PNG file 320x240. Size <100kb with a single text box overlaid. Considering all the processing is 'onboard', its barely faster than sending graphics to a dumb screen over SPI.
Nextion instructions:
Note: baud=38400 will set the current baud rate to 38400 using bauds=38400 will set the current baud rate to 38400 and save this to be new power on default baud rate, persisting until changed. Note: on rare occasions bauds has become lost. With the addition of the Editor Program.s feature, it is now recommended to specify your desired baud rate baud=9600 between declarations and before the page0 instruction and no longer recommending inserting bauds=9600 in the first page’s Preinitialization Event of the HMI.
I don't think the baud rate is the cause of your problem. I have never seen your problem, maybe when you share your code and configuration I'll be able to be more helpful.
I change the baud rate by putting
baud=38400 // For example
In Post Initialisation event, then initialising the baud rate on the controller to match. I've not tried doing it by sending a new baud rate over the serial link partly because there's no need, partly because I can see too many ways for it to go wrong.
I've been very happy with Nextion screens and I continue to use them. Yes, they have their quirks, but that will be true of anything you try. For your interest attached is the biggest Nextion configuration I have ever created and it works flawlessly.
I've not found anything either, nor have I seen anything mentioned by others. Dwin offered me free kit and a small payment to write a tutorial about their kit, but when I looked at it I decided it wasn't for me. It took me a long time and a lot of effort to understand Nextion properly and write a tutorial.
Looking at your HMI Perry (Thanks for that)... you have values in your 'Touch Press Event' window for instance. I do not have anything.
What does that achieve?
I just have buttons with the send component Id box ticked. When Serial data arrives from the Nextion, I check the value of the variable arrived (the id). If the id matches my button number.. then I do what ever is required.
For text boxes, I just write to the text box id. That all seems to work fine.
For instance, on your Heating button... what do these achieve?
va0.val=60
dim=va0.val
tm0.en=1
tm1.en=0
I don't seem to have any issues writing to text, buttons etc.
It's my 56kb images.... flashes a white screen between each page change. No idea why.
Sorry....bit difficult to post my code as it's full of bits I should not post...
But for example, my NEXTION is now set to 115200 in the Nextion editor (not via software).
Page images are all PNG <60kb (My usual method).
This is the setup boot routine I have used many times before:
// ------ Nextion screen setup -------
Serial7.begin(115200); // Nextion screen comms
do {
ScreenDump = Serial7.read();
delay(10);
} while (Serial7.available() > 0); // Clear the Nextion buffer
Serial7.print("rest"); Serial7.print("\xFF\xFF\xFF"); // Reset the Nextion screen
delay(500);
Serial7.print("dim=0"); Serial7.print("\xFF\xFF\xFF"); // Set screen to 0 percent brightness
Serial7.print("cls BLACK"); Serial1.print("\xFF\xFF\xFF"); // Set the screen black
delay(200);
Serial7.print("page "); Serial7.print(0); Serial7.print("\xFF\xFF\xFF"); Page = 0; // Load splash page
Serial7.print("sendxy=0"); Serial7.print("\xFF\xFF\xFF"); // Turn off co-ord reporting
Serial7.print("dim=100"); Serial7.print("\xFF\xFF\xFF"); // Set screen to 100 percent brightness
delay(300);
Serial7.print("page "); Serial7.print(1); Serial7.print("\xFF\xFF\xFF"); Page = 1; // Load DMX Universes number page
delay(500);
Serial7.print(F("dmxno.txt=\"")); Serial7.print(dmxUNI); Serial7.print(F("\"")); Serial7.write(0xff); Serial7.write(0xff); Serial7.write(0xff); // How many DMX universes are available
delay(300);
Serial7.print("page "); Serial7.print(2); Serial7.print("\xFF\xFF\xFF"); Page = 2; // Selection menu (Setup, run, test)
This works fine. But, there is a white flash right to left as the pages change in this routine.
This is the first 'Advanced' screen I have tried. Could that be it?
I used a 7" basic screen last time and it didn't do this (and this code is identical)
The brightness commands was me trying to stop it flashing. Made no difference
My methods are based around sending data to the controller, which then interacts with a nested series of switch / case statements to do whatever it is needs to be done. The same is in my tutorial, but a lot simpler than the example I've given you here. There's no one right way to interact with a Nextion, if you have devised a different way that works for you then all good!
They dim the display on a timeout.
Ah! Good! Yes, that would have cause a problem! I'm pleased you found out what the cause was.
On a more general note, you are going to have problems using delay(), sooner or later it will bite you. You need to learn about millis() for timing, about non-blocking code and state machines. All my examples are based around these concepts. There's no point using a high baud rate for serial if you then stop everything dead by using delays.
Millis() are used as timing throughout the main loop.
Delay is only used in that setup section to hold the pages for a period of time during setup as they step through.
No delays in my main loop or sub-routines!
Does the delay then 'stop' a serial transfer? i though that continued in the background after it's called?