Add files via upload
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
// DS3231_Serial_Easy
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my DS3231-library to
|
||||
// quickly send time and date information over a serial link
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the chipKit you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// chipKit Uno32/uC32:
|
||||
// ----------------------
|
||||
// DS3231: SDA pin -> Analog 4
|
||||
// SCL pin -> Analog 5
|
||||
// *** Please note that JP6 and JP8 must be in the I2C position (closest to the analog pins)
|
||||
//
|
||||
// chipKit Max32:
|
||||
// ----------------------
|
||||
// DS3231: SDA pin -> Digital 20 (the pin labeled SDA)
|
||||
// SCL pin -> Digital 21 (the pin labeled SCL)
|
||||
//
|
||||
// The chipKit boards does not have pull-up resistors on the hardware I2C interface
|
||||
// so external pull-up resistors on the data and clock signals are required.
|
||||
//
|
||||
// You can connect the DS3231 to any available pin but if you use any
|
||||
// other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used.
|
||||
//
|
||||
|
||||
#include <DS3231.h>
|
||||
|
||||
// Init the DS3231 using the hardware interface
|
||||
DS3231 rtc(SDA, SCL);
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Setup Serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// Initialize the rtc object
|
||||
rtc.begin();
|
||||
|
||||
// The following lines can be uncommented to set the date and time
|
||||
//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
|
||||
//rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
|
||||
//rtc.setDate(1, 1, 2014); // Set the date to January 1st, 2014
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Send Day-of-Week
|
||||
Serial.print(rtc.getDOWStr());
|
||||
Serial.print(" ");
|
||||
|
||||
// Send date
|
||||
Serial.print(rtc.getDateStr());
|
||||
Serial.print(" -- ");
|
||||
|
||||
// Send time
|
||||
Serial.println(rtc.getTimeStr());
|
||||
|
||||
// Wait one second before repeating :)
|
||||
delay (1000);
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// DS3231_Serial_Hard
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my DS3231-library to
|
||||
// retrieve time- and date-data for you to manipulate.
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the chipKit you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// chipKit Uno32/uC32:
|
||||
// ----------------------
|
||||
// DS3231: SDA pin -> Analog 4
|
||||
// SCL pin -> Analog 5
|
||||
// *** Please note that JP6 and JP8 must be in the I2C position (closest to the analog pins)
|
||||
//
|
||||
// chipKit Max32:
|
||||
// ----------------------
|
||||
// DS3231: SDA pin -> Digital 20 (the pin labeled SDA)
|
||||
// SCL pin -> Digital 21 (the pin labeled SCL)
|
||||
//
|
||||
// The chipKit boards does not have pull-up resistors on the hardware I2C interface
|
||||
// so external pull-up resistors on the data and clock signals are required.
|
||||
//
|
||||
// You can connect the DS3231 to any available pin but if you use any
|
||||
// other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used.
|
||||
//
|
||||
|
||||
#include <DS3231.h>
|
||||
|
||||
// Init the DS3231 using the hardware interface
|
||||
DS3231 rtc(SDA, SCL);
|
||||
|
||||
// Init a Time-data structure
|
||||
Time t;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Setup Serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// Initialize the rtc object
|
||||
rtc.begin();
|
||||
|
||||
// The following lines can be uncommented to set the date and time
|
||||
//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
|
||||
//rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
|
||||
//rtc.setDate(1, 1, 2014); // Set the date to January 1st, 2014
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Get data from the DS3231
|
||||
t = rtc.getTime();
|
||||
|
||||
// Send date over serial connection
|
||||
Serial.print("Today is the ");
|
||||
Serial.print(t.date, DEC);
|
||||
Serial.print(". day of ");
|
||||
Serial.print(rtc.getMonthStr());
|
||||
Serial.print(" in the year ");
|
||||
Serial.print(t.year, DEC);
|
||||
Serial.println(".");
|
||||
|
||||
// Send Day-of-Week and time
|
||||
Serial.print("It is the ");
|
||||
Serial.print(t.dow, DEC);
|
||||
Serial.print(". day of the week (counting monday as the 1th), and it has passed ");
|
||||
Serial.print(t.hour, DEC);
|
||||
Serial.print(" hour(s), ");
|
||||
Serial.print(t.min, DEC);
|
||||
Serial.print(" minute(s) and ");
|
||||
Serial.print(t.sec, DEC);
|
||||
Serial.println(" second(s) since midnight.");
|
||||
|
||||
// Send a divider for readability
|
||||
Serial.println(" - - - - - - - - - - - - - - - - - - - - -");
|
||||
|
||||
// Wait one second before repeating :)
|
||||
delay (1000);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// DS3231_Temperature
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my DS3231-library to
|
||||
// quickly send the current temperature over a serial link
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the chipKit you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// chipKit Uno32/uC32:
|
||||
// ----------------------
|
||||
// DS3231: SDA pin -> Analog 4
|
||||
// SCL pin -> Analog 5
|
||||
// *** Please note that JP6 and JP8 must be in the I2C position (closest to the analog pins)
|
||||
//
|
||||
// chipKit Max32:
|
||||
// ----------------------
|
||||
// DS3231: SDA pin -> Digital 20 (the pin labeled SDA)
|
||||
// SCL pin -> Digital 21 (the pin labeled SCL)
|
||||
//
|
||||
// The chipKit boards does not have pull-up resistors on the hardware I2C interface
|
||||
// so external pull-up resistors on the data and clock signals are required.
|
||||
//
|
||||
// You can connect the DS3231 to any available pin but if you use any
|
||||
// other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used.
|
||||
//
|
||||
|
||||
#include <DS3231.h>
|
||||
|
||||
// Init the DS3231 using the hardware interface
|
||||
DS3231 rtc(SDA, SCL);
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Setup Serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// Initialize the rtc object
|
||||
rtc.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Send current temperature
|
||||
Serial.print("Temperature: ");
|
||||
Serial.print(rtc.getTemp());
|
||||
Serial.println(" C");
|
||||
delay (1000);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
// DS3231_UnixTime
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my DS3231-library to
|
||||
// convert date and time to UnixTime
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the chipKit you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// chipKit Uno32/uC32:
|
||||
// ----------------------
|
||||
// DS3231: SDA pin -> Analog 4
|
||||
// SCL pin -> Analog 5
|
||||
// *** Please note that JP6 and JP8 must be in the I2C position (closest to the analog pins)
|
||||
//
|
||||
// chipKit Max32:
|
||||
// ----------------------
|
||||
// DS3231: SDA pin -> Digital 20 (the pin labeled SDA)
|
||||
// SCL pin -> Digital 21 (the pin labeled SCL)
|
||||
//
|
||||
// The chipKit boards does not have pull-up resistors on the hardware I2C interface
|
||||
// so external pull-up resistors on the data and clock signals are required.
|
||||
//
|
||||
// You can connect the DS3231 to any available pin but if you use any
|
||||
// other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used.
|
||||
//
|
||||
|
||||
#include <DS3231.h>
|
||||
|
||||
// Init the DS3231 using the hardware interface
|
||||
DS3231 rtc(SDA, SCL);
|
||||
|
||||
Time t;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Setup Serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// Initialize the rtc object
|
||||
rtc.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Send Current time
|
||||
Serial.print("Current Time.............................: ");
|
||||
Serial.print(rtc.getDOWStr());
|
||||
Serial.print(" ");
|
||||
Serial.print(rtc.getDateStr());
|
||||
Serial.print(" -- ");
|
||||
Serial.println(rtc.getTimeStr());
|
||||
|
||||
// Send Unixtime
|
||||
// ** Note that there may be a one second difference between the current time **
|
||||
// ** and current unixtime show if the second changes between the two calls **
|
||||
Serial.print("Current Unixtime.........................: ");
|
||||
Serial.println(rtc.getUnixTime(rtc.getTime()));
|
||||
|
||||
// Send Unixtime for 00:00:00 on January 1th 2014
|
||||
Serial.print("Unixtime for 00:00:00 on January 1th 2014: ");
|
||||
t.hour = 0;
|
||||
t.min = 0;
|
||||
t.sec = 0;
|
||||
t.year = 2014;
|
||||
t.mon = 1;
|
||||
t.date = 1;
|
||||
Serial.println(rtc.getUnixTime(t));
|
||||
|
||||
// Wait indefinitely
|
||||
while (1) {};
|
||||
}
|
||||
Reference in New Issue
Block a user