I've have good success using 3.5 inch Basic Nextion and waveform. Just purchased a 10 inch and using the same code and my waveform does not display. I wrote a test program. Any help appreciated.
//Test Waveform on 10 inch
int temp_array_1[480], temp_array_2[480], temp_array_4[480], temp_array_10[480];
String sendThis;
int nextion_delay = 10;
void setup() {
Serial.begin(115200);
Serial2.begin(115200);
delay(4000);
Serial.println("Starting");
sendThis = "rest"; // reset Nextion
writeString(sendThis);
delay(1000);
sendThis = "page 6"; // Jump to page 6 - works OK
writeString(sendThis);
delay(1000);
init_arrays();
sendThis = "page6.s0.bco=57087"; // Changes waveform background - works OK
writeString(sendThis);
delay(1000);
}
void loop() {
Serial.println("Loop");
Serial.println(temp_array_1[0]);
for (int i = 1; i < temp_array_1[0]; i++)
{
sendThis = "add 1,0,";
sendThis.concat(temp_array_1[i]);
writeString(sendThis);
delay(nextion_delay);
Serial.println(sendThis);
sendThis = "add 1,1,";
sendThis.concat(String(temp_array_2[i]));
writeString(sendThis);
delay(nextion_delay);
Serial.println(sendThis);
sendThis = "add 1,2,";
sendThis.concat(String(temp_array_4[i]));
writeString(sendThis);
delay(nextion_delay);
Serial.println(sendThis);
sendThis = "add 1,3,";
sendThis.concat(String(temp_array_10[i]));
writeString(sendThis);
delay(nextion_delay);
Serial.println(sendThis);
}
while (true) {};
}
void init_arrays()
{
sendThis = "cle 1,255"; // clears graph
writeString(sendThis);
delay(100);
temp_array_1[0] = 106; // Number of data points in the array
temp_array_2[0] = temp_array_1[0];
temp_array_4[0] = temp_array_1[0];
temp_array_10[0] = temp_array_1[0];
for (int i = 1; i < temp_array_1[0]; i++)
{
temp_array_1[i] = i;
temp_array_2[i] = 20;
temp_array_4[i] = 40;
temp_array_10[i] = 60;
Serial.println(i);
}
}
//******************************************************************************************************
// Send string to Nextion
void writeString(String stringData)
{ // Used to serially push out a String with Serial.write()
for (int i = 0; i < stringData.length(); i++)
{
Serial2.write(stringData[i]);
}
Serial2.write(0xff); //We need to write the 3 ending bits to the Nextion as well
Serial2.write(0xff); //it will tell the Nextion that this is the end of what we want to send.
Serial2.write(0xff);
} // end writeString functiontype or paste code here
If your code worked on one Nextion I'd expect it to work on another. For test code it looks way too complicated to me and I am struggling to follow what it does. You've not uploaded your HMI file, so I can't look at that for possible problems (you have to put it in a zip file to upload to the forum). I would think there is something different between the HMI file of the one that works and the one that doesn't.
One possible problem is the baud rate, I've had problems above 57600 baud, and for testing purposes it makes sense to use the default of 9600 baud, one less thing to go wrong.
Nothing to do with what you asked but you will have to lose the delays, in answer to the question you've not yet asked: "why is my sketch not responsive?" the answer is "because of the delays".
Thanks for your response. I'll upload the HMI file.
I don't believe it's baud rate, but I'll check it. The first thing the test program does is reset the Nextion, jump to page 6, and then change the background color of the waveform, which are all done correctly.
The delays got left in when using the 3.5 inch displays, which are slower. There I was sending over 700 points and was getting buffer overflow so I added the delay.
The program basically loads some values into arrays and then pushes then out with the add command to four channels.
I was under the impression from your first post that you had a simple Nextion configuration to test, now I know you don't. I suggest you build a simple page with just a waveform and get that working the way you want, then build up to the complete project in small steps, testing at each step.
Which is exactly the problem I had. Get rid of the delay and drop the baud rate to 9600. Get it working and slowly increase the baud rate. I found it works OK with 57600, any faster and I get buffer overflow. I am using a 7" CPT Nextion.
You could also break the code that sends the data into segments so it sends some points then pauses for a few hundred milliseconds and then sends some more. You can do this with a switch case finite state machine and millis() for timing.
I don't need to see your HMI file, concentrate on getting a simple version of what you want working.
I just couldn't believe that 115200 baud wouldn't work. It worked for the 3.5 inch Nextion and what really fooled me is that it worked to change the page number and the background of the waveform. However, you advise was sound. When I changed everything to 9600 baud it's all working.
Thanks for your previous help. Here's the status of my project. My 10 inch Nextion only has a page 0 and it only contains a single waveform. I write a simple program to send 254 points which are simply 1 to 254, so a straight line get plotted. I used 9600 baud and no delays between sending add commands. All's well at this point.
Next I upload to the 10 inch Nextion code for 8 pages plus a keyboard page. This has lots of full screen images, and a scrolling text display on page 0, etc. When I send the same data from my simple program all I get are 12 errors, invalid waveform id or channel number.
Baud rate is 9600. Is the Nextion just too busy with other things like scrolling display to handle receiving and executing add commands?
Hi Theron,
Good to hear from you, thanks for the update.
That sounds to me like you have an error somewhere, I doubt the Nextion is too busy. I would not jump from 1 to 8 pages in one go, get 1 page working, get a second page working, get the 3rd etc. In any case, the Nextion is only doing stuff on the page that's displayed, not the pages you can't see, so it's not too busy with those.
My biggest project has 6 pages, I have no problems like you describe. I did find that it's possible to overflow the buffer sending too much to it. By trial and error I found it works without a problem up to 38400 Baud. Mine is the 7" Enhanced with capacitive touch screen. I don't have a 10" Nextion, so I can't try your code.