Start a new topic

print text on nextion

can some one help me please??

how must write the sketch for my nextion with arduino mega


this is the sketch for my rtc temp.

the time and date working

i want the temp value, on my page0 


#include <DS3231.h>

// Init the DS3231 using the hardware interface

DS3231 rtc(SDA, SCL);

void setup()

{

  // Setup Serial connection

  Serial.begin(115200);

  // Uncomment the next line if you are using an Arduino Leonardo

  //while (!Serial) {}

  // Initialize the rtc object

  rtc.begin();

}

void loop()

{

  // Send current temperature

  Serial.print("Temperature: ");

  Serial.print(rtc.getTemp());

  Serial.println(" C");

  delay (1000);



this is the sketch till now, and this will work at my 7'nextion and arduino mega.

how can i print multiple times my Dayofweek "t3"


[code]

#include "Nextion.h"

#include <Wire.h> // Comes with Arduino IDE

#define DS3231_I2C_ADDRESS 0x68

/*

 * Declare a button object [page id:1,component id:11, component name: "b1"].

 */

NexButton b1 = NexButton(3, 12, "b1");

NexButton b2 = NexButton(3, 14, "b2");

NexButton b3 = NexButton(3, 13, "b3");

NexButton b4 = NexButton(3, 15, "b4");

NexButton b5 = NexButton(3, 17, "b5");

NexButton b6 = NexButton(3, 16, "b6");

NexButton b10 = NexButton(2, 11, "b10");

NexButton b11 = NexButton(2, 12, "b11");

NexButton b12 = NexButton(2, 13, "b12");

NexButton b13 = NexButton(2, 15, "b13");

NexButton b14 = NexButton(2, 16, "b14");

NexButton b15 = NexButton(2, 17, "b15");

NexButton b70 = NexButton(2, 14, "b70");

NexButton b72 = NexButton(2, 18, "b72");

NexText t0 = NexText(3, 4, "t0");

NexText t1 = NexText(3, 6, "t1");

NexText t2 = NexText(3, 8, "t2");

NexText t3 = NexText(2, 9, "t3");

NexText t4 = NexText(2, 8, "t4");

unsigned long timed;

unsigned long curtimed;

unsigned long timep;

unsigned long curtimep;

char buffer[15] = {0};

char buffer_temp[10] = {0};

char buffer_hour[10] = {0};

char buffer_week[10] = {0};

char buffer_second[10] = {0};

char buffer_year[10] = {0};

char buffer_dayOfWeek[10] = {0}; //dow DayOfWeek

uint8_t number = 0;

/*

 * Register a button object to the touch event list.

 */

NexTouch *nex_listen_list[] =

{

    &b1,

    &b2,

    &b3,

    &b4,

    &b5,

    &b6,

    &b10,

    &b11,

    &b12,

    &b70,

    &b72,

    &b13,

    &b14,

    &b15,

    &t0,

    &t1,

    &t2,

    &t3,

    &t4,

    NULL

};

/*

 * Button component pop callback function.

 * In this example,the button's text value will plus one every time when it is released.

 */

void b1PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (hour == 23){hour=-1;}

    setDS3231time(second, minute, hour+1, dayOfWeek, dayOfMonth, month, year);

}

void b4PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (hour == 0){hour=24;}

    setDS3231time(second, minute, hour-1, dayOfWeek, dayOfMonth, month, year);

}

void b2PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (minute == 59){minute=-1;}

    setDS3231time(second, minute+1, hour, dayOfWeek, dayOfMonth, month, year);

}

void b5PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (minute == 0){minute=60;}

    setDS3231time(second, minute-1, hour, dayOfWeek, dayOfMonth, month, year);

}

void b3PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (second == 59){second=-1;}

    setDS3231time(second+1, minute, hour, dayOfWeek, dayOfMonth, month, year);

}

void b6PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (second == 0){second=60;}

    setDS3231time(second-1, minute, hour, dayOfWeek, dayOfMonth, month, year);

}

