Start a new topic

4 slider - 4 Number to Read ( Noobie )

Hello


I am trying to figure out how to read 4 different number data that controlled by the slider on Nextion. I am using Arduino Uno and as librariy, nextion - master library. 

Basically when i touch the SET button, i need to get these 4 numbers to int x,y,z,t.


Any idea, suggestion ?

HMI
(25.4 KB)

For clarity, is the issue in designing the HMI via the Nextion Editor, or in coding the Arduino?


There are two approaches I can offer (from the Nextion Editor side) - so the first approach

The SET button has an .id number.  Take note of this number

If in the event section of the Editor under Touch Release check Send Component ID

This will cause the Nextion to send

      0X65 0X00 0X02 0X00 0XFF 0XFF 0XFF

(blue 0x00 - page, orange 0x02 - .id, and purple 0x00 - released, 0xFF 0xFF 0xFF - terminator)
Trap this in your code and when it occurs your code needs to request the value of each slider by sending "get h0.val" followed by a 0xFF 0xFF 0xFF terminator (where h0 is the .objname of your slider component).  For each of these requests, the Nextion will return the slider value.

      0X71 0X66 0X00 0X00 0X00 0XFF 0XFF 0XFF  // number value in hex little endian ordered.

Parse each value following each request, and you have your four values.

---

The second approach is to push all the data at once to your MCU inside the SET button event
printh 83 34 3A FF FF FF // S4: user defined code for this event, not used by nextion return codes
print h0.val  // where h0 is the first slider
printh 2C
print h1.val
printh 2C
print h2.val
printh 2C
print h3.val  // where h3 is the fourth slider
printh 2C
printh FF FF FF  // sending the data terminator

Your code would be set that when your defined code is received, you know the next 16 bytes before the terminator are the values of your sliders - no need to send gets as the data is being sent right away.

(I will sit back and see if comma delimited data starts trending now)

error stated above, there is 20 bytes before the terminator

 - I added the printh 2C for the comma after writing "the next 16 bytes" and forgot to change it.

Hello Patrick,


Thank you for your detailed answer. I made it writing this code into SET Button:

 

cov h0.val,va0.txt,0
printh 70
print va0.txt
printh ff ff ff
cov h1.val,va0.txt,0
printh 70
print va0.txt
printh ff ff ff
cov h2.val,va0.txt,0
printh 70
print va0.txt
printh ff ff ff


So i have only one problem to solve, is there any chance to set the sliders' value between 0 and 1. In the new HMI file i attached below, duration should be between 0 and 1 ms.


Is it possible ? 


Thank you

Best Regards

HMI
(1.13 MB)

Lets say that the short answer is no. 


The Nextion is integer based, counting numbers -  0,1,2,3 ...

As the Nextion doesn't have floating point (0.752, 0.2467)


So you need to approach the problem differently.

How many useful setting for the end-user are there really between 0 and 1 ... 10, 20, 180?

As in a clock, there are only 60 seconds ... so 60 useful points.

If I make my slider 0 to 60  with .minval=0 .maxval=60 I can transfer that number in h0.vall

BUT on the MCU side once it is received, if I then divide h0.val by h0.maxval I have then I get 60 values between 0 and 1.  This is assuming the receiving MCU has floating point.


If the receiving MCU did not have floating point support, then h0.val*1000/h0.maxval changes the scale of the 60 point values between 0 and 1000, 1/60th apart on the scale. (0,16,33,50,66 ...950,966,983,1000).


With that little math adjustment, these values only appear to be out of proportion.  But if you look closer:

0µs, 16µs, 33µs ...966µs, 983µs, 1000µs.  So dividing the integer values by 1000000 gives you the µs that you need between 0ms and 1ms.


So change .maxval to number of useful points, and above each of the cov commands in the button use

  h0.val=h0.val*1000/h0.maxval  // where .maxval is the number of segments


Hello Patrick


I got your idea. I'm OK with MCU part. But i have to see these number as ms. So i set the slider values between 0 and 10 and i can see that values as number on the screen. And, i added "0." as text to left side of the number and there we go, i can see something like, "0.1 , 0.2 , ... 0,9" as ms. At MCU part, i divided slider value by 10. Because its actual values are between 0 and 10. The problem is occurs  at when slier value became 10. When it became 10, actually i have to see 1.0. So, i need something like below;


if ( slidervalue == 10){

slidervalue ==0;

t7.txt == 1;

}


Just to see 1.00 ms on the screen.. Like some kind of trick ?


Thank you

Best Regards. 


[SOLVED]


Thank you Patrick, i just solve it by writing this code below the sliders' touch - move feature

 

if(h2.val==10)
{
  t7.txt="1."
  n2.val=0
}
if(h2.val!=10)
{
  t7.txt="0."
}

 

When you ponder a little - all of programming is a trick.  Between what the machine needs, and what we want to represented on the display.

Login or Signup to post a comment