Start a new topic

Message Receive from Nextion to Arduino is sometime lost or alterate

Hello,


I'm working with a Nextion 7'' Enhanced screen and arduino nano (few mega on the mail).


I played a lot with all available examples here and on internet. 


The problem I got now is that when the Nextion send a message to arduino, sometime this message is alterate or just lost!


I'm sending ASCII value with print instruction and on the other side I compared this message on a list and it do what it suppose to do. It's was working fine at the beginning with no error or lost message.


I added only one AM2301 temp/hum sensor to the system ( I needed 3 on my system) and the problem start at this time.


Because the temp and humidity value have to be refresh on the screen I have to send it on a loop to the screen. 


Temp and humidity value work perfectly but I think it flooded the serial buss or something like that. 


I tried to add delay, with 2 second delay no lost message but sometime alterate like LighOn instead of LightON. Right at the middle of it! 


The arduino didn't recognize the first message so the command was never executed!


I also tried with milis instead of delay, no change

I tried serial.flush, no change

I tried to clear the serial just before the message was send, no change.


Instead of sending the message several time to make sure it will be receive, how can I manage those message to make sure to receive it correctly? 


The sensor flooded the TX to the Nextion but the RX is not so busy, the light didn't flick a lot. Only when I request a message from the screen.


I didn't find anything similar on the forum but there are a lot of pages, it's possible that I miss some thread. I use the search function a lot too without good result!


Thank you for your help

Stephane Jean




Stephane, 


I am having a very similar issue if not the same. I am using an Arduino Mega, 3.2" Enhanced Nextion touch screen and a DHT22 temp/humidity sensor. The library I am using is from:


 https://github.com/bborncr/nextion


The Nextion is sending a component ID on touch, and an if == statement in an Arduino loop does its  thing. At first, when the code was simple, the component ID was seen by the Arduino on each Nextion button press. As the code got more complex it started to miss the sent component ID and spit out a bunch of "yyy"s (or so that is what the Arduino was seeing in serial anyways". I believe this was  the result of some data colliding or something because of all the "setComponentText, setComponentValue and sendCommand lines I have in my code, one after another. I could be completely wrong about this of course. 


As of this moment I have resolved for the issue mostly by adding a 7ms delay between each of those last 3 commands throughout the code. Any delay less or more did not seem to help much in my situation. 


By using a variable, I also made it so I can easily change it in the future should I find that I need to modify or remove the delay. 

int nexCmdDelay= 7;  

delay(nexCmdDelay);


I'm hoping to find a cleaner way of resolving for this issue without all of the delays. 


Hope this helps you or someone in the meantime. 


Dennis



I should add that there are also 4 analog inputs from a light sensor and 3 soil moisture sensors. I do not think they had any impact on the missed commands, though it may be worth noting. 



Dennis

Thank you for your answer Dennis,


You're right, it's really the setComponentText or setvalue that cause the problem. I made a test yesterday by keeping the sensor running but remove the setvalue to the screen to see the difference and it work fine at this time.


Tonight I'll try to place a 7ms delay after each command to see the difference. Did you place that delay between each Serial.Write too?


The big question now is why it did that, others peoples made bigger projects and I didn't ear about something like that.


Is it possible to plug RX and TX of the screen on 2 different serial channel on Arduino? Commands sent from Arduino to Nextion on one channel and and message receive from screen on another one? I only have Arduino nano for now so i'm not able to test that.


Is it possible to use an interrupt when a message was receive from the screen? So at the exact moment the message will come it will be read.


Thank you for the help of everybody to solve that problem!

Stephane




Stephane, 

I did not use any Serial.write's or Serial.print's in my code so I do not know if the same would have to be done after each of those. I only had to do this with the setComponent and sendCommand lines. Someone else will have to address your other issues as I am new to the Nextion and Arduino, so my knowledge is very limited at this time. Best of luck!


Dennis

Login or Signup to post a comment