Difference between revisions of "Setting Time and Date for the DS3231 RTC"

From media_wiki
Jump to: navigation, search
 
(8 intermediate revisions by the same user not shown)
Line 6: Line 6:
 
   Either a CR2032 or LI2032 coin cell battery will work.
 
   Either a CR2032 or LI2032 coin cell battery will work.
 
   Insert '''DS3231 module''' into the '''Power Logger PCB''' at J5.  
 
   Insert '''DS3231 module''' into the '''Power Logger PCB''' at J5.  
+
'''Download the Drivers'''
To Set the date and time use the follow program and paste in the Arduino IDE.<br>
+
  The '''ds3231.h''' library can be downloaded from https://github.com/rodan/ds3231.
Ensure sure you have added these two libraries to the Arduino environment using the library manager.
+
  Create a folder in Documents called Power-Fail-logger.
 +
  Download and Save '''ds3231-master.zip''' to that folder.
 +
  Install the Zip file by clicking on the '''Sketch''' Tab in the '''Arduino IDE'''.  
 +
  Select '''Include library'''. 
 +
  Select '''Add .ZIP Library...'''
 +
 
 +
  Ensure sure you have added these two libraries to the Arduino environment.  
 
  '''Wire.h'''   
 
  '''Wire.h'''   
 
  '''ds3231.h'''  
 
  '''ds3231.h'''  
 +
'''Validate the libraries are installed'''
 +
  Click the '''Sketch''' Tab
 +
  Select '''Include library'''.
 +
  The libraries will be listed
 +
  '''Arduino libraries'''      (Wire)
 +
  '''Contributed Libraries.''' (ds3231-master)
 +
  
 +
To Set the date and time use the follow program and paste in the '''Arduino IDE'''.<br>
 +
 +
----
 
   // '''DS3231-Set-Time-Date.ino'''
 
   // '''DS3231-Set-Time-Date.ino'''
 
   //This code can be found here:https://github.com/rodan/ds3231
 
   //This code can be found here:https://github.com/rodan/ds3231
Line 55: Line 71:
 
   Serial.print(number);
 
   Serial.print(number);
 
   }  
 
   }  
 
+
----
 
'''Set up Programmer'''
 
'''Set up Programmer'''
 
   Connect the '''USBTinyISP''' to the '''AVR-ISP-6 pin header J7''' on the '''Power Fail Logger PCB'''.
 
   Connect the '''USBTinyISP''' to the '''AVR-ISP-6 pin header J7''' on the '''Power Fail Logger PCB'''.
   In the Arduino IDE click on '''Tools''' Tab - Select '''Programmer''' then select '''USBTinyISP'''.<br>
+
   In the '''Arduino IDE''' click on '''Tools''' Tab - Select '''Programmer''' then select '''USBTinyISP'''.<br>
 +
'''Select correct target board'''
 +
  In the '''Arduino IDE''' click on '''Tools''' Tab - Select '''Board''' then select the '''Arduino Uno'''.<br>
 +
'''Connect Serial Port to the RS232 Port'''
 +
  Plug into your laptop USB port the '''Prolific USB-to-Serial Comm Port'''
 
   Connect the '''Prolific USB-to-Serial Comm Port''' to the '''RS232 Port''' on the Power Fail Board  
 
   Connect the '''Prolific USB-to-Serial Comm Port''' to the '''RS232 Port''' on the Power Fail Board  
   Use '''Device Manager''' to validate which Comm Port is used.
+
   Connect the '''TX''', '''RX''', and '''Ground''' Pins to '''J4'''.
  In the Arduino IDE click on '''Tools''' Tab - Select '''Port''' then select the '''Prolific Port''' (Example Comm6).<br>
+
          Prolific        J4 Power Logger
   Select correct target board
+
              TX      -    RX
   In the Arduino IDE click on '''Tools''' Tab - Select '''Board''' then select the '''Arduino Uno'''.<br>
+
              RX      -    TX
 +
              GND    -    GND
 +
   Use Windows '''Device Manager''' to validate which Comm Port is used. You will need this later.
 +
   In the '''Arduino IDE''' click on '''Tools''' Tab - Select '''Port''' then select the '''Prolific Port''' (Example Comm6).<br>
 +
 
 
'''Flash the Microcontroller''' with DS3231-Set-Time-Date Program
 
'''Flash the Microcontroller''' with DS3231-Set-Time-Date Program
 
   Paste the above program '''DS3231-Set-Time-Date.ino''' into the '''Arduino IDE'''.
 
   Paste the above program '''DS3231-Set-Time-Date.ino''' into the '''Arduino IDE'''.
Line 78: Line 102:
 
   It will update and display the time once a minute
 
   It will update and display the time once a minute
  
Next Step '''Flash the Microcontroller''' with Power-Fail-Logger Program
+
Next Step click on link below '''Programming Power Fail Logger with Arduino IDE''' with Power-Fail-Logger Program
 
 
 
