RTC Module - time appears to jump around randomly?

Our range of tiny modules are designed to make it easy for you to quickly add functionality to your projects. [Module List]
Post Reply
victorhooi
Posts:16
Joined:Thu Mar 06, 2014 4:00 pm
RTC Module - time appears to jump around randomly?

Post by victorhooi » Thu Sep 11, 2014 12:45 pm

Hi,

I'm trying to use the RTC module with the DMD module to build a wall clock.

I'm attempting to retrieve the time, as per the quickstart guide (http://www.freetronics.com/pages/rtc-re ... tart-guide):

Code: Select all

rtc.readTime(&time);
Serial.print(time.hour, DEC);
Serial.print(":");
Serial.print(time.minute, DEC);
Serial.print(":");
Serial.print(time.second, DEC);
Serial.print("\n");
delay(1000);
However, when I check the serial monitor, the output looks like this:

Code: Select all

22:3:0
22:39:10
1:1:1
0:0:0
0:81:6
0:81:6
19:0:0
0:0:0
0:0:0
0:0:0
0:0:0
Any thoughts on what's going on here?

Thanks,
Victor

andrew
Freetronics Staff
Freetronics Staff
Posts:978
Joined:Sun Jul 14, 2013 7:06 am

Re: RTC Module - time appears to jump around randomly?

Post by andrew » Thu Sep 11, 2014 7:57 pm

Double-check your wiring (5V, GND, SDA to A4, SCL to A5) and ensure you have a good connection.
Then run the sketch found here:
http://cdn.shopify.com/s/files/1/0045/8 ... ds3232.ino
and let me know how you go.

victorhooi
Posts:16
Joined:Thu Mar 06, 2014 4:00 pm

Re: RTC Module - time appears to jump around randomly?

Post by victorhooi » Thu Sep 11, 2014 8:43 pm

Hi John,

Thanks for the instructions.

I downloaded that file, and I seem to be getting the correct time in my Serial Monitor with that sketch:

Code: Select all

6:Day of week:Monday
6:41:05  2/1/0  Day of week:Monday
6:41:06  2/1/0  Day of week:Monday
Day of week:Monday
6:41:04  2/1/0  Day of week:Monday
6:41:05  2/1/0  Day of week:Monday
6:41:06  2/1/0  Day of week:Monday
6:41:08  2/1/0  Day of week:Monday
6:41:09  2/1/0  Day of week:Monday
6:41:10  2/1/0  Day of week:Monday
So it seems there must be something wrong with my code to print out the hour to the Serial Monitor. I've provided the full contents of my sketch, in case you can see something I'm doing wrong? (I'm just playing around with things at the moment, this doesn't do anything serious yet).

Code: Select all

/*
  Countdown on a single DMD display
 */

#include <SPI.h>
#include <DMD2.h>
#include <fonts/SystemFont5x7.h>

#include <SoftI2C.h> // initialise required libraries
#include <DS3232RTC.h>
SoftI2C i2c(A4, A5); // assign pins to SDA and SCL
DS3232RTC rtc(i2c);

const int COUNTDOWN_FROM = 12;
int counter = COUNTDOWN_FROM;

SoftDMD dmd(1,1);  // DMD controls the entire display
DMD_TextBox upper_box(dmd, 7, 0);  // "box" provides a text box to automatically write to/scroll the display
DMD_TextBox lower_box(dmd, 1, 9);


// the setup routine runs once when you press reset:
void setup() {
  Serial.begin(9600);
  dmd.setBrightness(255);
  dmd.selectFont(SystemFont5x7);
  dmd.begin();
  upper_box.print("NYC");

}

// the loop routine runs over and over again forever:
void loop() {
  RTCTime time;
  //Serial.print(counter);
  rtc.readTime(&time);
  lower_box.print(time.hour, DEC);
  //lower_box.print("14" + ":" + "0");
  Serial.print(time.hour, DEC);
  Serial.print(":");
  Serial.print(time.minute, DEC);
  Serial.print(":");
  Serial.print(time.second, DEC);
  Serial.print("\n");
  delay(1000);
  lower_box.clear();
  
}
Cheers,
Victor

