help for display Nextion + Arduino

Hello,
I tried to ask on the forum in Italian but I didn't have any big help. I am a novice with Arduino but I have already created several unpublished projects (iz3zlu.weebly.com), but since my knowledge is rather scarce I stopped myself on a problem.
I built a controller for antenna rotor with Nextion '7 display. Everything works but I would like to implement with a numeric keypad where to write the degrees and sending send the antenna up to that point. Hogià created the numerical testatore and already sends the number of degrees .... but now I do not know what to write on Arduino to make it work. If someone could write me a simple sketch it would make me a great gift. I apologize for Google's English.
I enclose a photo of the message sent by the display.
Thanks a lot.
Lan

Hello Lanfra,
I have already wrote an example for another user in this forum.
It is similar to the one you want and you can find it here:

How to send values and store them on Arduino.

To send the degree value to Arduino (or as you name it "message to send"), you must send it over serial port with a print command (< print > , < printh >, or < prints >).

So when you press the button to send the command from the keyboard, you must send the print command followed by the degrees.

You can send (attach) in a zip file the .HMI file from your Nextion project in this topic and I will try to adapt it to your needs. :slight_smile:

Also, please tell me the minimum and maximum value of the degrees.

Dear Seithan,
I thank you and I attach the HMI file with Wetransfer and the sketch of my project ... Thank you so much.

Wetransfer file HMI
https://wetransfer.com/downloads/45f9a647b991610d4866e8dc10151b0820191019163311/c194fd25ca6c13a0eff23fb71b4af5c220191019163311/6d6ad4

Controller_Rotore_Nextion_buono.zip (2 KB)

The minimum value is 0°, the maximum value is 450° (360° + overlap 90°).

Dear Seithan,
If you were kind enough to explain to me how to enter the direction of rotation to choose based on the distance ...
Arduino commands a shield of relays through two pins, if you were so kind as to make me understand how to write that if the selected degrees are greater than the current ones, digitalWrite (2, HIGH); , instead if the selected grades are smaller than the current ones, digitalWrite (3, HIGH); .
When the selected grades are the same as the current ones then STOP.
You can see a video of my controller on - YouTube and into my website iz3zlu.weebly.com
Many thanks again.
Lan

Dear Lanfra,

Because your project is built using a Nextion library, we can't do as many things as we tought.

In your case, There is no need to make many changes to the Arduino code. You can do it from Nextion.

I added two buttons for CW and CCW at page2 . You can even make them visible or invisible with the < vis > command.

Also, I added a hotspot with some code that runs when you press the "GO TO" button.

covx t0.txt,n1.val,0,0
while(n1.val<n0.val)
{
  click b55,1
  doevents
}
while(n1.val>n0.val)
{
  click b50,1
  doevents
}

At the "GO TO" button, I changed the code a little:

//print t0.txt
if(t0.txt!="")
{
  t0.txt="INV"
}
click m0,1

A numeric component n1 was added to store the converted numeric value of the t0 .

Because I do not have the hardware needed, I can't test it.
Check if this version matches your needs and let me know. :slight_smile:

The modified files:
The .HMI file

Controller_Rotore_Nextion_buono_SEITHAN.ino (7.5 KB)

Many thanks Seithan, but I have a problem opening the .HMI file.
Tells me:
"Wrong resource file or resource file has been damaged"

Thanks for your patience.

Lanfra

just on time i have make chance to .HMI try the new version
@Lanfra because i don't like the command (can cause stack in the while loop)
I make a new version of the HMI with a timer in place of the hot spot and with statement inside.

t0.txt=""
if(n1.val<451)
{
if(n1.val<n0.val)
{
  click b55,1
  //n0.val=n0.val-1 //debug
}
if(n1.val>n0.val)
{
  click b50,1
  //n0.val=n0.val+1 //debug
}
if(n1.val==n0.val)
{
  click b55,0
  click b50,0
  tm0.en=0
}
}
else
{
tm0.en=0
}

here is the new .HMI
Version 2 of .HMI

You really are a Great Seithan ... thanks for the time you dedicate to me.
Unfortunately I can't open your file with Nextion Editor. See error message.

Lanfra:
You really are a Great Seithan ... thanks for the time you dedicate to me.
Unfortunately I can't open your file with Nextion Editor. See error message.

try to update the Editor to 0.58

https://nextion.tech/nextion-editor-ver-0-58/#_section1

or happens to me many times, i forgot to unzip the files (try extract)

YEAAAAH!!! With the new editor the file works fine.....now I begin to study seriously. I'll let you know. Meanwhile, thank you again.
Lanfra

