|
DS3231S#Analog Devices Inc./Maxim Integrated
|
x 1 | |
|
1N4007B-GComchip Technology
|
x 1 | |
|
C503B-RBS-CW0Z0AA2Cree LED
|
x 1 | |
|
106CKR063MIllinois Capacitor
|
x 1 | |
|
CR2302 BatteryMAXELL
|
x 1 |
|
arduino IDEArduino
|
Diy RTC Module
DS3231 RTC chip
At the heart of the module is a low-cost, extremely accurate RTC chip from Maxim – DS3231. It manages all timekeeping functions and features a simple two-wire I2C interface which can be easily interfaced with any microcontroller of your choice.
The chip maintains seconds, minutes, hours, day, date, month, and year information. The date at the end of the month is automatically adjusted for months with fewer than 31 days, including corrections for leap year (valid up to 2100).
The clock operates in either the 24-hour or 12-hour format with an AM/PM indicator. It also provides two programmable time-of-day alarms.
The other cool feature of this board comes with SQW pin, which outputs a nice square wave at either 1Hz, 4kHz, 8kHz or 32kHz and can be handled programmatically. This can further be used as an interrupt due to alarm condition in many time-based applications.
Temperature Compensated Crystal Oscillator(TCXO)
Most RTC modules come with an external 32kHz crystal for time-keeping. But the problem with these crystals is that external temperature can affect their oscillation frequency. This change in frequency can be negligible but it surely adds up.
To avoid such slight drifts in crystal, DS3231 is driven by a 32kHz temperature compensated crystal oscillator (TCXO). It’s highly immune to the external temperature changes.
TCXO is packaged inside the RTC chip, making the whole package bulky. Right next to the integrated crystal is a temperature sensor.
This sensor compensates the frequency changes by adding or removing clock ticks so that the timekeeping stays on track.
That’s the reason TCXO provides a stable and accurate reference clock, and maintains the RTC to within ±2 minutes per year accuracy.
Wiring DS3231 RTC module to Arduino UNO
Let’s hook the RTC up to the Arduino.
Connections are fairly simple. Start by connecting VCC pin to the 5V output on the Arduino and connect GND to ground.
Now we are remaining with the pins that are used for I2C communication. Note that each Arduino Board has different I2C pins which should be connected accordingly. On the Arduino boards with the R3 layout, the SDA (data line) and SCL (clock line) are on the pin headers close to the AREF pin. They are also known as A5 (SCL) and A4 (SDA).
If you have a Mega, the pins are different! You’ll want to use digital 21 (SCL) and 20 (SDA). Refer below table for quick understanding.
Code Explanation:
The sketch starts with including wire.h & RTClib.h libraries for communicating with the module. We then create an object of RTClib library and define daysOfTheWeek 2D character array to store days information.
In setup and loop sections of the code, we use following functions to interact with the RTC module.
begin() function ensures that the RTC module is connected.
lostPower() function reads the DS3231’s internal I2C registers to check if the chip has lost track of time. If the function returns true, we can then set the date & time.
adjust() function sets the date & time. This is an overloaded function.
One overloaded method DateTime(F(__DATE__), F(__TIME__)) sets the date & time at which the sketch was compiled.
Second overloaded method DateTime(YYYY, M, D, H, M, s) sets the RTC with an explicit date & time. For example to set January 27 2017 at 12:56 you would call: rtc.adjust(DateTime(2017, 1, 27, 12, 56, 0));
now() function returns current date & time. Its return value is usually stored in the variable of datatype DateTime.
year() function returns current year.
month() function returns current month.
day() function returns current day.
dayOfTheWeek() function returns current day of the week. This function is usually used as an index of a 2D character array that stores days information like the one defined in above program daysOfTheWeek
hour() function returns current hour.
minute() function returns current minute.
second() function returns current seconds.
unixtime() function returns unix time in seconds. Unix time is a system for describing a point in time. It is the number of seconds that have elapsed since 00:00:00(known as Coordinated Universal Time – Thursday, 1 January 1970).
TimeSpan() function is used to add/subtract time to/from current time. You can add/subtract days, hours, minutes & seconds. It’s also an overloaded function.
now() + TimeSpan(seconds) returns the future time with seconds added into current time.
now() - TimeSpan(days,hours, minutes, seconds) returns the past time.
Arduino Code – Reading/Writing in 24C32 EEPROM
With DS3231 RTC module, as a bonus, you get 32 bytes of Electrically Erasable ROM. Its contents will not be erased even if main power to the device is interrupted.
The following program writes and then reads a message from the 24C32 EEPROM. You can use this program to save settings or passwords or really anything.
#include <Wire.h>
void setup()
{
char somedata[] = "lastminuteengineers.com"; // data to write
Wire.begin(); // initialise the connection
Serial.begin(9600);
Serial.println("Writing into memory...");
// write to EEPROM
i2c_eeprom_write_page(0x57, 0, (byte *)somedata, sizeof(somedata));
delay(100); //add a small delay
Serial.println("Memory written");
}
void loop()
{
Serial.print("Reading memory: ");
int addr=0; //first address
// access the first address from the memory
byte b = i2c_eeprom_read_byte(0x57, 0);
while (b!=0)
{
Serial.print((char)b); //print content to serial port
addr++; //increase address
b = i2c_eeprom_read_byte(0x57, addr); //access an address from the memory
}
Serial.println(" ");
delay(2000);
}
void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
int rdata = data;
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.write(rdata);
Wire.endTransmission();
}
// WARNING: address is a page address, 6-bit end will wrap around
// also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length ) {
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddresspage >> 8)); // MSB
Wire.write((int)(eeaddresspage & 0xFF)); // LSB
byte c;
for ( c = 0; c < length; c++)
Wire.write(data[c]);
Wire.endTransmission();
}
byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available()) rdata = Wire.read();
return rdata;
}
// maybe let's not read more than 30 or 32 bytes at a time!
void i2c_eeprom_read_buffer( int deviceaddress, unsigned int eeaddress, byte *buffer, int length ) {
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,length);
int c = 0;
for ( c = 0; c < length; c++ )
if (Wire.available()) buffer[c] = Wire.read();
}
Features:
Two Time-of-Day Alarms.
Digital Temp Sensor Output.
Register for Aging Trim.
DS 3231 RTC with 2032 Battery Holder.
Highly Accurate RTC Completely Manages All Timekeeping Functions.
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.
Configurable I2C device Address for AT24C32 using SMD jumpers on PCB (A0, A1, A2).
Programmable Square-Wave Output Signal.
Battery-Backup Input for Continuous Timekeeping.
Low Power Operation Extends Battery-Backup Run Time.
Diy RTC Module
*PCBWay community is a sharing platform. We are not responsible for any design issues and parameter issues (board thickness, surface finish, etc.) you choose.
- Comments(4)
- Likes(0)
- 0 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
More by Sreeram.zeno
- Esp12-F Cluster V1.0 The ESP8266 is a low-cost Wi-Fi microchip, with built-in TCP/IP networking software, and microcontro...
- TB6612FNG Motor Driver The TB6612FNG Motor Driver can control up to two DC motors at a constant current of 1.2A (3.2A peak)...
- Sunny Buddy Solar Charger v1.0 This is the Sunny Buddy, a maximum power point tracking (MPPT) solar charger for single-cell LiPo ba...
- Diy 74HC4051 8 Channel Mux Breakout Pcb The 74HC4051; 74HCT4051 is a single-pole octal-throw analog switch (SP8T) suitable for use in analog...
- Diy RFM97CW Breakout Pcb IntroductionLoRa? (standing for Long Range) is a LPWAN technology, characterized by a long range ass...
- ProMicro-RP2040 Pcb The RP2040 is a 32-bit dual ARM Cortex-M0+ microcontroller integrated circuit by Raspberry Pi Founda...
- Serial Basic CH340G Pcb A USB adapter is a type of protocol converter that is used for converting USB data signals to and fr...
- Mp3 Shield For Arduino Hardware OverviewThe centerpiece of the MP3 Player Shield is a VS1053B Audio Codec IC. The VS1053B i...
- MRK CAN Shield Arduino The CAN-BUS Shield provides your Arduino or Redboard with CAN-BUS capabilities and allows you to hac...
- AVR ISP Programmer AVR is a family of microcontrollers developed since 1996 by Atmel, acquired by Microchip Technology ...
- Diy Arduino mega Pcb The Arduino Mega 2560 is a microcontroller board based on the ATmega2560. It has 54 digital input/ou...
- Max3232 Breakout Board MAX3232 IC is extensively used for serial communication in between Microcontroller and a computer fo...
- Line Follower Pcb The Line Follower Array is a long board consisting of eight IR sensors that have been configured to ...
- HMC6343 Accelerometer Module The HMC6343 is a solid-state compass module with tilt compensation from Honeywell. The HMC6343 has t...
- RTK2 GPS Module For Arduino USBThe USB C connector makes it easy to connect the ZED-F9P to u-center for configuration and quick ...
- Arduino Explora Pcb The Arduino Esplora is a microcontroller board derived from the Arduino Leonardo. The Esplora differ...
- Diy Stepper Motor Easy Driver A motor controller is a device or group of devices that can coordinate in a predetermined manner the...
- Diy Arduino Pro Mini The Arduino Pro Mini is a microcontroller board based on the ATmega168 . It has 14 digital input/out...
-
-
Helium IoT Network Sensor Development board | H2S-Dev V1.2
90 0 0 -
-
-
-
-
-
3D printed Enclosure Backplate for Riden RD60xx power supplies
176 1 1