==[[ Power Fail Logger by Microrusty ]]==
 
==[[ Power Fail Logger by Microrusty ]]==
 +
==[[Initializing the Microcontroller]]==
 +
==[[Setting Time and Date for the DS3231 RTC]]==
 +
==[[ Programming Power Fail Logger with Arduino IDE]]==
 +
==[[Installation and use]]==
 +
----
 +
==[[ Main Page ]]==

Latest revision as of 21:37, 17 August 2021

DS3231.PNG

Setting up the DS3231 RTC

 DS3231 RTC Datasheet: https://datasheets.maximintegrated.com/en/ds/DS3231.pdf
 Insert a coin cell battery into DS3231. 
 Either a CR2032 or LI2032 coin cell battery will work.
 Insert DS3231 module into the Power Logger PCB at J5. 

Download the Drivers

 The ds3231.h library can be downloaded from https://github.com/rodan/ds3231.
 Create a folder in Documents called Power-Fail-logger.
 Download and Save ds3231-master.zip to that folder.
 Install the Zip file by clicking on the Sketch Tab in the Arduino IDE. 
 Select Include library.   
 Select Add .ZIP Library...
 
 Ensure sure you have added these two libraries to the Arduino environment. 
Wire.h  
ds3231.h 

Validate the libraries are installed

 Click the Sketch Tab
 Select Include library.
 The libraries will be listed 
 Arduino libraries      (Wire) 
 Contributed Libraries. (ds3231-master)

To Set the date and time use the follow program and paste in the Arduino IDE.


 // DS3231-Set-Time-Date.ino
 //This code can be found here:https://github.com/rodan/ds3231
 #include <Wire.h>    //Make sure you have added this library to the Arduino environment
 #include <ds3231.h>  //Make sure you have added this library to the Arduino environment
 struct ts t; 
 void setup() {
 Serial.begin(9600);
 Wire.begin();
 DS3231_init(DS3231_CONTROL_INTCN);
 /*----------------------------------------------------------------------------
 In order to synchronize your clock module, insert timetable values below !
 ----------------------------------------------------------------------------*/
 t.hour=20;      //Set the hour in military time to your current time. 
 t.min=40;       //Set the minutes. 
 t.sec=0;        //No need to change   
 t.mday=11;      //Set the Day
 t.mon=4;        //Set the Month
 t.year=2021;    //Set the Year
 DS3231_set(t);  //Comment this line out after setting RTC with time & date to validate
 }

 void loop() {
 DS3231_get(&t);
 Serial.print("Date : ");
 Serial.print(t.mon);
 Serial.print("/");
 Serial.print(t.mday);
 Serial.print("/");
 Serial.print(t.year);
 Serial.print("\t Hour : ");
 Serial.print(t.hour);
 Serial.print(":");
 Serial.println(t.min);
 Serial.print(":");
 Serial.println(t.sec);
 delay(60000);
 }
 void print2digits(int number){
 if (number >= 0 && number < 10) {
   Serial.write ('0');
 }
 Serial.print(number);
 } 

Set up Programmer

 Connect the USBTinyISP to the AVR-ISP-6 pin header J7 on the Power Fail Logger PCB.
 In the Arduino IDE click on Tools Tab - Select Programmer then select USBTinyISP.

Select correct target board

 In the Arduino IDE click on Tools Tab - Select Board then select the Arduino Uno.

Connect Serial Port to the RS232 Port

 Plug into your laptop USB port the Prolific USB-to-Serial Comm Port 
 Connect the Prolific USB-to-Serial Comm Port to the RS232 Port on the Power Fail Board 
 Connect the TX, RX, and Ground Pins to J4.
         Prolific         J4 Power Logger
             TX      -    RX
             RX      -    TX
             GND     -    GND
 Use Windows Device Manager to validate which Comm Port is used. You will need this later.
 In the Arduino IDE click on Tools Tab - Select Port then select the Prolific Port (Example Comm6).

Flash the Microcontroller with DS3231-Set-Time-Date Program

 Paste the above program DS3231-Set-Time-Date.ino into the Arduino IDE.
 After changing the time stamp in the program to match your current time do the following:
 In the Arduino IDE click on Sketch Tab - Select Upload Using Programmer
 

Validate the clock is set

 After program has uploaded go back and comment out the DS3231_set(t); statement. 
 Validate by reprograming the board with that line commented out.
 Use the same programming steps as stated above. 
In the Arduino IDE click on Tools Tab - Select Serial Monitor
Once the program has finished loading hit the Reset button on the Power Fail Logger Board. You should see the correct time and date display in the Serial Monitor. It will update and display the time once a minute

Next Step click on link below Programming Power Fail Logger with Arduino IDE with Power-Fail-Logger Program

Power Fail Logger by Microrusty

Initializing the Microcontroller

Setting Time and Date for the DS3231 RTC

Programming Power Fail Logger with Arduino IDE

Installation and use


Main Page