💬 Real Time Clock Module, LCD Display and Controller Time


  • Admin

    This thread contains comments for the article "Real Time Clock Module, LCD Display and Controller Time" posted on MySensors.org.



  • Thank you for this nice write up.

    I have some "low power" questions:

    • Will the RTC continue to work when the Arduino is set to Sleep?
    • Is there a way to save battery and wake up the Arduino using the RTC?
    • What is the power consumption of a get time request?
    • What is the autonomy of the RTC?

  • Admin

    Yes, the RTC will continue to function while the Arduino is sleeping.

    On the DS3232RTC you can set alarm (which triggers the INT pin of the module). See more info here:
    https://github.com/mysensors/MySensorsArduinoExamples/tree/master/libraries/DS3232RTC



  • I was modify code to Present temp to controller .

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik Ekblad
     * 
     * DESCRIPTION
     * Example sketch showing how to request time from controller which is stored in RTC module
     * The time and temperature (DS3231/DS3232) is shown on an attached Crystal LCD display
     * 
     *
     * Wiring (radio wiring on www.mysensors.org)
     * ------------------------------------
     * Arduino   RTC-Module     I2C Display 
     * ------------------------------------
     * GND       GND            GND
     * +5V       VCC            VCC
     * A4        SDA            SDA
     * A5        SCL            SCL
     *
     * http://www.mysensors.org/build/display
     *
     */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
     
    #include <SPI.h>
    #include <MySensors.h>  
    #include <TimeLib.h> 
    #include <DS3232RTC.h>  // A  DS3231/DS3232 library
    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>
    //#include <LCD_1602_RUS.h>
    
    bool timeReceived = false;
    unsigned long lastUpdate=0, lastRequest=0;
    
    int numSensors=0;
    #define CHILD_ID_TEMP 15
    #define COMPARE_TEMP 1                            // Send temperature only if changed? 1 = Yes 0 = No
    MyMessage msg(0,V_TEMP);
    float lastTemperature;
    
    
    // Initialize display. Google the correct settings for your display. 
    // The follwoing setting should work for the recommended display in the MySensors "shop".
    LiquidCrystal_I2C lcd(0x3F, 16, 2);
    //LCD_1602_RUS lcd(0x3F, 16, 2);
    
    void setup()  
    {  
      // the function to get the time from the RTC
      setSyncProvider(RTC.get);  
    
      // Request latest time from controller at startup
      requestTime();  
      
      // initialize the lcd for 16 chars 2 lines and turn on backlight
      lcd.begin(16,2); 
      lcd.init();                    // Инициализируем экран
      lcd.clear();
      lcd.backlight();               //включаем подсветку
    }
    
    void presentation()  {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("RTC Clock + Temp", "1.1.1");
      present(0, S_TEMP); 
     
      numSensors = 1 ;
    }
    
    // This is called when a new time value was received
    void receiveTime(unsigned long controllerTime) {
      // Ok, set incoming time 
      Serial.print("Time value received: ");
      Serial.println(controllerTime);
      RTC.set(controllerTime); // this sets the RTC to the time from controller - which we do want periodically
      timeReceived = true;
    }
     
    void loop()     
    {     
      unsigned long now = millis();
      
      // If no time has been received yet, request it every 10 second from controller
      // When time has been received, request update every hour
      if ((!timeReceived && (now-lastRequest) > (10UL*1000UL))
        || (timeReceived && (now-lastRequest) > (60UL*1000UL*60UL))) {
        // Request time from controller. 
        Serial.println("requesting time");
        requestTime();  
        lastRequest = now;
      }
      
      // Update display every second
      if (now-lastUpdate > 1000) {
        updateDisplay();  
        lastUpdate = now;
      }
    }
    
    
    void updateDisplay(){
      tmElements_t tm;
      RTC.read(tm);
    
      // Print date and time 
      lcd.home();
      lcd.print(tm.Day);
      lcd.print("/");
      lcd.print(tm.Month);
      lcd.print("/");
      lcd.print(tmYearToCalendar(tm.Year)-2000);
    
      lcd.print(" ");
      printDigits(tm.Hour);
      lcd.print(":");
      printDigits(tm.Minute);
    //  lcd.print(":");
    //  printDigits(tm.Second);
    
      // Go to next line and print temperature
      lcd.setCursor ( 0, 1 );  
      lcd.print("Temp: ");
      lcd.print(RTC.temperature()/4);
      lcd.write(223); // Degree-sign
      lcd.print("C");
      float temperature = (RTC.temperature()/4);
      #if COMPARE_TEMP == 1
        if (lastTemperature != temperature && temperature != -127.00 && temperature != 85.00) {
        #else
        if (temperature != -127.00 && temperature != 85.00) {
        #endif
    
          // Send in the new temperature
          send(msg.setSensor(0).set(temperature, 1));
          // Save new temperatures for next compare
          lastTemperature=temperature;
        }
     
      
    }
    
    
    void printDigits(int digits){
      if(digits < 10)
        lcd.print('0');
      lcd.print(digits);
    }
    
    
    


  • @cadet
    Hi all

    Can I display Temp from other sensor ?

    Thank you
    Andrey



  • Hi, I wanted to know if it was possible to create a node in each room with a temperature sensor and display and send it all to the controller


  • Mod

    @cadet sure you can, in the send() function you can specify a destination ID of the node with the display

    @exagon_46 of course is possible, just add some code to display the temperature (use the examples of the LiquidCrystal_I2C library as reference)



  • good evening

    again a new sketch for the "void receiveTime" function
    (without RTC clock)

    • start synchronization with the controller and regularly for the drift of the arduino.
    • display time and date on an OLED screen
    • error message when a loss of communication with the controller occurs

    a video "https://www.casimages.com/v/RSWTNb-vokoscreen-2022-05-24-19-33-49.mp4.html"

    /*
     * LIBRAIRIE:
     *  MySensors v2    : https://github.com/mysensors/MySensors
     *  TimeLib.h       : https://github.com/PaulStoffregen/Time
     *  SSD1306Ascii.h  : https://github.com/greiman/SSD1306Ascii
     *
     * MATERIEL:
     *    Arduino Uno
     *    -Afficheur OLED 0,96" I2C TF052 / circuit SSD1306.
     *    bus TTLModule RS485
     * 
     * REVISION HISTORY
     *  base de Henrik Ekblad 2013-2015 et autres :)
     *  ajout bus RS485 et OLED
     * 
     * DESCRIPTION
     *  demander Date et Heure au  contrôleur et l'affiche sur ecran OLED 
     *  Request date and time from the controller and display it on OLED screen 
     *  
     *  Connectique i2c:
    *   Arduino :  A4   A5
    *   OLED    :  SDA  SCL
     *  
     */
    //-- The sketch uses 11932 bytes (36%) ----global variables use 839 bytes (40%)-----------
    //-
    //------------ 2022 ----------------------- Fonctionnelle avec MyC et MyS------------------- 
    
      //#define MY_DEBUG                  /*Enable debug prints to serial monitor*/
      #define MY_TRANSPORT_WAIT_READY_MS 3000  /*Timeout (ms) pour mis en Com.(0 pour aucun)*/
      #define MY_NODE_ID 22          /*Node en ID static*/
    
    /* ----- Module RS485 ----*/
      #define MY_RS485                  /*Apl du transport RS485 (protocol?)*/
      #define MY_RS485_DE_PIN 2         /*Cmd DE pin*/
      #define MY_RS485_BAUD_RATE 9600   /*Set RS485 baud rate to use*/
    //#define MY_RS485_HWSERIAL Serial1 /*pour port Serial autre*/
      
      #include "SSD1306Ascii.h"
      #include "SSD1306AsciiAvrI2c.h"
      
      #include <MySensors.h>  
      #include <TimeLib.h> 
    
      #define CHILD_ID 22       /* MyS numero du Node*/
    
      #define I2C_ADDRESS 0x3C                        /*i2c adresse*/
      
      #define RST_PIN -1  // Define proper RST_PIN if required.(oled)
       
      SSD1306AsciiAvrI2c oled;  //type de com oled
    
    //----- MyS ------
        bool timeReceived = false;  
        bool stateCom = false;
        unsigned long lastUpdate=0, lastRequest=0 , lastmillis = 0;
        unsigned long newTime = 0, oldTime = 0, ComTime = 6000;
    
    //---------------- SETUP ----------------------------
    
      void setup()  {  
    
    //--- OLED ----
      #if RST_PIN >= 0
        oled.begin(&Adafruit128x32, I2C_ADDRESS, RST_PIN);
      #else // RST_PIN >= 0
        oled.begin(&Adafruit128x32, I2C_ADDRESS);
      #endif // RST_PIN >= 0
    
        oled.setFont(Adafruit5x7);         /*font Oled*/
        // oled.setFont(font8x8);             //bien 
        // oled.setFont(Verdana12);           //grand
        // oled.setFont(fixed_bold10x15);     //tres grand   
        // oled.setFont(Arial_bold_14);       //grand sympa 
        oled.clear();
        }
    
    //--------------MySensors-------------
    
      void presentation()  {
        sendSketchInfo("Clock", "2.0");
        }
    
    //------------------ LOOP -----------------------
      void loop() {     
      
    // ---- MyS time --------  
      unsigned long now = millis();
      
       if (now-lastRequest > (ComTime)) {    
                    
          timeReceived = false;
          requestTime(receiveTime);   // Request time from controller. 
          lastRequest = now;
          }
        
    //----- Tempo Display Oled ----------
      if (now-lastUpdate > 10000) {  //10secondes
        lastUpdate = now;
       // Serial.print(" test lastmillis------------ display : "); 
       // Serial.println(timeReceived);
        updateDisplay();
        lastmillis = millis();
    
    
    //----- Stat Com ---
        if (timeReceived == 1) {   //En Com Controller stateCom
          ComTime = 480UL*1000UL;    // 480=8 minutes cycles for Control presence controller 
            }
        else  {           // Erreur Com Controller
          stateCom = false;
          ComTime = 60UL*1000UL;    // secondes for attempted reconnection to the controller 
         // Serial.println(" ----*** Erreur Com Controller *** ---- ");
          }
         }
       } //---Loop
    
     // -------------------- MyS --------------------------------
      void receiveTime(unsigned long controllerTime)   {   
       if (receiveTime) stateCom = true ; else stateCom = false;
        newTime = controllerTime;
        timeReceived = true;
        setTime(controllerTime); // apl pour TimeLib.h
        }
        
    //------------Gestion de l'affichage OLED---------------
      void updateDisplay() {
    
        oled.set1X();           //ligne Message
        oled.setCursor(2, 0);
        printStatDay () ;       // affiche jour de la semaine/poster day of the week
        //oled.print(day());
       
        oled.set2X();           //ligne Heures
        oled.setCursor(18,1);
        oled.print(hour());
        printDigits(minute());
        printDigits(second());
         
        oled.set1X();           // ligne jour mois Année / day month year
        oled.setCursor(35,3);
        oled.print(day());
        printDigitsDay(month());
        printDigitsDay(year());
       }
    
    //-------- Day displaying-------
      void printDigitsDay(int digitday) { //function for Day displaying "0" and separator "/" for day/month/year values
        oled.print("/");
          if(digitday < 10)
            oled.print('0');
            oled.print(digitday);
        }
    
    //-------- Time displaying-------
      void printDigits(int digits) {  //function for Time displaying "0" and separator ":" for hour:minute:sec values
        oled.print(":");
          if(digits < 10)
            oled.print('0');
            oled.print(digits);
        }
    
    //------ conversion date en texte (fonction weekday) et statu Com Controller -----------  
      void printStatDay () {   //function for display Day texte
    
        oled.invertDisplay(!(stateCom)); // inverse N/B Oled sur erreur Com
        if(stateCom == true) { oled.print("com  "); }    //com okai
        if(stateCom == false){ oled.print("Error"); }    //com Error
          // oled.print(stateCom);
            oled.print("  ");
          
       
        if(weekday() == 1) { oled.print("dimanche"); }  //Sunday
        if(weekday() == 2) { oled.print("lundi"); }     //Monday
        if(weekday() == 3) { oled.print("mardi"); }     //Tuesday
        if(weekday() == 4) { oled.print("mercredi"); }  //Wednesday
        if(weekday() == 5) { oled.print("jeudi"); }     //Thursday
        if(weekday() == 6) { oled.print("vendredi"); }  //Friday
        if(weekday() == 7) { oled.print("samedi"); }    //Saturday
    
         oled.print(" ");
         oled.print(day());
       }
    
    //-------------------FIN PGM --------------------------
    
    //------------------- INFO -------------------
    

    why open a new post, there is still some space here 🙂


Log in to reply
 

Suggested Topics

  • 162
  • 3
  • 1075
  • 171
  • 61
  • 103
  • 58
  • 28

89
Online

10.6k
Users

10.8k
Topics

111.0k
Posts