DS3231_Serial_Easy.pde 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 chipKit you must connect
  9. // the pins as follows:
  10. //
  11. // chipKit Uno32/uC32:
  12. // ----------------------
  13. // DS3231: SDA pin -> Analog 4
  14. // SCL pin -> Analog 5
  15. // *** Please note that JP6 and JP8 must be in the I2C position (closest to the analog pins)
  16. //
  17. // chipKit Max32:
  18. // ----------------------
  19. // DS3231: SDA pin -> Digital 20 (the pin labeled SDA)
  20. // SCL pin -> Digital 21 (the pin labeled SCL)
  21. //
  22. // The chipKit boards does not have pull-up resistors on the hardware I2C interface
  23. // so external pull-up resistors on the data and clock signals are required.
  24. //
  25. // You can connect the DS3231 to any available pin but if you use any
  26. // other than what is described above the library will fall back to
  27. // a software-based, TWI-like protocol which will require exclusive access
  28. // to the pins used.
  29. //
  30. #include <DS3231.h>
  31. // Init the DS3231 using the hardware interface
  32. DS3231 rtc(SDA, SCL);
  33. void setup()
  34. {
  35. // Setup Serial connection
  36. Serial.begin(115200);
  37. // Initialize the rtc object
  38. rtc.begin();
  39. // The following lines can be uncommented to set the date and time
  40. //rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
  41. //rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
  42. //rtc.setDate(1, 1, 2014); // Set the date to January 1st, 2014
  43. }
  44. void loop()
  45. {
  46. // Send Day-of-Week
  47. Serial.print(rtc.getDOWStr());
  48. Serial.print(" ");
  49. // Send date
  50. Serial.print(rtc.getDateStr());
  51. Serial.print(" -- ");
  52. // Send time
  53. Serial.println(rtc.getTimeStr());
  54. // Wait one second before repeating :)
  55. delay (1000);
  56. }