victorhooi
Posts:16
Joined:Thu Mar 06, 2014 4:00 pm

Re: RTC Module - time appears to jump around randomly?

Post by victorhooi » Thu Sep 11, 2014 9:05 pm

Hi,

Ok, I've found something strange - it seems to be something to do with my dmd.begin() line.

The below code will print out the time correctly to the Serial Monitor:

Code: Select all

/*
  Countdown on a single DMD display
 */

#include <SPI.h>
#include <DMD2.h>
#include <fonts/SystemFont5x7.h>

#include <SoftI2C.h> // initialise required libraries
#include <DS3232RTC.h>
SoftI2C i2c(A4, A5); // assign pins to SDA and SCL
DS3232RTC rtc(i2c);

const int COUNTDOWN_FROM = 12;
int counter = COUNTDOWN_FROM;

SoftDMD dmd(1,1);  // DMD controls the entire display
DMD_TextBox upper_box(dmd, 7, 0);  // "box" provides a text box to automatically write to/scroll the display
DMD_TextBox lower_box(dmd, 1, 9);


// the setup routine runs once when you press reset:
void setup() {
  Serial.begin(9600);
  dmd.setBrightness(255);
  dmd.selectFont(SystemFont5x7);
//  dmd.begin();
}

// the loop routine runs over and over again forever:
void loop() {
  RTCTime time;

  rtc.readTime(&time);
  Serial.print("Time: ");
  printDec2(time.hour);
  Serial.print(':');
  printDec2(time.minute);
  Serial.print(':');
  printDec2(time.second);
  Serial.println();
  
  Serial.print(time.hour, DEC);
  Serial.print(":");
  Serial.print(time.minute, DEC);
  Serial.print(":");
  Serial.print(time.second, DEC);
  Serial.print("\n");
  delay(1000);  
}

void printDec2(int value)
{
    Serial.print((char)('0' + (value / 10)));
    Serial.print((char)('0' + (value % 10)));
}
Serial Monitor:

Code: Select all

Time4:13
7:4:13
Time: 07:04:14
7:4:14
Time: 07:04:15
7:4:15
Time: 07:04:16
7:4:16
Time: 07:04:17
7:4:17
Time: 07:04:18
7:4:18
Time: 07:04:20
However, when I uncomment the dmd.begin() line in setup(), and upload that, it then prints out the garbage from before:

Code: Select all

Time: 07:05:30
7:5:30
Time: 01:02:02
1:2:2
Time: 00:00:00
0:0:0
Time: 00:81:06
0:81:6
Time: 00:81:06
0:81:6
Time: 16:00:00
16:0:0
Time: 00:00:00
0:0:0
Does that mean there's some kind of incompatibility between the RTC library, and the DMD2 library?

Cheers,
Victor

andrew
Freetronics Staff
Freetronics Staff
Posts:978
Joined:Sun Jul 14, 2013 7:06 am

Re: RTC Module - time appears to jump around randomly?

Post by andrew » Thu Sep 11, 2014 11:06 pm

Possibly, however the DMD2 is still in beta. We'll look into it. In the meanwhile, please install the DMD library if you haven't already done so, and try the following sketch:
https://sites.google.com/site/tronixstu ... edirects=0

angusgr
Freetronics Staff
Freetronics Staff
Posts:853
Joined:Tue Apr 09, 2013 11:19 pm
Location:Melbourne, Australia
Contact:

Re: RTC Module - time appears to jump around randomly?

Post by angusgr » Tue Sep 16, 2014 7:35 am

Hi Victor,

Did you get a chance to try the sketch that John posted?

I can't think of any reason these two wouldn't play together. Something you could try is changing 'SoftDMD' to 'SPIDMD' in the declaration, assuming that you're using an atmega328p (Arduino Uno compatible, ie Eleven or similar) and the standard pins. No other changes should be necessary. This will use hardware SPI so less CPU overhead than software, more time for any background operations that use the RTC.

Please let us know how you get on.

- Angus

PS I've deleted the post asking about this thread in the other DMD2 thread. It's no problem "bumping" a post if it hasn't had a response in a while, but please do it in the same thread - doing it in different threads creates confusion for people reading them later on.

Post Reply