Uno and Nextion - Odd Behavior

I’m hopeful someone will take a look at my code for what is goofy, I’m a newbie to this language. I have a little experience with VBA so I get most concepts but Serial is new to me and I can not figure out my problem. My code works when the ide serial monitor is running, the nextion refreshes and all the data is accurate. However, with out the IDE monitor running the only two items that update on the nextion are my egt and cht values. Everything else is static. If I fire the IDE monitor the screen flashes and start acting as it should again.

Sorry in advance if my code is messy I’m still learning!

Thanks in advance…

DynoPanel.zip (569 KB)

Hello jwiedmayer,

Thanks for the code but what I meant when I replied to your PM was upload the Nextion HMI file in a zip file and post your code in the forum in code tags </>

Anyway.

Sorry in advance if my code is messy I’m still learning!

You are clearly not new to programming and you clearly have your own style, I would not call it messy, in some ways it’s quite neat (not that I’m the expert).

I’ve had a quick look through, the most obvious thing is you send the data to the Nextion every time round loop(). I have not read enough of your code to get a feel for how often that is, but as you obviously know better than to use delay() all over the place I suspect it’s way too often. There is no point in updating a display more than about 5 times per second as a human can’t read it that fast anyway. You should only send stuff to the display when something changes. Given that you obviously know how to write code I leave it to you to find ways to do this.

If you read my posts you will know I absolutely detest delay(), however, in this case I suggest a simple test; put delay(500); in loop(); to slow it down. If that fixes the problem then the problem is sending the data too fast.

If that doesn’t fix if then I suggest you take your Nextion() function into a test sketch, define all the same variables and just have them incrementing slowly and send the values to the Nextion, and work from there.

You are more likely to get help with code if the code you post is short and illustrates the problem.

The Uno is not the ideal board to use with a Nextion because you are sharing the serial port with the serial monitor and the Nextion. My preferred board is the Nano Every, which has a spare serial port and in my opinion is a far superior board.

Perry,
Thank you for the time you invested in your response. I have been working more on a root cause and I believe I have a power supply or board problem. If I simply plug another usb in that is connected to a wall supply everything works as expected. My power supply that the board and nextion is powered by has 8a at 5v… It or my board must have a problem.

Thank you for the kind words regarding my project I stated with my first Arduino board purchase in 11/20. So I am happy with my work and the challenge is exciting!

I did not like the idea of delay either but understand your point. Perhaps I will put a time check in the loop, like ensure that more than xx time goes by before running the loop. I could not figure out how to attach the hmi to this post so I modified my original. I would always be receptive to any fresh eyes or critiques of that as well!

Thanks Jason

It never crossed my mind you might have a power problem. Some photos of what you have might reveal some obvious mistake affecting power. You should be powering everything from 5V.

I’m a bit confused about your ability level in writing code, what you posted and your existing knowledge of VBA suggests to me you know how to write code, but are not familiar with the quirks of writing C/C++ for a micro-controller, is that about right?

Perhaps I will put a time check in the loop, like ensure that more than xx time goes by before running the loop.

Delaying loop() was only a suggestion as a test, you absolutely should not delay loop() by any means for normal operation, let it run freely.

Do you know about using millis() to schedule things to happen at particular intervals without stopping other things from happening? For updating a display you need to do one of 2 things:

Preferably set flags when something changes then use the flags to tell your display update code to send the updates. The obvious example being for a clock you set a flag every time the seconds counter increments then use the flag to tell the display update function to send the current time to the display.

Alternatively use a millis() based timer to send changes to the display at appropriate intervals. What counts as ‘appropriate’ is going to depend on the project, but keep in mind that a display is for a human to read and if it updates faster than it can be read then it is updating too fast.

All my sample code in my tutorials is written to obey the above principals, so study that.

I could not figure out how to attach the hmi to this post so I modified my original.

I suspect you replied by typing in the reply box below the last answer. Instead if you click the button you should have options for attachments shown. You can go back and edit a post to add attachments, click on /

Perry,
You are correct I'm well versed in dealing with office products and VBA even though I was self taught. I was not even sure Arduino was using C but started to pick up on quirks, like the ;, == <>= etc.. I'm a ME by trade so this programming/EE stuff is just a hobby that I treated like the plague when I was in school. Now I have grown to appreciate it and I enjoy learning about it.

If the delay statement (timer) is on the nextion side do I still need to stop the loop bombardment to it? The way you explained the Mills() function is what I had in my head instead of the delay.

What has me totally baffled is how the Max6675 data is updated all the time on Nextion. The HX711 only updates with the added PS. The data is always correct because I have checked it on the SD card that gets the same feed.

I have yet to put the power supply to the 5V pin instead of Vin on the UNO. I'm a little nervous about that but I think that maybe the problem. If I'm understanding what might be happening with the onboard voltage regulator getting fed 5V. My PS has a ground lug and I have a three wire wire into it. So I think the ground issue is eliminated.

I have attached both layouts I have tried.. Both present with same issue odd behavior with out a USB in power attached.

Layout1.PNG

Layout2.PNG

Layout1.PNG

Layout2.PNG

You caught me about to close my PC and go shopping for food so I will reply properly later.

Please take some photos of your actual project and post those (you might have to reduce the file size, I use Paint to do that, better image processing programs are available).

No worries and I'm not in a hurry! Now for a peek inside the messy workshop project.

Here is a video incase I'm not describing what I'm seeing properly. If you watch the nextion the Torque never moves with pressure on the load cell. However the EGT rises when subjected to heat. Then I simply plug in a usb hooked to a phone charger and the torque.

The 20x4 is on a separate UNO with common PS that is just taking weather measurements.

Problem solved!!! PS to 5V on the arudino and everything works!

Still have the open question about the "refresh" rate on the screen. I have a timer on the Nextion side that is slowing the refresh. Should I also slow the number of inputs out of the arduino loop? Seems like I could stack up into a double delay..

Problem solved!!! PS to 5V on the Arduino and everything works!

I was just about to tell you that from your reply #4, which I didn't really look at earlier.

There you go! You don't need me!

jwiedmayer:
Still have the open question about the “refresh” rate on the screen. I have a timer on the Nextion side that is slowing the refresh. Should I also slow the number of inputs out of the Arduino loop? Seems like I could stack up into a double delay…

I don’t understand the question, sorry.

What does this mean?

I have a timer on the Nextion side that is slowing the refresh.

And this?

Should I also slow the number of inputs out of the Arduino loop?

Read my reply #3 and implement one or other of the strategies suggested, I don’t know which is best in your circumstances.

What does this mean?
Quote

I have a timer on the Nextion side that is slowing the refresh.

I was trying to explain the attachment.

If I'm using the timer event on the nextion side should I still attempt not to send the data from arduino to the nextion on every loop by coding the flags in the loop?

Thanks in advance!

timer.PNG

timer.PNG

If I’m using the timer event on the Nextion side should I still attempt not to send the data from Arduino to the Nextion on every loop by coding the flags in the loop?

Forget the timer events on the Nextion.

Think about how often it is useful to send stuff to the Nextion and write code accordingly. The example I gave was a clock; the seconds increment once per second so the sensible thing is to send that information once per second.

The intervals will be different of different kinds of data, depending on when they change. There are examples of this in my sample code in my tutorial.

From what I’ve seen of your code so far I believe you are more than capable of working out how to do this and I strongly believe in teaching by letting people work it through for themselves. Happy to help if you try something and get stuck but see my sample code for ideas.

Enjoy.

Perry,
Thanks for the guidance. I understand what you mean now and implemented the code as suggested!

PerryBebbington:
All my sample code in my tutorials is written to obey the above principals, so study that.

How do I find your turtorials?

They are at the top of the general electronics and displays sections of the forums.

This topic was automatically closed after 120 days. New replies are no longer allowed.