Start a new topic

increments by 1 moved from bug

Hi All

the following is for the display to alter variables of a picaxe then relate the selection back.

The nextion simply sends out code for the picaxe to determine the code and respond by the print t1.txt ect then within the nextion cov t1.txt,nex var.val,0

The selection of the picaxe variables are via the day, date, hot spot ect.

Pressing the relivent var selection button when pressed sends a update nextion variable code and assigns a value to a nextion variable which is then used via the + / - hot spots turning on the nextion timer variable which uses that value to print the relivent code to update the picaxe.

What I am finding is that after the selection ie day the nextion is 1 behind the picaxe value

picaxe code as follows

for inc/dec numeric value

n3:'"D"
       select case marker
     case "^"  hserout 0, ("t1.txt=",QT,#vH)
     case "+"
         vH=vH+1 max 100
     case "-"
         vH=vH-1 min 20       
       end select         
         hserout 0, ("t1.txt=",QT,#vH)          
         return

for day value

n4:'"E"
       
       select case marker
     case="^" if day=0 then
         day=1
          hserout 0, ("t0.txt=",QT,#day)
     else
          hserout 0, ("t0.txt=",QT,#day)
          end if
     case= "+"       
        day=day+1 max 7
        hserout 0, ("t0.txt=",QT,#day)             
     case= "-"      
       day=day-1 min 1
          hserout 0, ("t0.txt=",QT,#day)     
     end select      
         daybcd = day / 10 * 6 + day         
       return

code end

So with the day at 0 pic inc's to 1 sends 1 nextion gets this displays monday all good ; press press to inc day via plus hot spot picaxe sends 2 nextion displays 1 press again pic 3 nextion tuesday 1 behind

any thoughts would be apprechiated

regards

john

 

HMI
(2.21 MB)

okay


So looking at your code, you are stumbling in logic.

You must decide which is in control.  MCU or Nextion.

According to your HMI, you are using a T series Nextion

 - without RTC

Therefore time is coming from MCU side.


Set MCU side to control the number

 - button press should only inform MCU of - or +

   MCU to carry out action

   MCU to update Nextion side shadow variable or t0.txt


OR if Nextion is in control

   then MCU sends datetime in compressed format

Timer event unpacks and sets date


You have code MCU side, Nextion side timer

   in button here, in button there

Too many chefs in the kitchen!


One Question becomes why you don't use

   Nextions natural Return Data (Nextion Instruction Set)

   t0 inform MCU of button Release (simple check box)


If time is coming in from MCU, most likely only once per second

  No need to over burden Nextion every 100ms (10x per second)


But I think when you consolidate the code to only one spot

  Only 1 chef in the kitchen handling the display routine

I think you will find that you aren't stumbling over your code

   to fix now is in too many places for the same "Wednesday"

   all must be changed, one is forgotten - hence your issue

Consolidate, only one spot triggers update

   only one spot to change, none forgotten and success.

Thanks Patrick
I feel the error is occuring as such when I send the update command from the Nextion via the day hotspot
this is updating correctly coverting t0 txt recieved to the day value converting day.val to t1 txt
I feel that the error in the update how I handle the inc decs through the timer variables if statement I need the timer variable to determine the value of the day value if any then display with paraty to the picaxe then inc or dec after that point
I hope I am making sense you can see the effect if you run the code in debug
press the day button t1.txt displays set day (as day.val=0)  press the + button  t1.txt displays 1? as day.val should =0 as there is no responce from the picaxe it should be displaying set day
this effect happends on all buttons if selected first all subsequent buttons selected after the first selection respond as desired. So it would seem that the variable of any button first selected is incrementing by 1 without the command to do so
regards
john

 

Search with Search Bar above

http://support.iteadstudio.com/support/search/topics?term=RTC


Code for updating the RTC have been provided already

- your model doesn't have RTC, but borrow from the concepts

  especially use of the b[.id] component array for string constants

Ask your self if you are over complicating such in your code?


Nextion side

   Number component to hold year

   Text component to hold month value

   Number component to hold day

   Text component to hold dayofweek

MCU side

   byte for yr  (17 portion)

      year+   n0.val=yr+1+2000

      year-    n0.val=yr-1+2000

   byte for mo

      month+   mo+=1 if m0=13 then mo=1  case mo send t0.txt= ...

      month-    mo-=1 if m0=0 then mo=12  case mo send t0.txt=

   byte for da

      day+     da+=  ....

There is little reason why 500 lines of code needed Nextion side


If logic is display side, then no need to have constant sending to MCU

   best is to use a "time setup page" and only send when user is finished


But it is back to which is in control MCU side or Nextion

   whom is telling whom.

Only one should tell, the other should only follow.

Hi Patrick
I have attempted to constructed the code on both sides so that the Picaxe is in control
with the Nextion simply letting it know that it is being requested to be updated by the user
The reason I am using the print commands for the +/- /^ for updating and changing is simply because I do not have the knowledge of either the picaxe or nextion to do the cleaver stuff in handing the data on either side so I have tried (long winded coding) in terms that I understand (obviously not what the unit understands) it does handle the numeric side well its just the coversion to t1 txt via day val var .
I have the unit constructed and working using DS1307 for the time and HTU21D for temp/rh on a update display once per minute routine
So after reading your comments I need to strip down the button pressed commands with the update handled in the timer variable.
I must say I am very impressed with the product and the support.
thank you for your comments
regards
john
works lovely 

 

Login or Signup to post a comment