void b10PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (dayOfMonth == 31){dayOfMonth=0;}

    setDS3231time(second, minute, hour, dayOfWeek, dayOfMonth+1, month, year);

}

void b11PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (month == 12){month=0;}

    setDS3231time(second, minute, hour, dayOfWeek, dayOfMonth, month+1, year);

}

void b12PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (year == 99){year=-1;}

    setDS3231time(second, minute, hour, dayOfWeek, dayOfMonth, month, year+1);

}

void b13PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (dayOfMonth == 1){dayOfMonth=32;}

    setDS3231time(second, minute, hour, dayOfWeek, dayOfMonth-1, month, year);

}

void b14PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (month == 1){month=13;}

    setDS3231time(second, minute, hour, dayOfWeek, dayOfMonth, month-1, year);

}

void b15PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (year == 0){year=100;}

    setDS3231time(second, minute, hour, dayOfWeek, dayOfMonth, month, year-1);

}

//===

void b70PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (dayOfWeek == 7){dayOfWeek=0;}

    setDS3231time(second, minute, hour, dayOfWeek+1, dayOfMonth, month, year);

}

void b72PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (dayOfWeek == 1){dayOfWeek=7;}

    setDS3231time(second, minute, hour, dayOfWeek-1, dayOfMonth, month, year);

}

byte DayOfWeek(int y, byte m, byte d) { // y > 1752, 1 <= m <= 12

  static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};

 

  y -= m < 3;

  return ((y + y/4 - y/100 + y/400 + t[m-1] + d) % 7) + 1; // 01 - 07, 01 = Sunday

}

//==

void setup(void)

{ Wire.begin();

    timed = millis();

    /* Set the baudrate which is for debug and communicate with Nextion screen. */

    nexInit();

    /* Register the pop event callback function of the current button component. */

    b1.attachPop(b1PopCallback, &b1);

    b2.attachPop(b2PopCallback, &b2);

    b3.attachPop(b3PopCallback, &b3);

    b4.attachPop(b4PopCallback, &b4);

    b5.attachPop(b5PopCallback, &b5);

    b6.attachPop(b6PopCallback, &b6);

    b10.attachPop(b10PopCallback, &b10);

    b11.attachPop(b11PopCallback, &b11);

    b12.attachPop(b12PopCallback, &b12);

    b13.attachPop(b13PopCallback, &b13);

    b14.attachPop(b14PopCallback, &b14);

    b15.attachPop(b15PopCallback, &b15);

    b70.attachPop(b70PopCallback, &b70);

    b72.attachPop(b72PopCallback, &b72);

}

void loop(void)

