Christan Shane Plaza
Christan Shane Plaza

Reputation: 19

Arduino RTC Module shows alternate information

So I tried to make an Arduino LCD Real Time Clock using the DS1302 RTC.

It works and reads the time stored in the RTC properly, yet every other second, displays empty sets of data

Here's a snapshot of the serial monitor and the sketch

I can't seem to find a problem.

It could be from the library itself but I got it from a video which seemed to work fine in the video.

I'm new in this environment so any type of help is much appreciated. Here's my sketch.

#include <DS1302.h>
#include <Wire.h>  
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
DS1302 rtc(2, 3, 4);

void setup()
{
  rtc.halt(false);
  rtc.writeProtect(false);
  lcd.begin(16, 2);
  Serial.begin(9600);
}

void loop()
{
  lcd.setCursor(4, 0);
  lcd.print(rtc.getTimeStr());
  Serial.print(rtc.getTimeStr());
  lcd.setCursor(0, 1);
  lcd.print(rtc.getDOWStr(FORMAT_SHORT));
  Serial.print(rtc.getDOWStr(FORMAT_SHORT));
  lcd.setCursor(6, 1);
  lcd.print(rtc.getDateStr());
  Serial.println(rtc.getDateStr());
  delay (1000);
}

DS1302 Library

Upvotes: 0

Views: 619

Answers (2)

willp
willp

Reputation: 11

I've just started playing with Arduino and had the same? problem with the DS1302 RTC board that came with my kit. I am using the DS1302RTC library (by Timur Maksimov 2014?).

In my case I narrowed the problem down to power supply.

I reduced the delay loop to 100ms and basically observed that data was corrupted on the tick over of every second second. ie I got 8-9 good reads followed by 8-9 corrupted reads repeatedly.

If I take power directly from the Uno board it all works fine. When I take power from the rails on my b/board it plays up again. (repeatable)

I also considered whether the serial cables were getting some interference, but it didn't seem to make a difference if I twisted the cables together or selected wide spacing for pins.

Have replied here in case this works for others. Google tells me the problem is quite common but does not offer many solutions.

Upvotes: 1

Christan Shane Plaza
Christan Shane Plaza

Reputation: 19

I gave up and just decided to use a different library instead. It seems like the problem lies with the library itself.

I tried removing anything related to the LCD, it didn't work. I tried removing anything related to Serial and still didn't work.

I used a different library and now it works for me!

The new Library I used

Upvotes: 0

Related Questions