DS3231_Serial_Easy.ino 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // DS3231_Serial_Easy
  2. // Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
  3. // web: http://www.RinkyDinkElectronics.com/
  4. //
  5. // A quick demo of how to use my DS3231-library to
  6. // quickly send time and date information over a serial link
  7. //
  8. // To use the hardware I2C (TWI) interface of the Arduino you must connect
  9. // the pins as follows:
  10. //
  11. // Arduino Uno/2009:
  12. // ----------------------
  13. // DS3231: SDA pin -> Arduino Analog 4 or the dedicated SDA pin
  14. // SCL pin -> Arduino Analog 5 or the dedicated SCL pin
  15. //
  16. // Arduino Leonardo:
  17. // ----------------------
  18. // DS3231: SDA pin -> Arduino Digital 2 or the dedicated SDA pin
  19. // SCL pin -> Arduino Digital 3 or the dedicated SCL pin
  20. //
  21. // Arduino Mega:
  22. // ----------------------
  23. // DS3231: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA pin
  24. // SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL pin
  25. //
  26. // Arduino Due:
  27. // ----------------------
  28. // DS3231: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin
  29. // SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL1 (Digital 71) pin
  30. //
  31. // The internal pull-up resistors will be activated when using the
  32. // hardware I2C interfaces.
  33. //
  34. // You can connect the DS3231 to any available pin but if you use any
  35. // other than what is described above the library will fall back to
  36. // a software-based, TWI-like protocol which will require exclusive access
  37. // to the pins used, and you will also have to use appropriate, external
  38. // pull-up resistors on the data and clock signals.
  39. //
  40. #include <DS3231.h>
  41. // Init the DS3231 using the hardware interface
  42. DS3231 rtc(SDA, SCL);
  43. void setup()
  44. {
  45. // Setup Serial connection
  46. Serial.begin(115200);
  47. // Uncomment the next line if you are using an Arduino Leonardo
  48. //while (!Serial) {}
  49. // Initialize the rtc object
  50. rtc.begin();
  51. // The following lines can be uncommented to set the date and time
  52. //rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
  53. //rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
  54. //rtc.setDate(1, 1, 2014); // Set the date to January 1st, 2014
  55. }
  56. void loop()
  57. {
  58. // Send Day-of-Week
  59. Serial.print(rtc.getDOWStr());
  60. Serial.print(" ");
  61. // Send date
  62. Serial.print(rtc.getDateStr());
  63. Serial.print(" -- ");
  64. // Send time
  65. Serial.println(rtc.getTimeStr());
  66. // Wait one second before repeating :)
  67. delay (1000);
  68. }