{

    /*

     * When a pop or push event occured every time,

     * the corresponding component[right page id and component id] in touch event list will be asked.

     */

    nexLoop(nex_listen_list);

    curtimed = millis();

 

if (abs(curtimed-timed) >= 500){

  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

   number = hour;

    itoa(number, buffer_temp, 10);

    if (number < 10)

    {

        strcpy(buffer, "0");

        strcat(buffer, buffer_temp);

        if (strcmp(buffer, buffer_second))

        {

            t0.setText(buffer);

            strcpy(buffer_second, buffer);

         }

    }

    else

    {

        if (strcmp(buffer_temp, buffer_second))

        {

            t0.setText(buffer_temp);

            strcpy(buffer_second, buffer_temp);

        }

    }

   number = minute;

    itoa(number, buffer_temp, 10);

    if (number < 10)

    {

        strcpy(buffer, "0");

        strcat(buffer, buffer_temp);

        if (strcmp(buffer, buffer_second))

        {

            t1.setText(buffer);

            strcpy(buffer_second, buffer);

         }

    }

    else

    {

        if (strcmp(buffer_temp, buffer_second))

        {

            t1.setText(buffer_temp);

            strcpy(buffer_second, buffer_temp);

        }

    }

       number = second;

    itoa(number, buffer_temp, 10);

    if (number < 10)

    {

        strcpy(buffer, "0");

        strcat(buffer, buffer_temp);

        if (strcmp(buffer, buffer_second))

        {

            t2.setText(buffer);

            strcpy(buffer_second, buffer);

         }

    }

    else

    {

        if (strcmp(buffer_temp, buffer_second))

        {

            t2.setText(buffer_temp);

            strcpy(buffer_second, buffer_temp);

        }

    }

//=========

 /*receive DayOfWeek data*/

    number = dayOfWeek;

    itoa(number, buffer_temp, 10);

    strcat(buffer, buffer_temp);

    strcat(buffer, "");

/*send to Nextion txt5*/

    if (strcmp(buffer_dayOfWeek, buffer))

    {

     t3.setText(buffer_temp);

     strcpy(buffer_second, buffer_temp);

    }

//=========

      memset(buffer, 0, sizeof(buffer));

    memset(buffer_temp, 0, sizeof(buffer_temp));

/*receive day's data*/

    number = dayOfMonth;

    itoa(number, buffer_temp, 10);

    strcat(buffer, buffer_temp);

    strcat(buffer, "/");

/*receive month's data*/

    number = month;

    itoa(number, buffer_temp, 10);

    strcat(buffer, buffer_temp);

    strcat(buffer, "/");

         

/*receive year's data*/

    number = year;

    strcat(buffer, "20"); // geeft 20xx jaartal aan

    if (year<10){ strcat(buffer, "0");}

    itoa(number, buffer_temp, 10);

    strcat(buffer, buffer_temp);

             

/*send to Nextion txt5*/

    if (strcmp(buffer_year, buffer))

    {

     t4.setText(buffer);

    }

timed = millis(); }

}

void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year) {

  // sets time and date data to DS3231

  Wire.beginTransmission(DS3231_I2C_ADDRESS);

  Wire.write(0); // set next input to start at the seconds register

  Wire.write(decToBcd(second)); // set seconds

  Wire.write(decToBcd(minute)); // set minutes

  Wire.write(decToBcd(hour)); // set hours

  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)

  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)

  Wire.write(decToBcd(month)); // set month

  Wire.write(decToBcd(year)); // set year (0 to 99)

  Wire.endTransmission();

}

void readDS3231time(byte *second, byte *minute, byte *hour, byte *dayOfWeek, byte *dayOfMonth, byte *month, byte *year) {

  Wire.beginTransmission(DS3231_I2C_ADDRESS);

  Wire.write(0); // set DS3231 register pointer to 00h

  Wire.endTransmission();

  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);

  // request seven bytes of data from DS3231 starting from register 00h

  *second = bcdToDec(Wire.read() & 0x7f);

  *minute = bcdToDec(Wire.read());

  *hour = bcdToDec(Wire.read() & 0x3f);

  *dayOfWeek = bcdToDec(Wire.read());

  *dayOfMonth = bcdToDec(Wire.read());

  *month = bcdToDec(Wire.read());

  *year = bcdToDec(Wire.read());

}

// Convert decimal numbers to binary coded decimal

byte decToBcd(byte val) {

  return ( (val / 10 * 16) + (val % 10) );

}

// Convert binary coded decimal to normal decimal numbers

byte bcdToDec(byte val) {

  return ( (val / 16 * 10) + (val % 16) );

}

[/code]

[code]

#include "Nextion.h"

#include <Wire.h> // Comes with Arduino IDE

#define DS3231_I2C_ADDRESS 0x68

/*

 * Declare a button object [page id:1,component id:11, component name: "b1"].

 */

NexButton b1 = NexButton(3, 12, "b1");

NexButton b2 = NexButton(3, 14, "b2");

NexButton b3 = NexButton(3, 13, "b3");

NexButton b4 = NexButton(3, 15, "b4");

NexButton b5 = NexButton(3, 17, "b5");

NexButton b6 = NexButton(3, 16, "b6");

NexButton b10 = NexButton(2, 11, "b10");

