RTC don't work

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

RTC don't work

Postby zio Tonino » Tue Jun 12, 2012 1:32 am

good morning,
I have a problem with the module rtc, I'm trying to connect it directly via pins to Arduino! I tried to set the following parameters in the setup:

Code: Select all



// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 RTC;

 
void setup () {

 
  Serial.begin(9600);
    Wire.begin();
    RTC.begin();
   
  pinMode(A3,OUTPUT);
  pinMode(A2,OUTPUT);
  digitalWrite(A3,HIGH);
  digitalWrite(A2,LOW);
   

  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(12/06/2012, 10:30:00));
  }

  pinMode(13,OUTPUT);
}

void loop () {
    DateTime now = RTC.now();
   
Serial.println(now.minute(),DEC);


if(now.hour()==10 && now.minute()==26){
   Serial.println("sono le ore: 10:26");
   }
   
    Serial.print(now.year(), DEC);
    Serial.print('/');
   
        if(now.month()<10){
      Serial.print("0");
    }
   
    Serial.print(now.month(), DEC);
    Serial.print('/');
   
        if(now.day()<10){
      Serial.print("0");
    }
   
    Serial.print(now.day(), DEC);
    Serial.print(' ');
   
        if(now.hour()<10){
      Serial.print("0");
    }
    Serial.print(now.hour(), DEC);
    Serial.print(':');
   
        if(now.minute()<10){
      Serial.print("0");
    }
    Serial.print(now.minute(), DEC);
    Serial.print(':');
   
    if(now.second()<10){
      Serial.print("0");
    }
   
    Serial.print(now.second(), DEC);
    Serial.println();

    delay(1000);
}


but Arduino seems not work! it seems as if the serial port does not work.
The LED blinks only when I deadlift rtc module, otherwise it is turned on and fixed.
In any case, both with and without the rtc module, the monitor serial does not show anything! What is wrong?

Thanks
zio Tonino
 
Posts: 27
Joined: Tue Jun 12, 2012 1:26 am

Re: RTC don't work

Postby zio Tonino » Tue Jun 12, 2012 3:44 am

Ok, now It works!
I changed serial.begin from 56700 to 9600! all charactes were garbled!


Now I have a problem with setting time:
RTC.adjust(DateTime(__DATE__, __TIME__));
My pc says 10.40 ... arduino 10.38!
O_ò
zio Tonino
 
Posts: 27
Joined: Tue Jun 12, 2012 1:26 am

Re: RTC don't work

Postby adafruit_support_bill » Tue Jun 12, 2012 5:40 am

Code: Select all
RTC.adjust(DateTime(__DATE__, __TIME__));

That will set the RTC to the time the sketch was compiled. The Arduino will always be a little behind because of the time it takes to upload the sketch to the Arduino.
User avatar
adafruit_support_bill
 
Posts: 15941
Joined: Sat Feb 07, 2009 9:11 am

Re: RTC don't work

Postby zio Tonino » Tue Jun 12, 2012 6:39 am

Thanks for the answer! :)
Arduino takes about 30 second to upload sketch! Not 4 minutes! :shock:
zio Tonino
 
Posts: 27
Joined: Tue Jun 12, 2012 1:26 am

Re: RTC don't work

Postby adafruit_support_bill » Tue Jun 12, 2012 7:03 am

You also have to factor in the time it takes to compile on your system. Since the time is only being reported with one minute resolution, the actual time difference between 10:38 and 10:40 could be as little as 61 seconds.
User avatar
adafruit_support_bill
 
Posts: 15941
Joined: Sat Feb 07, 2009 9:11 am


Return to Other Arduino products from Adafruit

Who is online

Users browsing this forum: No registered users and 2 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [102]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[108]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[69]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]