Hi from france. i'm sorry if my english is bad
i have a big problem with my arduino and my nextion 3.5".
i need to monitoring my arduino in real time , so i send myNextion.updateProgressBar to my nextion( by nextion master lib)
it works great ,
but if i need to change the page on the nextion and stop the monitoring ( and send component value to arduino to stop myNextion.updateProgressBar .)
the arduino don't recieve the message and continue to refresh bar on the wrong page
i think the problem is the arduino myNextion.updateProgressBar .
if i add a delay ( approx 1sec) on my myNextion.updateProgressBar .
so nextion can send the component value .
i tested clear buffer ( code_c) ,com_stop com star, but it doesn't work.
i hope to be understand.
i make a small videos to see my problem ,
when i'm on live screen , the nextion don't send the value to the page change
Nextion is not an MCU monitor, Nextion is HMI device
HMI - Human Machine Interfacing, input / status.
Nextion is serial device, max 115200 baud, 9600 baud typical.
@9600 baud, max 960 chars per second
Arduino is microprocessor - MCU.
MCU controls your program, send status to Nextion HMI
MCU program should be in control, have priority.
Want to debug and get many messages - use Serial Monitor.
Delay? Bad move. Delay means halt until such time passes.
Arduino MCU or Nextion will do NOTHING during this time
Timers are used to do something 1 second later, and with timer
MCU still processes, your code still runs - when time up on
the timer, what needed to be 1 second later then runs.
Delay means stop everything, stay on this line of code until.
You should plan and strategize with this in mind.
i think the problem is data in the buffer
when i add a delay on my arduino , the nextion can execute all in the buffer and i can send the component value who can it read after by the arduino
i suppose while the nextion buffer isn't empty it can't send value to arduino.
Data in Nextion buffer is max 1024 bit/ 128 bytes.
Command in Nextion buffer needs to be terminated by 3 0xFFs
- it is on receiving the last of these 0xFFs that Nextion processes command
So if data remains in inbound buffer,
it is because the last of terminating 0xFFs not yet received.
If data remains in outbound buffer it would only be because
MCU is not receiving it from port to put in MCU buffer
Delay could certainly cause it to not to be received
When does Arduino move from port to MCU buffer?
- either in beginning of nexLoop()
- end of Arduino loop() after last line before return to top of loop()
- explicit serialEvent2() triggered after last line of loop()
Also ... myNextion.updateProgressBar
this is not IteadLib Arduino Nextion Library
Perhaps ask authors of that library how it works.
yes this is not iteadlib , i have also this lib but i don't understand all and i can't do what i wan't.
in the begining i white my arduino program only with
but i have the same problem .
i'm going to try the official itead lib.
Other things to consider.
If your plan for your MCU sends out to component on HMI page
and you have changed page on Nextion device ...
This means component on HMI page is no longer in memory
unless user specifically sets component to global scope.
Command becomes invalid when component not loaded
- but you would receive this via your Serial Monitor
Nextion Instruction Set sends Return Data when bkcmd is set
So if your code does not display such so you are well informed
- it is because you are ignoring the debugging tools at hand.
Catching the Return Codes sent by Nextion
creating meaningful message based on and send to Serial Monitor
Create Serial.print commands to send to Serial Monitor
Use millis() and microSeconds() so you understand the timing
But from what you describe it is your code creating your issue
Understanding the code is Arduino C++
- programming language
- Arduino compiler
- Arduino IDE
- capabilities and limitations of your MCU.
This requires looking in documentation of each.
Iteadlib code is available to read and modify.
Code you introduce:
serial.print("j0.val="); // missing semicolon?
If this is sent to serial, it goes to Serial Monitor, no?