Problem with DS1302 display in monitor

I got DS1302 library at this webpage and put it to Arduino library file path.
(Electronics - Henning Karlsen).

Because I am a programming beginner, it’s my first time to use DS1302.
So I use the Examples (DS1302_Serial_Easy) to demo and learn.

I found a problem with Serial Monitor, the time displays not synchronous and not continuous. (Time is not changing with seconds.) :cold_sweat:

First, please read Nick Gammon's two posts at the top of this Forum. They provide guidelines that will help you get the most help possible. Second, post your code, not JPG's of it. Use the code tags as explained in Nick's posts. While I can't tell for sure because you didn't post your code, the DS1302 presents its data in BCD format.

Thank your reply, I provide more detail.
I download the DS1302 library (attached file) and collected together into a library folder.
I have tried working through the examples (File Menu → Examples> DS1302 > DS1302_Serial_Easy).

The demo( DS1302_Serial_Easy) code is as below:

// DS1302_Serial_Easy (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// A quick demo of how to use my DS1302-library to 
// quickly send time and date information over a serial link
//
// I assume you know how to connect the DS1302.
// DS1302:  CE pin    -> Arduino Digital 2
//          I/O pin   -> Arduino Digital 3
//          SCLK pin  -> Arduino Digital 4

#include <DS1302.h>

// Init the DS1302
DS1302 rtc(2, 3, 4);

void setup()
{
  // Set the clock to run-mode, and disable the write protection
  rtc.halt(false);
  rtc.writeProtect(false);
  
  // Setup Serial connection
  Serial.begin(9600);

  // The following lines can be commented out to use the values already stored in the DS1302
  rtc.setDOW(FRIDAY);        // Set Day-of-Week to FRIDAY
  rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  rtc.setDate(6, 8, 2010);   // Set the date to August 6th, 2010
}

void loop()
{
  // Send Day-of-Week
  Serial.print(rtc.getDOWStr());
  Serial.print(" ");
  
  // Send date
  Serial.print(rtc.getDateStr());
  Serial.print(" -- ");

  // Send time
  Serial.println(rtc.getTimeStr());
  
  // Wait one second before repeating :)
  delay (1000);
}

My question is that time displays not synchronous and not continuous in Serial Monitor.

DS1302.zip (71.8 KB)

aa.jpg

my problem is when i open the code and verity, it high lights

DS1302RTC RTC(27, 29, 31);

Not to sure what to do?

Dave…

// DS1302_LCD (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// Adopted for DS1302RTC library by Timur Maksimov 2014
//
// A quick demo of how to use my DS1302-library to make a quick
// clock using a DS1302 and a 16x2 LCD.
//
// I assume you know how to connect the DS1302 and LCD.
// DS1302: CE pin → Arduino Digital 27
// I/O pin → Arduino Digital 29
// SCLK pin → Arduino Digital 31
// VCC pin → Arduino Digital 33
// GND pin → Arduino Digital 35
// LCD: DB7 → Arduino Digital 7
// DB6 → Arduino Digital 6
// DB5 → Arduino Digital 5
// DB4 → Arduino Digital 4
// E → Arduino Digital 9
// RS → Arduino Digital 8

#include <Wire.h> // Need for NewLiquidCrystal library
#include <LiquidCrystal.h>
#include <DS1302RTC.h>
#include <Time.h>

// Init the DS1302
// Set pins: CE, IO,CLK
DS1302RTC RTC(27, 29, 31);

// Optional connection for RTC module
#define DS1302_GND_PIN 33
#define DS1302_VCC_PIN 35

// Init the LCD
// initialize the library with the numbers of the interface pins
// lcd(RS, E, d4, d5, d6, d7, bl, polarity)
LiquidCrystal lcd(8, 9, 4, 5, 6, 7, 10, POSITIVE);

void setup()
{
// Setup LCD to 16x2 characters
lcd.begin(16, 2);

// Activate RTC module
digitalWrite(DS1302_GND_PIN, LOW);
pinMode(DS1302_GND_PIN, OUTPUT);

digitalWrite(DS1302_VCC_PIN, HIGH);
pinMode(DS1302_VCC_PIN, OUTPUT);

lcd.print(“RTC activated”);

delay(500);

lcd.clear();
if (RTC.haltRTC())
lcd.print(“Clock stopped!”);
else
lcd.print(“Clock working.”);

lcd.setCursor(0,1);
if (RTC.writeEN())
lcd.print(“Write allowed.”);
else
lcd.print(“Write protected.”);

delay ( 2000 );

// Setup time library
lcd.clear();
lcd.print(“RTC Sync”);
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus() == timeSet)
lcd.print(" Ok!");
else
lcd.print(" FAIL!");

delay ( 2000 );

lcd.clear();
}

void loop()
{
static int sday = 0; // Saved day number for change check

// Display time centered on the upper line
lcd.setCursor(3, 0);
print2digits(hour());
lcd.print(" “);
print2digits(minute());
lcd.print(” ");
print2digits(second());

// Update in 00:00:00 hour only
if(sday != day()) {
// Display abbreviated Day-of-Week in the lower left corner
lcd.setCursor(0, 1);
lcd.print(dayShortStr(weekday()));

// Display date in the lower right corner
lcd.setCursor(5, 1);
lcd.print(" “);
print2digits(day());
lcd.print(”/");
print2digits(month());
lcd.print("/");
lcd.print(year());
}
// Warning!
if(timeStatus() != timeSet) {
lcd.setCursor(0, 1);
lcd.print(F(“RTC ERROR: SYNC!”));
}

// Save day number
sday = day();

// Wait small time before repeating :slight_smile:
delay (100);
}

void print2digits(int number) {
if (number >= 0 && number < 10) {
lcd.write(’_’);
}
lcd.print(number);
}