NexButton b11 = NexButton(2, 12, "b11");

NexButton b12 = NexButton(2, 13, "b12");

NexButton b13 = NexButton(2, 15, "b13");

NexButton b14 = NexButton(2, 16, "b14");

NexButton b15 = NexButton(2, 17, "b15");

NexButton b70 = NexButton(2, 14, "b70");

NexButton b72 = NexButton(2, 18, "b72");

NexText t0 = NexText(3, 4, "t0");

NexText t1 = NexText(3, 6, "t1");

NexText t2 = NexText(3, 8, "t2");

NexText t3 = NexText(2, 9, "t3");

NexText t4 = NexText(2, 8, "t4");

unsigned long timed;

unsigned long curtimed;

unsigned long timep;

unsigned long curtimep;

char buffer[15] = {0};

char buffer_temp[10] = {0};

char buffer_hour[10] = {0};

char buffer_week[10] = {0};

char buffer_second[10] = {0};

char buffer_year[10] = {0};

char buffer_dayOfWeek[10] = {0}; //dow DayOfWeek

uint8_t number = 0;

/*

 * Register a button object to the touch event list.

 */

NexTouch *nex_listen_list[] =

{

    &b1,

    &b2,

    &b3,

    &b4,

    &b5,

    &b6,

    &b10,

    &b11,

    &b12,

    &b70,

    &b72,

    &b13,

    &b14,

    &b15,

    &t0,

    &t1,

    &t2,

    &t3,

    &t4,

    NULL

};

/*

 * Button component pop callback function.

 * In this example,the button's text value will plus one every time when it is released.

 */

void b1PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (hour == 23){hour=-1;}

    setDS3231time(second, minute, hour+1, dayOfWeek, dayOfMonth, month, year);

}

void b4PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (hour == 0){hour=24;}

    setDS3231time(second, minute, hour-1, dayOfWeek, dayOfMonth, month, year);

}

void b2PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (minute == 59){minute=-1;}

    setDS3231time(second, minute+1, hour, dayOfWeek, dayOfMonth, month, year);

}

void b5PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (minute == 0){minute=60;}

    setDS3231time(second, minute-1, hour, dayOfWeek, dayOfMonth, month, year);

}

void b3PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (second == 59){second=-1;}

    setDS3231time(second+1, minute, hour, dayOfWeek, dayOfMonth, month, year);

}

void b6PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (second == 0){second=60;}

    setDS3231time(second-1, minute, hour, dayOfWeek, dayOfMonth, month, year);

}

void b10PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (dayOfMonth == 31){dayOfMonth=0;}

    setDS3231time(second, minute, hour, dayOfWeek, dayOfMonth+1, month, year);

}

void b11PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (month == 12){month=0;}

    setDS3231time(second, minute, hour, dayOfWeek, dayOfMonth, month+1, year);

}

void b12PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (year == 99){year=-1;}

    setDS3231time(second, minute, hour, dayOfWeek, dayOfMonth, month, year+1);

}

void b13PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (dayOfMonth == 1){dayOfMonth=32;}

    setDS3231time(second, minute, hour, dayOfWeek, dayOfMonth-1, month, year);

}

void b14PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (month == 1){month=13;}

    setDS3231time(second, minute, hour, dayOfWeek, dayOfMonth, month-1, year);

}

void b15PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (year == 0){year=100;}

    setDS3231time(second, minute, hour, dayOfWeek, dayOfMonth, month, year-1);

}

//===

void b70PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (dayOfWeek == 7){dayOfWeek=0;}

    setDS3231time(second, minute, hour, dayOfWeek+1, dayOfMonth, month, year);

}

void b72PopCallback(void *ptr)

{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

    if (dayOfWeek == 1){dayOfWeek=7;}

    setDS3231time(second, minute, hour, dayOfWeek-1, dayOfMonth, month, year);

}

byte DayOfWeek(int y, byte m, byte d) { // y > 1752, 1 <= m <= 12

  static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};

 

  y -= m < 3;

  return ((y + y/4 - y/100 + y/400 + t[m-1] + d) % 7) + 1; // 01 - 07, 01 = Sunday

}

//==

void setup(void)

{ Wire.begin();

    timed = millis();

    /* Set the baudrate which is for debug and communicate with Nextion screen. */

    nexInit();

    /* Register the pop event callback function of the current button component. */

    b1.attachPop(b1PopCallback, &b1);

    b2.attachPop(b2PopCallback, &b2);

    b3.attachPop(b3PopCallback, &b3);

    b4.attachPop(b4PopCallback, &b4);

    b5.attachPop(b5PopCallback, &b5);

    b6.attachPop(b6PopCallback, &b6);

    b10.attachPop(b10PopCallback, &b10);

    b11.attachPop(b11PopCallback, &b11);

    b12.attachPop(b12PopCallback, &b12);

    b13.attachPop(b13PopCallback, &b13);

    b14.attachPop(b14PopCallback, &b14);

    b15.attachPop(b15PopCallback, &b15);

    b70.attachPop(b70PopCallback, &b70);

    b72.attachPop(b72PopCallback, &b72);

}

void loop(void)

{

    /*

     * When a pop or push event occured every time,

     * the corresponding component[right page id and component id] in touch event list will be asked.

     */

    nexLoop(nex_listen_list);

    curtimed = millis();

 

if (abs(curtimed-timed) >= 500){

  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

    // retrieve data from DS3231

    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

   number = hour;

    itoa(number, buffer_temp, 10);

    if (number < 10)

    {

        strcpy(buffer, "0");

        strcat(buffer, buffer_temp);

        if (strcmp(buffer, buffer_second))

        {

            t0.setText(buffer);

            strcpy(buffer_second, buffer);

         }

    }

    else

    {

        if (strcmp(buffer_temp, buffer_second))

        {

            t0.setText(buffer_temp);

            strcpy(buffer_second, buffer_temp);

        }

    }

   number = minute;

    itoa(number, buffer_temp, 10);

    if (number < 10)

    {

        strcpy(buffer, "0");

        strcat(buffer, buffer_temp);

        if (strcmp(buffer, buffer_second))

        {

            t1.setText(buffer);

            strcpy(buffer_second, buffer);

         }

    }

    else

    {

        if (strcmp(buffer_temp, buffer_second))

        {

            t1.setText(buffer_temp);

            strcpy(buffer_second, buffer_temp);

        }

    }

       number = second;

    itoa(number, buffer_temp, 10);

    if (number < 10)

    {

        strcpy(buffer, "0");

        strcat(buffer, buffer_temp);

        if (strcmp(buffer, buffer_second))

        {

            t2.setText(buffer);

            strcpy(buffer_second, buffer);

         }

    }

    else

    {

        if (strcmp(buffer_temp, buffer_second))

        {

            t2.setText(buffer_temp);

            strcpy(buffer_second, buffer_temp);

        }

    }

//=========

 /*receive DayOfWeek data*/

    number = dayOfWeek;

    itoa(number, buffer_temp, 10);

    strcat(buffer, buffer_temp);

    strcat(buffer, "");

/*send to Nextion txt5*/

    if (strcmp(buffer_dayOfWeek, buffer))

    {

     t3.setText(buffer_temp);

     strcpy(buffer_second, buffer_temp);

    }

//=========

      memset(buffer, 0, sizeof(buffer));

    memset(buffer_temp, 0, sizeof(buffer_temp));

/*receive day's data*/

    number = dayOfMonth;

    itoa(number, buffer_temp, 10);

    strcat(buffer, buffer_temp);

    strcat(buffer, "/");

/*receive month's data*/

    number = month;

    itoa(number, buffer_temp, 10);

    strcat(buffer, buffer_temp);

    strcat(buffer, "/");

         

/*receive year's data*/

    number = year;

    strcat(buffer, "20"); // geeft 20xx jaartal aan

    if (year<10){ strcat(buffer, "0");}

    itoa(number, buffer_temp, 10);

    strcat(buffer, buffer_temp);

             

/*send to Nextion txt5*/

    if (strcmp(buffer_year, buffer))

    {

     t4.setText(buffer);

    }

timed = millis(); }

}

