DS3231_Temperature.ino 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // DS3231_Temperature
  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 the current temperature 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. }
  52. void loop()
  53. {
  54. // Send current temperature
  55. Serial.print("Temperature: ");
  56. Serial.print(rtc.getTemp());
  57. Serial.println(" C");
  58. delay (1000);
  59. }