<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									Getting and reseting RTC without using the DS3231 library on the fly - C++				            </title>
            <link>https://forum.dronebotworkshop.com/c-plus-plus/getting-and-reseting-rtc-without-using-the-ds3231-library-on-the-fly/</link>
            <description>Discussion board for Robotics, Arduino, Raspberry Pi and other DIY electronics and modules. Join us today!</description>
            <language>en-US</language>
            <lastBuildDate>Mon, 08 Jun 2026 20:33:20 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>RE: Getting and reseting RTC without using the DS3231 library on the fly</title>
                        <link>https://forum.dronebotworkshop.com/c-plus-plus/getting-and-reseting-rtc-without-using-the-ds3231-library-on-the-fly/#post-22952</link>
                        <pubDate>Mon, 06 Dec 2021 11:38:59 +0000</pubDate>
                        <description><![CDATA[The library used was by Eric Ayars. it has examples for set time, test time, echo time, and oscillator test. 
i will upload the different codes for these tasks here]]></description>
                        <content:encoded><![CDATA[3610
<p>The library used was by Eric Ayars. it has examples for set time, test time, echo time, and oscillator test. </p>
<p>i will upload the different codes for these tasks here</p>
<p> </p>]]></content:encoded>
						                            <category domain="https://forum.dronebotworkshop.com/c-plus-plus/">C++</category>                        <dc:creator>abdulhak33m</dc:creator>
                        <guid isPermaLink="true">https://forum.dronebotworkshop.com/c-plus-plus/getting-and-reseting-rtc-without-using-the-ds3231-library-on-the-fly/#post-22952</guid>
                    </item>
				                    <item>
                        <title>RE: Getting and reseting RTC without using the DS3231 library on the fly</title>
                        <link>https://forum.dronebotworkshop.com/c-plus-plus/getting-and-reseting-rtc-without-using-the-ds3231-library-on-the-fly/#post-22951</link>
                        <pubDate>Mon, 06 Dec 2021 11:30:20 +0000</pubDate>
                        <description><![CDATA[/*DS3231_test.pdeEric Ayars4/11
Test/demo of read routines for a DS3231 RTC.
Turn on the serial monitor after loading this to check if things areworking as they should.
*/
#include &lt;D...]]></description>
                        <content:encoded><![CDATA[<p>/*<br />DS3231_test.pde<br />Eric Ayars<br />4/11</p>
<p>Test/demo of read routines for a DS3231 RTC.</p>
<p>Turn on the serial monitor after loading this to check if things are<br />working as they should.</p>
<p>*/</p>
<p>#include &lt;DS3231.h&gt;<br />#include &lt;Wire.h&gt;<br />#include &lt;LiquidCrystal.h&gt;<br />LiquidCrystal Lcd(10,9,5,4,3,2);</p>
<p>DS3231 clock;<br />bool century = false;<br />bool h12Flag;<br />bool pmFlag;<br />byte alarmDay, alarmHour, alarmMinute, alarmSecond, alarmBits;<br />bool alarmDy, alarmH12Flag, alarmPmFlag;<br />int relay1 =12;<br />int redled = 13;<br />int blueled = 11;<br />int greenled = 10;</p>
<p>void setup() {<br />// Start the I2C interface<br />Wire.begin();<br />pinMode(relay1, OUTPUT);<br />pinMode(redled, OUTPUT);<br />pinMode(greenled, OUTPUT);<br />pinMode(blueled, OUTPUT);<br />// Start the serial interface<br />Serial.begin(57600);</p>
<p>Lcd.begin(16,2);<br />Lcd.setCursor(0,0);<br />Lcd.print("Quickfix Eng ltd");<br /><br />}</p>
<p>void loop() {<br />// send what's going on to the serial monitor.<br /><br />// Start with the year<br />Serial.print("2");<br />if (century) { // Won't need this for 89 years.<br />Serial.print("1");<br />} else {<br />Serial.print("0");<br />}<br />Serial.print(clock.getYear(), DEC);<br />Serial.print(' ');<br /><br />// then the month<br />Serial.print(clock.getMonth(century), DEC);<br />Serial.print(" ");<br /><br />// then the date<br />Serial.print(clock.getDate(), DEC);<br />Serial.print(" ");<br /><br />// and the day of the week<br />Serial.print(clock.getDoW(), DEC);<br />Serial.print(" ");<br /><br />// Finally the hour, minute, and second<br />Serial.print(clock.getHour(h12Flag, pmFlag), DEC);<br />Serial.print(" ");<br />Serial.print(clock.getMinute(), DEC);<br />Serial.print(" ");<br />Serial.print(clock.getSecond(), DEC);</p>
<p><br />// Add AM/PM indicator<br />if (h12Flag) {<br />if (pmFlag) {<br />Serial.print(" PM ");<br />} else {<br />Serial.print(" AM ");<br />}<br />} else {<br />Serial.print(" 24h ");<br />}</p>
<p><br />for (clock.getYear()==21; clock.getYear()&lt;=50; clock.getYear()==clock.getYear()+1){ //for all years before 2050<br />/* for(clock.getMonth(century)==1; clock.getMonth(century)&lt;=12; clock.getMonth(century)== clock.getMonth(century)+1){ // for all 12 months <br />for(clock.getDoW()==1; clock.getDoW()&lt;=7; clock.getDoW()== clock.getDoW()+1){ */ // for all days in a week</p>
<p><br /><br />if(clock.getMonth(century)==9 || clock.getMonth(century)==10 || clock.getMonth(century)==11 || clock.getMonth(century)==12){<br />if(clock.getDoW()=="7"){<br />if(clock.getHour(h12Flag,pmFlag) == 01){<br />// if((clock.getMinute(), DEC)== 45){</p>
<p><br />digitalWrite(relay1, HIGH);<br />digitalWrite(redled, LOW);<br />digitalWrite(greenled, HIGH);<br />Lcd.setCursor(0,1);<br />Lcd.print(" ");<br />Lcd.setCursor(0,1);<br />Lcd.print("WATERING"); <br /><br />}<br />}<br />}<br />}</p>
<p> </p>
<p> </p>
<p>if(clock.getMonth(century)==9 || clock.getMonth(century)==10 || clock.getMonth(century)==11 || clock.getMonth(century)==12){<br />if(clock.getDoW()=="7"){<br />if(clock.getHour(h12Flag,pmFlag) == 02){<br />// if((clock.getMinute(), DEC)== 47){</p>
<p><br />digitalWrite(relay1, LOW);<br />digitalWrite(redled, HIGH);<br />digitalWrite(greenled, LOW);<br />Lcd.setCursor(0,1);<br />Lcd.print(" ");<br />Lcd.setCursor(0,1);<br />Lcd.print("NOT WATERING"); <br /><br />}<br />}<br />}<br />}</p>
<p> </p>
<p> </p>
<p> </p>
<p><br />/*if (clock.getHour(h12Flag,pmFlag) == 22 | ){<br />digitalWrite(relay1, HIGH);<br />digitalWrite(redled, HIGH);<br />digitalWrite(greenled, LOW);<br />Lcd.setCursor(0,1);<br />Lcd.print(" ");<br />Lcd.setCursor(0,1);<br />Lcd.print("FRIDGE OFF TIME");<br />}*/</p>
<p>/* if (clock.getHour(h12Flag,pmFlag) == 7 ||clock.getHour(h12Flag,pmFlag)==8 || clock.getHour(h12Flag,pmFlag)==9 || clock.getHour(h12Flag,pmFlag)==10 || clock.getHour(h12Flag,pmFlag)== 11 ||clock.getHour(h12Flag,pmFlag)== 12 || clock.getHour(h12Flag,pmFlag)== 13 || clock.getHour(h12Flag,pmFlag)== 14 || clock.getHour(h12Flag,pmFlag)== 15 || clock.getHour(h12Flag,pmFlag)==16 || clock.getHour(h12Flag,pmFlag)== 17 || clock.getHour(h12Flag,pmFlag)== 18 || clock.getHour(h12Flag,pmFlag)== 19 || clock.getHour(h12Flag,pmFlag)== 20){<br />digitalWrite(relay1, LOW);<br />digitalWrite(redled, LOW);<br />digitalWrite(greenled, HIGH);<br />Lcd.setCursor(0,1);<br />Lcd.print(" ");<br />Lcd.setCursor(0,1);<br />Lcd.print("FRIDGE ON TIME"); <br />}*/</p>
<p>// if (clock.getHour(h12Flag,pmFlag) &gt;= 21 ||clock.getHour(h12Flag,pmFlag)&lt;=7){<br />//digitalWrite(redled, HIGH);<br />//digitalWrite(greenled, LOW);<br />// digitalWrite(blueled, LOW);<br />// }</p>
<p>//if (clock.getHour(h12Flag,pmFlag) &gt;= 7 &amp;&amp; clock.getHour(h12Flag,pmFlag)&lt;=17){<br />// digitalWrite(redled, LOW);<br />// digitalWrite(greenled, HIGH);<br />// digitalWrite(blueled, LOW);<br />// }</p>
<p>// if (clock.getHour(h12Flag,pmFlag) &gt;= 17 &amp;&amp; clock.getHour(h12Flag,pmFlag)&lt;=21){<br />// digitalWrite(redled, LOW);<br />// digitalWrite(greenled, LOW);<br />// digitalWrite(blueled, HIGH);</p>]]></content:encoded>
						                            <category domain="https://forum.dronebotworkshop.com/c-plus-plus/">C++</category>                        <dc:creator>abdulhak33m</dc:creator>
                        <guid isPermaLink="true">https://forum.dronebotworkshop.com/c-plus-plus/getting-and-reseting-rtc-without-using-the-ds3231-library-on-the-fly/#post-22951</guid>
                    </item>
				                    <item>
                        <title>RE: Getting and reseting RTC without using the DS3231 library on the fly</title>
                        <link>https://forum.dronebotworkshop.com/c-plus-plus/getting-and-reseting-rtc-without-using-the-ds3231-library-on-the-fly/#post-22950</link>
                        <pubDate>Mon, 06 Dec 2021 11:29:41 +0000</pubDate>
                        <description><![CDATA[@frogandtoad Thank you so much for the response. I will post the code in the next slide along with the library and sketch i modified to arrive at this code. Please understand that the lines ...]]></description>
                        <content:encoded><![CDATA[<p>@frogandtoad Thank you so much for the response. I will post the code in the next slide along with the library and sketch i modified to arrive at this code. Please understand that the lines i commented were originally for the first project i did using this library. The task was to put off a fridge at 9:pm and put it on at 7:am. it worked perfectly. And because it was aimed at repeating this operation every day, there was nothing to test for other parameters like minutes, day of week, month of year and even seconds. So i assumed the code was fine. </p>
<p>I then tried to adapt the same code for an irrigation system that turns on a dc pump on specific dates and times using a cropping calendar as a criteria. That was when i discovered that the code does not respond to the functions i mentioned; months, weeks, minutes and second.</p>]]></content:encoded>
						                            <category domain="https://forum.dronebotworkshop.com/c-plus-plus/">C++</category>                        <dc:creator>abdulhak33m</dc:creator>
                        <guid isPermaLink="true">https://forum.dronebotworkshop.com/c-plus-plus/getting-and-reseting-rtc-without-using-the-ds3231-library-on-the-fly/#post-22950</guid>
                    </item>
				                    <item>
                        <title>RE: Getting and reseting RTC without using the DS3231 library on the fly</title>
                        <link>https://forum.dronebotworkshop.com/c-plus-plus/getting-and-reseting-rtc-without-using-the-ds3231-library-on-the-fly/#post-22949</link>
                        <pubDate>Mon, 06 Dec 2021 11:02:58 +0000</pubDate>
                        <description><![CDATA[@abdulhak33m 
Since you acknowledge that your code is the problem... please provide it along with your questions... that may encourage people to chime in and help, because they know the pro...]]></description>
                        <content:encoded><![CDATA[<p>@abdulhak33m </p>
<p>Since you acknowledge that your code is the problem... please provide it along with your questions... that may encourage people to chime in and help, because they know the problem.</p>
<p>Cheers.</p>]]></content:encoded>
						                            <category domain="https://forum.dronebotworkshop.com/c-plus-plus/">C++</category>                        <dc:creator>frogandtoad</dc:creator>
                        <guid isPermaLink="true">https://forum.dronebotworkshop.com/c-plus-plus/getting-and-reseting-rtc-without-using-the-ds3231-library-on-the-fly/#post-22949</guid>
                    </item>
				                    <item>
                        <title>RE: Getting and reseting RTC without using the DS3231 library on the fly</title>
                        <link>https://forum.dronebotworkshop.com/c-plus-plus/getting-and-reseting-rtc-without-using-the-ds3231-library-on-the-fly/#post-22943</link>
                        <pubDate>Sun, 05 Dec 2021 19:08:47 +0000</pubDate>
                        <description><![CDATA[@jscottbee Thanks. i have a problem using ds3231 module. i want it to trigger a relay for instance on monday January13, 2022 at 5.30am and put it off at 6.20pm. i modified a sketch from Eric...]]></description>
                        <content:encoded><![CDATA[<p>@jscottbee Thanks. i have a problem using ds3231 module. i want it to trigger a relay for instance on monday January13, 2022 at 5.30am and put it off at 6.20pm. i modified a sketch from Eric Ayars library on github but im only able to get the hour functionality and nothing else. i cant program for years, months, days of week, minutes and seconds. kindly assist as i can provide you with my code</p>]]></content:encoded>
						                            <category domain="https://forum.dronebotworkshop.com/c-plus-plus/">C++</category>                        <dc:creator>abdulhak33m</dc:creator>
                        <guid isPermaLink="true">https://forum.dronebotworkshop.com/c-plus-plus/getting-and-reseting-rtc-without-using-the-ds3231-library-on-the-fly/#post-22943</guid>
                    </item>
				                    <item>
                        <title>RE: Getting and reseting RTC without using the DS3231 library on the fly</title>
                        <link>https://forum.dronebotworkshop.com/c-plus-plus/getting-and-reseting-rtc-without-using-the-ds3231-library-on-the-fly/#post-1062</link>
                        <pubDate>Thu, 04 Jul 2019 10:36:54 +0000</pubDate>
                        <description><![CDATA[This has whetted my appetite to start some bit bashing in the alarm registers!]]></description>
                        <content:encoded><![CDATA[<p>This has whetted my appetite to start some bit bashing in the alarm registers!</p>]]></content:encoded>
						                            <category domain="https://forum.dronebotworkshop.com/c-plus-plus/">C++</category>                        <dc:creator>Pugwash</dc:creator>
                        <guid isPermaLink="true">https://forum.dronebotworkshop.com/c-plus-plus/getting-and-reseting-rtc-without-using-the-ds3231-library-on-the-fly/#post-1062</guid>
                    </item>
				                    <item>
                        <title>RE: Getting and reseting RTC without using the DS3231 library on the fly</title>
                        <link>https://forum.dronebotworkshop.com/c-plus-plus/getting-and-reseting-rtc-without-using-the-ds3231-library-on-the-fly/#post-1042</link>
                        <pubDate>Wed, 03 Jul 2019 19:19:32 +0000</pubDate>
                        <description><![CDATA[@pugwash nice.Yeah, the DS3231 is one of the nice and easy i2c devices to play with and learn i2c protocol coding with.  I had a pic based outdoors lighting controller I did back in 2005 or ...]]></description>
                        <content:encoded><![CDATA[<p>@pugwash nice.</p><p>Yeah, the DS3231 is one of the nice and easy i2c devices to play with and learn i2c protocol coding with.  I had a pic based outdoors lighting controller I did back in 2005 or 2006. The board is probably in a box somewhere now. </p><p>Good coding,</p><p>Scott</p>]]></content:encoded>
						                            <category domain="https://forum.dronebotworkshop.com/c-plus-plus/">C++</category>                        <dc:creator>jscottbee</dc:creator>
                        <guid isPermaLink="true">https://forum.dronebotworkshop.com/c-plus-plus/getting-and-reseting-rtc-without-using-the-ds3231-library-on-the-fly/#post-1042</guid>
                    </item>
				                    <item>
                        <title>Getting and reseting RTC without using the DS3231 library on the fly</title>
                        <link>https://forum.dronebotworkshop.com/c-plus-plus/getting-and-reseting-rtc-without-using-the-ds3231-library-on-the-fly/#post-1040</link>
                        <pubDate>Wed, 03 Jul 2019 19:08:05 +0000</pubDate>
                        <description><![CDATA[Another thread got my attention so I decided to code my own sketch to set RTC breakout boards. I have few RTCs lying around so I decided to write my own sketch and publish for all forum memb...]]></description>
                        <content:encoded><![CDATA[<p>Another thread got my attention so I decided to code my own sketch to set RTC breakout boards. I have few RTCs lying around so I decided to write my own sketch and publish for all forum members to use. There are no bells or whistles, so no error will be thrown if the input is not correct. </p><p>I have tried to document all procedures in the sketch, and if anyone has suggestions for improvements, I would be happy to hear them.</p><pre>// Steve Clements 2019<br />// Get or set DS3231 registers without a DS3231 library.<br />// To set the registers input a string as follows<br />// SS MM HH DW DD MM YY - use any non-digit character as a<br />// spacer or just use empty spaces as shown.<br />// Use either single or double digits i.e. 7 or 07.<br />// DW is user defined and is a value between 0 and 6, depending<br />// on which day the user decides is the first day of the week.<br /><br />#include &lt;Wire.h&gt;<br /><br />// thanks to jscottbee(forum member) for this parsing function<br />#define dec2bcd(dec_in) ((dec_in / 10) &lt;&lt; 4) + (dec_in % 10)<br /><br />int ds3231_address = 0x68; //ds3231 address, change if required.<br /><br />byte mByte; // create array for the register contents<br /><br />String dOw; // holds the Day of the Week<br /><br />void setup() {<br />Serial.begin(9600);<br />Wire.begin();<br /><br />}<br /><br />void loop() {<br /><br />delay(2000);<br /><br />// if serial input data availble, reset time<br />if(Serial.available() &gt; 0){<br />String tempString = Serial.readString();<br />setDateTime(tempString);<br />}<br /><br />// display register values in main loop<br />Wire.beginTransmission (ds3231_address); <br />Wire.write (0x00); // Set device to start read reg 0<br />Wire.endTransmission ();<br /><br />// request 19 bytes from the DS3231 and release the I2C bus<br />Wire.requestFrom(ds3231_address, 0x13, true);<br /><br />int idx = 0;<br /><br />// read the bytes into an array<br />while(Wire.available()) {<br /><br />byte input = Wire.read(); // read each byte from the register<br />mByte = input; // store each single byte in the array<br />idx++;<br />}<br /><br />// get day of the week<br /><br />switch (mByte) {<br />case 0x0:<br />dOw = "Sunday";<br />break;<br />case 0x1:<br />dOw = "Monday";<br />break;<br />case 0x2:<br />dOw = "Tuesday";<br />break;<br />case 0x3:<br />dOw = "Wednesday";<br />break;<br />case 0x4:<br />dOw = "Thursday";<br />break;<br />case 0x5:<br />dOw = "Friday";<br />break;<br />case 0x6:<br />dOw = "Saturday";<br />break;<br />default:<br />// statements<br />break;<br />}<br /><br />// print current values to serial output<br />Serial.print("Seconds = "); Serial.println(mByte, HEX);<br />Serial.print("Minutes = "); Serial.println(mByte, HEX);<br />Serial.print("Hours = "); Serial.println(mByte, HEX);<br />Serial.print("Day of Week = "); Serial.println(dOw);<br />Serial.print("Date = "); Serial.println(mByte, HEX);<br />Serial.print("Month = "); Serial.println(mByte, HEX);<br />Serial.print("Year = "); Serial.println(mByte, HEX);<br />Serial.print("On-board Chip Temperature ");Serial.print(" "); Serial.print(mByte, DEC); Serial.println("°C");<br />Serial.println();<br /><br />}<br /><br /><br /><br /><br />void setDateTime(String dateTime){<br /><br />// create empty array for datetime values<br />int dateTimeVals ={}; <br /><br />// convert string to character array<br /><br />int stringLength = dateTime.length();<br />char dateTimeArray;<br />// convert string to character array<br />dateTime.toCharArray(dateTimeArray, stringLength + 1);<br /><br />// char array index<br />int idx1 = 0;<br />// array index<br />int idx2 = 0;<br /><br />while(idx2 != 7){<br /><br />// process double digit input<br />if(isDigit(dateTimeArray) &amp;&amp; isDigit(dateTimeArray)){<br />int temp1 = int(dateTimeArray);<br />temp1 = temp1 - 48;<br />int temp2 = int(dateTimeArray);<br />temp2 = temp2 - 48;<br />dateTimeVals = (temp1 * 10) + temp2;<br />idx1 += 3;<br />}<br />// process single digit input<br />else if(isDigit(dateTimeArray) &amp;&amp; !isDigit(dateTimeArray)){<br />dateTimeVals = int(dateTimeArray - 48);<br />idx1 += 2;<br />}<br />// increment if input is not a digit<br />else{<br />idx1++;<br />}<br /><br />// increment array index<br />idx2++;<br /><br />}<br /><br />// write values to the DS3231 registers<br />Wire.beginTransmission (ds3231_address);<br />// Set device to start read reg 0<br />Wire.write (0x00);<br />for (int idx = 0; idx &lt; 7; idx++){<br />Wire.write (dec2bcd(dateTimeVals));<br />}<br /><br />Wire.endTransmission (); <br /><br />return;<br /><br /><br />}<br /><br /></pre><p>Have fun dissecting this!</p><p> </p>]]></content:encoded>
						                            <category domain="https://forum.dronebotworkshop.com/c-plus-plus/">C++</category>                        <dc:creator>Pugwash</dc:creator>
                        <guid isPermaLink="true">https://forum.dronebotworkshop.com/c-plus-plus/getting-and-reseting-rtc-without-using-the-ds3231-library-on-the-fly/#post-1040</guid>
                    </item>
							        </channel>
        </rss>
		