Update.
If I touch the two buttons you created (CW and CCW) the two arduino pins go high (perfect !!) ... But when the software touches the buttons for me, you see the button change color but the Arduino pins don't they go high.
Then I didn't understand if the STOP button (b16) should block the rotation ... if this is his job, he doesn't.
Last thing ... if you exceed the typed degrees I see that the other button is also activated ... I think this causes a problem. for now I'm using two LEDs.
However you did a wonderful job, if you want to correct it when you can. Thank you so much.

Here is the link for the fixed .HMI
.HMI file version 3

remember that you can Hide the button's and the n1 componet that i make to page 2 by uncomment (delete the //) from vis command

//vis n1,0
//vis b50,0
//vis b55,0

to the Preinitialize Event of page 2
I believe that there not any other bugs :slight_smile:

Fill free to ask again

HI Seithan,
Now the CW works perfectly, but the CCW button set by numeric keypad does not activate .... it is activated in debugging of Nextion editor but not in reality. An error in the Arduino sketch?
I apologize and thank you very much for this help. I wanted to implement something and I don't have the appropriate knowledge. My knowledge of Arduino and Nextion stops where I came from alone. I had been asking for help for months and you are the only person who was kind enough to do it.

I installed the sketch and the .HMI file in the controller to test if it works. Unfortunately, if the degree counter moves quickly, sometimes it skips a few numbers, so if you set a number of degrees and skip the one where it should stop, the rotor continues to turn until you touch the stop button. Could it be written that the end point has a range of a few degrees so that if the exact number is exceeded it stops on the next one or a few degrees later?

When you have time and desire ... I don't want to bother you
Lanfra

Thank you Lanfra for your kind words. I really appreciate your kindness.

Do not blame the people that did not help all this time, because they may not have the knowledge or the time to work with something new.

The problem is that I don't have the controller to test the code. It is like writing code in the blind.

I have set the delay in the timer to 400 milliseconds before the timer runs the code again. This means that the value of the current degrees is checked every 400 milliseconds. You can change that by clicking on < tm0 > component and changing the < tim > value at the right side of the screen (Attributes) and adjust it at a value that can catch up the speed of the rotation.

To see if the CCW problem is caused by the sketch, press the button manually with your finger. If Arduino responds, then the sketch is ok.

Due to the code being based on a Nextion Library, the code is not as efficient as it should be and it limits us a lot.

Could you send the schematics and what type of hardware you are using?

Feel free to ask again and freely add a Karma :slight_smile:

Thanks a lot.

Thanks Seithan,
I have attached a drawing of the hardware.
I didn't want to be argumentative saying that for many months I had been asking for help on the forum ... but the fact that after a few hours from my request on the international forum, I received an answer, while on the Italian forum I had little help (not just for this project, but for others), it makes me feel bad. Unfortunately I don't know English and I use Google translator and this is a big problem.
My projects are open source (ham spirit) but I get angry if I can't do something ... I feel stupid.

and then I'm not a kid ... I'm 58 and I'm really struggling :slight_smile: : Smiley-confuse:

I don't know how to write a sketch that makes Arduino work instead of the Nextion library. I understand how it should be theoretically but I can't write it.

For karma .... I've added 3 these days :slight_smile:

Ciao Lanfra

Hi Seithan,
Changing the scan time to 200mS the CW works perfectly. If you could make me understand why the CCW doesn't work, I'd be fine ...
Thanks

I am going to send you a more complex code ( I am working on it). I asked you before and I didn't get an answer "Does the button work when you press it manually?". It is ok however and this is going to help me see where the problem is.

Sorry, I thought I answered you ...
all the buttons work perfectly if you touch them. Instead when you type on the numeric keypad the CW turns red and you hear the relay, instead if you type a position that requires the CCW, the button does not change color and does not work ...

Dear Lanfra,

Sorry for the delayed anwser. I think that I found the bug. It was a typing error in the code for Arduino.

Here is the part that the mistake was at:

//The wrong code:
NexButton b50 = NexButton(2, 25, "b50");//ADDED BY SEITHAN CW a pagina 2
NexButton b55 = NexButton(2, 24, "b55");//ADDED BY SEITHAN CCW a pagina 2
//The correct code:
NexButton b50 = NexButton(2, 24, "b50");//ADDED BY SEITHAN CW a pagina 2
NexButton b55 = NexButton(2, 23, "b55");//ADDED BY SEITHAN CCW a pagina 2

As you can see, the mistake was at the IDs of the button components.

If you could, please try it again. I am sending you the new .ino file. :slight_smile:

-Thanasis Seitanis

Controller_Rotore_Nextion_buono_SEITHAN.ino (7.58 KB)

I have to apologize again, Seithan ... I had already found this error and fixed the same evening you sent me the new sketch, but my old head thought to forget to tell you. The buttons all work if you touch them, only the CCW works by touching it but not with the numeric keypad. Still sorry and thank you for your patience.