Ardumotive Arduino Greek Playground
  • Home
    • About us
    • License
  • Arduino
    • Tutorials
    • Workshop
  • Raspberry Pi
  • DIY 3D Printer
  • News
    • Events >
      • Unboxing & Review
    • Blog
The 1st Arduino Playground in Greece - Open Source Hardware

Ώρα και ημερομηνία με το RTC DS1307

Available Languages
Picture
Picture

Εισαγωγή

Picture
Το DS1307 είναι ένα RTC (real time clock) ολοκληρωμένο το οποίο μπορεί και κρατάει στην μνήμη του, με την βοήθεια μιας μπαταρίας, την ώρα και ημερομηνία. 

Το συγκεκριμένο module που θα χρησιμοποιήσουμε έχει και μια μνήμη EEPROM για μελλοντική/άλλη χρήση (π.χ. αποθήκευση θερμοκρασίας)
​
Σε αυτό το tutorial θα δούμε πως μπορούμε να σετάρουμε την τρέχουσα ώρα και ημερομηνία και πως μετά να την διαβάσουμε απ' την σειριακή οθόνη του Arduino IDE.

Τα υλικά που θα χρειαστούμε 

Για το tutorial αυτό θα χρειαστούμε:
  • Arduino uno
  • Breadboard (προαιρετικό)
  • DS1307 RTC Module (i2c)
  • CR1220 3V (μικρή στρογγυλή μπαταρία)

Για να το χρησιμοποιήσετε θα πρέπει να κολλήσετε 4 καλώδια.

Picture

Το κύκλωμα

Η συνδεσμολογία είναι αρκετά απλή:
  • Vcc στο Arduino 5V pin 
  • GND στο Arduino GND pin 
  • SDA στο Arduino  analog pin 4
  • ​SCL στο Arduino analog pin 5

Ο κώδικας

Set current date and time with:
rtc.adjust(DateTime(2016, 11, 19, 19, 45, 0));
 // Format: YYYY,MM,DD,HH,MM,SS
​
  • Read day from RTC: now.day();
  • Read month from RTC: now.month();
  • Read year from RTC: now.year();
  • and etc...
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {
  Serial.begin(9600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  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(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    rtc.adjust(DateTime(2016, 11, 19, 19, 45, 0));   // <----------------------SET TIME AND DATE: YYYY,MM,DD,HH,MM,SS
  }
  delay(100);
}

void loop () {
    DateTime now = rtc.now();
    Serial.print(now.day(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.year(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    
    delay(3000); //Print date and time every 3 sec
}
Κατεβάστε τον κώδικα απ' εδώ και ανοίξτε το αρχείο με το Arduino IDE. Μέσα θα βρείτε και την σχετική βιβλιοθήκη.
rtc_ds1307_tutorial.zip
File Size: 17 kb
File Type: zip
Download File


​Ανοίξτε την σειριακή οθόνη απ' το μενού εργαλεία του Arduino IDE.


Το αποτέλεσμα:
Picture

Συγχαρητήρια! 

Picture
Μόλις ολοκληρώσατε άλλο ένα "How to" tutorial και μάθατε πως να χρησιμοποιείτε το real time clock DS1307.

Ελπίζω να σας άρεσε, αν θέλετε μπορείτε να αφήσετε το σχόλιο σας παρακάτω.
​

Picture

Search Engine

Picture

Licence 

Picture

Help us to grow up!

Picture


Donate us
About us
License
Cookies policy

Visit the biggest Arduino Shop in Greece!

Picture
find us on dwrean.net
find us on Codebender
find us on Instructables
Developed and designed by Vasilakis Michalis Copyright © 2013 Ardumotive All Rights Reserved
All trademarks referenced herein are properties of their
Powered by Create your own unique website with customizable templates.
Design by DivTag Templates