Using Nextion displays with Arduino problem

I am new to Nextion and Arduino and seem to jumped into the “deep end”. (My prior programming experience was with Fortran 4 using punch cards. (Guess that dates me in the steam driven computer age!)

I have been trying to set up an Arduino Uno controller with a Nextion 7" display to control a number of motorised blinds. I seem to have most of it sorted out except for one thing.

My plan is to use the Nextion to set up basic control parameters (duration of motor operation, time to start etc.)

I can get the communication of button pushes to the Arduino and response with writing a variable back to Nextion and displaying it.

However, to complete this, I need to have the Arduino read either a Nextion Variable or Nextion Number and then perform simple maths on it.

Ive spent(wasted) a number of days trolling the internet trying various ways to do this, but nothing I try seems to work. Below part of the code for the latest trial

#include <Nextion.h>

float ArdClockSpeed = 1000; // Number of clock cycles per second

NexNumber ClockSpeedDisp = NexNumber (1,32,“ClockSpeedDisp”); // Set Clock Speed

NexTouch *nex_listen_list =
{

&ClockSpeedUP,
&ClockSpeedDN,
NULL // String terminated
};

void ClockSpeedUPPushCallback(void *ptr) // Press event for button UP
{
ArdClockSpeed = ClockSpeedDisp;
}

This gives me the following error…“error: cannot convert ‘NexNumber’ to ‘float’ in assignment”

Changing the declaration form float to int doesn’t help, neither does using a Nextion Variable instead of a number.

HEEEEEEELLLLLLLPPPP!

Hello rickives, Welcome to the forum.

I note that you originally posted this question at the end of my tutorial, I asked the moderator to move it to its own thread; thank you moderator.

If you have read my tutorial you will see I don't use the Nextion libraries and can't help with them, I note that you are using them. While there might be a solution involving the Nextion libraries, my approach without them would not involve any numbers on the Nextion at all. I would keep all numbers on the Arduino and do any maths there, then send the result to a Nextion text box as text, not as a number. So, you press a button or move a slider or whatever it might be on the Nextion, send that event to the Arduino, perform any actions you need on the data and send the result back to be displayed. If you look at my example with the clock then the buttons for setting the time work this way.

Please will you also read 'how to use this forum - please read' then go back and modify your post in accordance with the instructions in section #7.

Thanks for the quick response and the guidance on the forum. Unfortunately when I try to modify the post, the toolbar mentioned in the guide doesn’t come up.

I went through your tutorial at some length and can see how you have done it to keep all numbers in the Arduino. However, in doing it the way you describe, I end up with about 50+ buttons communicating with the Arduino Uno and some complex math to ensure that the various commands for each blind dont interfer with each other. This is already giving me warnings of low memory available.

Doing some basic math in the Nextion gives me the ability to greatly reduce and simplify the code in the Arduino Uno like the following.

In the Nextion, through button pushes I generate a single number for each blind, where the sign indicates the direction up or down, and the magnitude indicates the time to run the motor. i.e.

-20 - run the blind motor for 20 seconds down
+40 - run the blind motor for 40 seconds up.

Each button push on the Nextion triggers a single hidden button that triggers the Arduino to act on the above number

In this way, I only need to have the Arduino reacting to a single button and one number for each blind.

Thanks for the quick response and the guidance on the forum. Unfortunately when I try to modify the post, the toolbar mentioned in the guide doesn’t come up.

Beneath your post (only your post, not mine or anyone else’s) at the bottom right you should have ‘quick edit’ and ‘More’. More has a drop down list which has ‘Modify’. Select ‘Modify’. You should have your post in an edit window with a tool bar across the top. The left hand icon on the tool bar should be </>, that’s the one for code tags. Select your code, click that icon. Click save.

If you really don’t have a tool bar then I have no idea, sorry.

However, in doing it the way you describe, I end up with about 50+ buttons communicating with the Arduino Uno and some complex math to ensure that the various commands for each blind dont interfer with each other. This is already giving me warnings of low memory available.

This is where it gets difficult to comment without seeing your code, and even if I see it I confess to not being very good at reading other people’s code. Usually on here I leave sorting out code problems to other people unless it’s fairly simple or the problem is obvious. My feeling is that 50 variables should not be a problem for even the smallest Arduino. Have you written functions to do the maths, so you call one function to do a particular thing, rather than repeating the same code multiple times?

If you really want your Arduino to ask the Nextion to return the value of a variable or number try using ‘get’. I’ve not tried it myself. However, the problem with using ‘get’ is that it won’t send the value in way my code was designed to handle, so you are on your own there. The other problem with doing it this way, and one big reason I would not even attempt to do it, is that if the Arduino has to ask the Nextion for a value, then to keep the whole thing responsive to user actions the Arduino has to keep asking, probably at least 20 times per second, every second, all day long. That puts a big demand on the Arduino and the serial port. If you don’t have the Arduino doing this then when a user presses a button (or whatever) nothing will happen until the Arduino asks for the data.

A suggestion might be that after you perform maths on the Nextion the next thing is does is to send the result, would that work for you?

I think you have the following choices:
Use my methods with all the maths on the Arduino, if the Arduino you have isn’t powerful enough buy a more powerful one, but before you do that optimise your code. I would think ALL code can be optimised, especially if you are new to this. If you use my methods I can continue to offer help.

Use the Nextion libraries, my methods are not designed to work with the libraries, maybe you or someone can combine them to work together but I certainly would not attempt this. I can’t help with Nextion libraries but if you do use them then see Ray Livingston’s version of them, he has fixed a load of bugs. There is a link from my tutorial.

Design your own method of communicating with the Nextion, that’s what I did! If you design your own method you can fix whatever short committing you see in my methods or the libraries.

Good luck!

"A suggestion might be that after you perform maths on the Nextion the next thing is does is to send the result, would that work for you?"

That would work perfectly, but I have no clue how to do this. I have been able to communicate button presses, but not send a variable.

Can you steer me in the right direction on this?

As correctly said through this forum, the Nextion documentation isn't exactly easy to use.

Your help is greatly appreciated.

That would work perfectly, but I have no clue how to do this. I have been able to communicate button presses, but not send a variable.

I can't really answer you unless you give me some idea of what you are doing on the Nextion.

If you look at the example of a creating a scrollable list (part 4 of the tutorial) I have shown how to use 'click' to trigger something to happen. You might be able to adapt that.

Alternatively adapt my code and put it at the end of a calculation to send the result.