void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year) {

  // sets time and date data to DS3231

  Wire.beginTransmission(DS3231_I2C_ADDRESS);

  Wire.write(0); // set next input to start at the seconds register

  Wire.write(decToBcd(second)); // set seconds

  Wire.write(decToBcd(minute)); // set minutes

  Wire.write(decToBcd(hour)); // set hours

  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)

  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)

  Wire.write(decToBcd(month)); // set month

  Wire.write(decToBcd(year)); // set year (0 to 99)

  Wire.endTransmission();

}

void readDS3231time(byte *second, byte *minute, byte *hour, byte *dayOfWeek, byte *dayOfMonth, byte *month, byte *year) {

  Wire.beginTransmission(DS3231_I2C_ADDRESS);

  Wire.write(0); // set DS3231 register pointer to 00h

  Wire.endTransmission();

  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);

  // request seven bytes of data from DS3231 starting from register 00h

  *second = bcdToDec(Wire.read() & 0x7f);

  *minute = bcdToDec(Wire.read());

  *hour = bcdToDec(Wire.read() & 0x3f);

  *dayOfWeek = bcdToDec(Wire.read());

  *dayOfMonth = bcdToDec(Wire.read());

  *month = bcdToDec(Wire.read());

  *year = bcdToDec(Wire.read());

}

// Convert decimal numbers to binary coded decimal

byte decToBcd(byte val) {

  return ( (val / 10 * 16) + (val % 10) );

}

// Convert binary coded decimal to normal decimal numbers

byte bcdToDec(byte val) {

  return ( (val / 16 * 10) + (val % 16) );

}

[/code]



my nextion is wired on the arduino mega to pin 

nextion RX ---> Tx2 pin 16 on the mega

nextion TX ---> Rx2 pin 17 on the mega


1 person likes this idea

Hi,

I use this sketch also wants as temperature measurement using a DS18B20.

Unfortunately it's still not been able to make it visible on the screen.

Who can give me a push to resolve this case?

greetings Vic

what dioes your nextion file look like ?

i would like to make that i can set the Day of week on the page of set date

and that the dow of week is also visable, on the frontpage.

the hmi file is for a 7" 


HMI

If anyone have working code of RTC ds3231 with Nextion then please share to me


Which Nextion series Basic or Enhanced


Thanks for prompt reply

I am using 7" Basic version and external RTC (DS3231)

I already have this RTClib, will it work with ds3231?

When it states it works with DS3231 why doubt it?

I stop trying when user stops trying

sorry

just now i check cpp file

there is mentioned for ds3231


thanks for best cooperation

So put 6 numbers on Nextion HMI

declare those 6 number fields in Arduino


NexNumber rYear = NexNumber(0,1,"n0");

NexNumber rMon = NexNumber(0,2,"n1");

NexNumber rDay = NexNumber(0,3,"n2");

NexNumber rHour = NexNumber(0,4,"n3");

NexNumber rMin = NexNumber(0,5,"n4");

NexNumber rSec = NexNumber(0,6,"n5");


After getting your rtc into DateTime dt

  rYear.setValue(2000+dt.yOff);

  rMon.setValue(dt.m);

  rDay.setValue(dt.d);

  rHour.setValue(dt.hh);

  rMin.setValue(dt.mm);

  rSec.setValue(dt.ss);



Now, it's fine Everything is working nice, I want bit changes in the dayOfWeek, it shows in number 1 to 7 but I want the name of day to display like Sat, Sun, Mon etc

I gave you a big boost there.  You must work out some yourself.

RTCs in general handle the DayoftheWeek in numeric.


You are not reading DS3231 Documentation OR the RTCLib code.

I will stop here now.



Login or Signup to post a comment