Start a new topic

Nextion Arduino Code Problem Need Help

Hi i have one problem with Nextion in combination with Arduino.


I have created 3 pages in Nextion. 


1st page shows the clock Hour:Minutes Seconds Here is no press action on the page as i need only to update the clock.


2nd page shows 2 progress bars, one slider and two buttons. Here there are events on 2 buttons  (+ and -) and events on slider.


3rd page is simular to the first one so here is just data which is beeing send from arduino to Nextion. I did not write the code for the 3 page jet.



I have a problem that i can make only 1 page which works at the time . 

As soon as i in loop section start to p0_t7.setText(buffer); set text i get errors on void methods for other elements.


How can i solve my problem? I will upload arduino code + nextion code.

ino
(3.42 KB)
HMI
(683 KB)

This is the code...



#include "Nextion.h"        // LCD Knjiznica
#include <virtuabotixRTC.h> // RTC Knjiznica

//STRAN 0
NexText p0_t0 = NexText(0, 1, "p0_t0");
NexText p0_t6 = NexText(0, 7, "p0_t6");
NexText p0_t7 = NexText(0, 8, "p0_t7");

////STRAN 1
NexProgressBar p1_j0 = NexProgressBar(1, 1, "p1_j0");
NexProgressBar p1_j1 = NexProgressBar(1, 7, "p1_j1");
NexButton p1_b0 = NexButton(1, 10, "p1_b0");
NexButton p1_b1 = NexButton(1, 11, "p1_b1");
NexSlider p1_h0 = NexSlider(1, 2, "p1_h0");
NexText p1_t1 = NexText(1, 5, "p1_t1");
NexText p1_t2 = NexText(1, 6, "p1_t2");
NexText p1_t4 = NexText(1, 9, "p1_t4");

//STRAN 2
NexText p2_t1 = NexText(2, 9, "p2_t1");
NexText p2_t4 = NexText(2, 12, "p2_t4");
NexText p2_t7 = NexText(2, 15, "p2_t7");

NexTouch *nex_listen_list[] =
{  
    &p1_b0,
    &p1_b1,
    &p1_h0,
    &p1_t2,
    &p2_t1,
    &p2_t4,
    &p2_t7,
    NULL
};

//-------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------//
//VARIABLE
char ciljna_vlaga[10] = {0};
uint16_t number_int16;
char buffer[100] = {0};
int MemorySec = 10;
 

// Real Time Clock Module
virtuabotixRTC myRTC(2,12,13); // CLK;DAT;RSK PWM Pin
int Ura;    // Ure
int Min;    // Minute
int Sec;    // Sekunde
int Day;    // Dan
int Month;  // Mesec
int Year;   // Leto

//METODE

void p1_h0PopCallback(void *ptr)
{
    uint32_t number = 0;
    dbSerialPrintln("p1_h0PopCallback");
    p1_h0.getValue(&number);
    utoa(number, ciljna_vlaga, 10);
    dbSerialPrintln(ciljna_vlaga);
    p1_t2.setText(ciljna_vlaga);
}

void p1_b0UpPopCallback(void *ptr)
{
    uint32_t number = 0;
    dbSerialPrintln("p1_b0UpPopCallback");

    p1_h0.getValue(&number);

    number += 5;
    if (number >= 100)
    {
        number = 100;
    }
   
    p1_h0.setValue(number);
    utoa(number, ciljna_vlaga, 10);
    dbSerialPrintln(ciljna_vlaga);
    p1_t2.setText(ciljna_vlaga);
}

void p1_b1DownPopCallback(void *ptr)
{
    uint32_t number = 0;
    dbSerialPrintln("p1_b1DownPopCallback");
    p1_h0.getValue(&number);

    if (number >= 5)
    {
        number -= 5;
    }
   
    p1_h0.setValue(number);
    utoa(number, ciljna_vlaga, 10);
    dbSerialPrintln(ciljna_vlaga);
    p1_t2.setText(ciljna_vlaga);
}


void setup(void)
{   //seconds, minutes, hours, day of the week, day of the month, month, year
    //myRTC.setDS1302Time(07,52,15,02,24,11,2015);
    nexInit();
    p1_b0.attachPop(p1_b0UpPopCallback);
    p1_b1.attachPop(p1_b1DownPopCallback);
    p1_h0.attachPop(p1_h0PopCallback);
    dbSerialPrintln("setup done");
}

void loop(void)
{
 nexLoop(nex_listen_list);
 
 myRTC.updateTime();       // Osvezi vrednosti
  Ura =(myRTC.hours);       // Beri ure
  Min =(myRTC.minutes);     // Beri Minute                                                                                                                                                         
  Sec =(myRTC.seconds);     // Beri sekunde 
 p0_t7.setText("11");

 if (Sec = 10)
 {
  number_int16 = Sec;
  memset(buffer, 0, sizeof(buffer));
  itoa(number_int16, buffer, 10);
  p0_t7.setText(buffer);
 
  number_int16 = Min;
  memset(buffer, 0, sizeof(buffer));
  itoa(number_int16, buffer, 10);
  p0_t6.setText(buffer);
  
  number_int16 = Ura;
  memset(buffer, 0, sizeof(buffer));
  itoa(number_int16, buffer, 10);
  p0_t0.setText(buffer);
}

}


I suggest you to run our first example, it will help you understand.

Login or Signup to post a comment