DS1307 Module Serial Monitor to LCD Module

Hello Everyone,

There is a problem with my software. As of now, I am currently working on a project using an Arduino Uno board, an LCD Module and the DS1307 module. It's intended goal is to initially display "Watch Clock" and then after a certain period of time it displays the time that is get from the Serial Monitor using the DS1307 Module. Currently, it only displays the initial "Watch Clock" text that I have set up in my void setup(). Maybe someone can help me with this predicament and help me understand something I am not. This is my code.
#include <LiquidCrystal.h>
#include <DS3232RTC.h>
#include <Streaming.h>

#define buttonPin_1 8

const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;

LiquidCrystal lcd (rs, en, d4, d5, d6, d7);


DS3232RTC myRTC;


void setup() {
  lcd.begin(16, 2);

  Serial.begin(9600);

  lcd.setCursor(4, 0);


    Serial << F( "\n" __FILE__ "\n" __DATE__ " " __TIME__ "\n" );
    myRTC.begin();

    setSyncProvider(myRTC.get);
    Serial << F("RTC Sync");


    Serial << endl;


    lcd.print("World Clock");

    pinMode(buttonPin_1, INPUT);
}

void loop() {
   static time_t tLast;
    time_t t;
    tmElements_t tm;


  
    // check for input to set the RTC, minimum length is 12, i.e. yy,m,d,h,m,s
    if (Serial.available() >= 12) {
        
        int y = Serial.parseInt();
        if (y >= 100 && y < 1000)
            Serial << F("Error: Year must be two digits or four digits!") << endl;
        else {
            if (y >= 1000)
                tm.Year = CalendarYrToTm(y);
            else    // (y < 100)
                tm.Year = y2kYearToTm(y);
            tm.Month = Serial.parseInt();
            tm.Day = Serial.parseInt();
            tm.Hour = Serial.parseInt();
            tm.Minute = Serial.parseInt();
            tm.Second = Serial.parseInt();
            t = makeTime(tm);
            myRTC.set(t);   // use the time_t value to ensure correct weekday is set
            setTime(t);
            Serial << F("RTC set to: ");
            printDateTime(t);
            Serial << endl;
            // dump any extraneous input
            while (Serial.available() > 0) Serial.read();
        }
    }

    t = now();
    if (t != tLast) {
        tLast = t;
        printDateTime(t);
  
     printTimeLCD(t);

        Serial << endl;
    }
  
  
}

void printDateTime(time_t t)
{
    printDate(t);
    Serial << ' ';
    printTime(t);
}

// print time to Serial
void printTime(time_t t)
{
    printI00(hour(t), ':');
    printI00(minute(t), ':');
    printI00(second(t), ' ');
}

// print date to Serial
void printDate(time_t t)
{
    printI00(day(t), 0);
    Serial << monthShortStr(month(t)) << _DEC(year(t));
}




// Print an integer in "00" format (with leading zero),
// followed by a delimiter character to Serial.
// Input value assumed to be between 0 and 99.
void printI00(int val, char delim)
{
    if (val < 10) Serial << '0';
    Serial << _DEC(val);
    if (delim > 0) Serial << delim;
    return;
}


void printTimeLCD(time_t t){
  if(Serial.available() && digitalRead(buttonPin_1) == HIGH){
    delay(100);
    
    lcd.clear();
    lcd.setCursor(4, 0);

    while (Serial.available() > 0) {
      lcd.setCursor(0, 1);
      lcd.write(Serial.read());
      
    }
  }
}`Use code tags to format code for the forum`

type or paste code here

Welcome! I cannot figure out what your question is. I am not going to build a project to test it. First you need to clarify your question by telling us what you expect the software to do and what your getting that is not correct.

Why are you using the DS3232RTC library instead of the DS1307RTC library?

#include <LiquidCrystal.h>
#include <DS3232RTC.h>
#include <Streaming.h>
.
.
.
DS3232RTC myRTC;

Is there some reason that you want to disable the time display on the LCD when the Serial receive buffer is empty? You are not even attempting to display the time, only the characters read from Serial.

void printTimeLCD(time_t t) {
  if (Serial.available() && digitalRead(buttonPin_1) == HIGH) {
    delay(100);

    lcd.clear();
    lcd.setCursor(4, 0);

    while (Serial.available() > 0) {
      lcd.setCursor(0, 1);
      lcd.write(Serial.read());

    }
  }
}
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.