โมดูลนาฬิกา DS1302
A Real Time Clock Module with battery backup using the easy to use DS1302 chip. The DS1302 chip uses a simple serial interface (see datasheet) and example code is available for Arduino, Raspberry Pi and many others.
การต่อใช้งาน Arduino DS1302
ไลบารี http://domoticx.phoenixinteractive.nl/arduino/libraries/ds13xx_ds32xx/DS1302%20v2.2.7z
วิธีการต่อ http://domoticx.com/arduino-rtc-tijdklok-ds1302/
โคดตัวอย่าง
/*
อัพโหลดโคด 2 ครั้ง ครั้งแรกเป็นการตั้งเวลา ครั้งที่สองเป็นการปิดคำสั่งตั้งเวลา
*/
// DS1302: RS -> Arduino Digital 2
// DA pin -> Arduino Digital 3
// CL pin -> Arduino Digital 4
// VCC -> 5V
// GND -> GND
#include "DS1302.h"
DS1302 rtc(2, 3, 4);
void clockdate()
{
Serial.println(rtc.getDateStr(FORMAT_LONG,FORMAT_LITTLEENDIAN, '/'));
Serial.println(rtc.getDOWStr());
Serial.println(rtc.getTimeStr());
}
void setup()
{
Serial.begin(9600);
// ตั้งเวลาครั้งแรก เอา comment นี้ออก ถ้าตั้งเสร็จแล้ว comment นี้ไว้เพื้อให้เวลาเดินต่อ
/*rtc.halt(false);
rtc.writeProtect(false);
rtc.setDOW(WEDNESDAY);
rtc.setTime(11, 16,00);
rtc.setDate(30, 10, 2017);
rtc.writeProtect(true);*/
}
void loop()
{
clockdate();
delay(1000);
}
Features
- Real-Time Clock Counts Seconds, Minutes, Hours, Date of the Month, Month, Day of the Week, and Year with Leap-Year Compensation Valid Up to 2100
- Serial I/O for Minimum Pin Count
- 2.0V to 5.5V Full Operation
- Uses Less than 300nA at 2.0V
- Single-Byte or Multiple-Byte (Burst Mode) Data Transfer for Read or Write of Clock or RAM Data
- Board Size: 44mm x 24mm
Documents
DS1302 Datasheet
Arduino DS1302 Real Time Clock
Using the Real Time Clock module on Raspberry Pi