Go Down

Topic: [solved]setting date on mega and wiznet (Read 529 times) previous topic - next topic

vespapierre

Nov 15, 2012, 09:01 pm Last Edit: Nov 17, 2012, 10:39 am by vespapierre Reason: 1
Hi,

I tried to set time and date on mega and wiznet with the below code, but no message on serial monitor...
what is wrong??


#include <Wire.h>
#include <Rtc_Pcf8563.h>

//init the real time clock
Rtc_Pcf8563 rtc;

void setup()
{
 //clear out the registers
 rtc.initClock();
 //set a time to start with.
 //day, weekday, month, century(1=1900, 0=2000), year(0-99)
 rtc.setDate(14, 6, 3, 1, 10);
 //hr, min, sec
 rtc.setTime(1, 15, 0);
}

void loop()
{
 //both format functions call the internal getTime() so that the
 //formatted strings are at the current time/date.
 Serial.print(rtc.formatTime());
 Serial.print("\r\n");
 Serial.print(rtc.formatDate());
 Serial.print("\r\n");
 delay(1000);
}


guix

#1
Nov 15, 2012, 09:16 pm Last Edit: Nov 15, 2012, 09:18 pm by guix Reason: 1
Hello, you forgot to initialize a serial instance :)

Add in setup():
Code: [Select]

Serial.begin( 9600 ); // 9600 or whatever is the baud speed that you have set in the serial monitor window

vespapierre

still no answer:( nothing happens on serial...this code was working fine on atmega328...but mega2560 now... :~
I have read on playground I should define I2C addresses...like
#define RTCC_R  0xa3
#define RTCC_W  0xa2

my addresses are 0x51 and 0x02

but I gues this format is not ok..or whatever...

vespapierre

ok, now it is answering after this:
include <Wire.h>
#include <Rtc_Pcf8563.h>
#define I2C_RTC 0x51

//init the real time clock
Rtc_Pcf8563 rtc;

void setup()
{
  Serial.begin( 9600 );
  //clear out the registers
  rtc.initClock();
  //set a time to start with.
  //day, weekday, month, century(1=1900, 0=2000), year(0-99)
  rtc.setDate(15, 4, 11, 0, 12);
  //hr, min, sec
  rtc.setTime(21, 52, 0);
}

void loop()
{
  //both format functions call the internal getTime() so that the
  //formatted strings are at the current time/date.
  Serial.print(rtc.formatTime());
  Serial.print("\r\n");
  Serial.print(rtc.formatDate());
  Serial.print("\r\n");
  delay(1000);
}


but still have wrong values back:

45:85:85
25/45/19@5

vespapierre

Take care about the pins!! for I2C

mega:
20 (SDA)
21 (SCL)

duemila:
A4 (SDA)
A5 (SCL)


Do I have to take care about it in the sketch after wiring out??


vespapierre

Problem is solved:

Have to wire out from wiznet to mega:

mega:
20 (SDA)
21 (SCL)

wiznet:
A4 (SDA)
A5 (SCL)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy