0

DS3231 example/demo sketch - erratic time
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

DS3231 example/demo sketch - erratic time

by Igor_van_Dame on Sun Jul 16, 2017 9:38 pm

I have the Adafruit DS3231 RTC connected to a Mega2560 R3 that also has the Adafruit Datalogging Shield (1141) installed.

When I 'reset' the time either by removing the battery, etc. per the tutorial or add the
rtc.adjust(Datetime(2017, 7, 16, 20, 46, 0));
just above the if loop for detecting lost power (not in the loops) .... and then re-edit the file to comment the added line out (once the RTC understands that it is not 1/1/1970) and re-load the sketch ...

The serial monitor shows the date as:
2017/7/16 (Sunday) 20:4:0
since midnight ... 1500235440s

then it repeats the exact same result (including the unix second total) 10 times without changing.

Then it changes to:
2017/7/10 (Monday) 20:4:0
since mindnight ... 1499717040s

That date/time repeats unchanged 40 times

Then it changes to:
2017/7/0 (Friday) 20:0:0
since midnight ... 1498852800s

That is repeated 40 times

Then it changes to:
2017/7/2 (Sunday) 20:0:0
since midnight... 1499025600s

[ok, so you're bored at this point]
it jumps from 2017/7/2 to 2017/7/4 then 7/6 then 7/0 then 7/10, 7/12, 7/14, 7/16 then 7/10, 7/0 ..2/4/6/0/10 etc.
changes every 40 loops of the program. Never goes to 8 always stops at 6 in the sequence before repeating.

I've changed batteries, so that is not the problem. The board is not 'mounted' but on a card table surface. Sure looks like random noise effects to me. Any suggestions on stabilizing the output?

Thanks in advance for the help.
Last edited by Igor_van_Dame on Mon Jul 17, 2017 6:37 am, edited 1 time in total.

Igor_van_Dame
 
Posts: 20
Joined: Sun Jun 21, 2015 9:09 am

Re: DS3231 example/demo sketch - erratic time

by franklin97355 on Sun Jul 16, 2017 10:05 pm

Could you post large (less than 1meg), clear, detailed pictures of both sides of your board showing any soldering you have done and the connections to it?

franklin97355
 
Posts: 16842
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: DS3231 example/demo sketch - erratic time

by Igor_van_Dame on Tue Jul 18, 2017 3:32 pm

Images linked here:
http://imgur.com/a/IWfV7

That being said, I'm working on software de-bouncing and have a batch of Schmidt triggers coming in to hardware de-bounce the project. That still doesn't help the random time issues mentioned here. I do have two other DS3231s installed at another location (production site) and will try the same sketch there.

Igor_van_Dame
 
Posts: 20
Joined: Sun Jun 21, 2015 9:09 am

Re: DS3231 example/demo sketch - erratic time

by franklin97355 on Tue Jul 18, 2017 4:04 pm

Let's see what the others do and go from there.

franklin97355
 
Posts: 16842
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: DS3231 example/demo sketch - erratic time

by Igor_van_Dame on Fri Jul 21, 2017 10:46 am

Today I'm on the production system and I'm getting similar results from another DS3231 installed there.

Although the day of the week changes, I'll focus on the current time portion of the now function.
I reset the RTC to 2017 7 21 10 20 0
I also added some Serial.println(); lines to place the hour/minute/second responses on separate lines.
My concern is that the h/m/s responses are being truncated to one digit.

Here is the result of pushing buttons 1, 2, 3 and 4 (only the button 1 Serial.print section has been modified with println():
Code: Select all | TOGGLE FULL SIZE
WAV Trigger v1.30b 
Number of tracks = 16
Initializing SD card...logging to: LOGGER22.CSV
2017/7/21
 (Friday)
0
:0
:0
,1500595200,1
2017/7/21 (Friday) 0:0:0,1500595200,2
2017/7/21
 (Friday)
0
:0
:0
,1500595200,1
2017/7/21 (Friday) 0:0:0,1500595200,4
2017/7/20 (Thursday) 0:0:0,1500508800,3
2017/7/20 (Thursday) 0:0:0,1500508800,2
2017/7/20 (Thursday) 0:0:0,1500508800,3
2017/7/20 (Thursday) 0:0:0,1500508800,4
2017/7/20 (Thursday) 0:0:0,1500508800,3
2017/7/20
 (Thursday)
0
:0
:0
,1500508800,1
2017/7/20 (Thursday) 0:0:0,1500508800,2


Here is the portion of the program generating this result:

Code: Select all | TOGGLE FULL SIZE
if (wTrig.isTrackPlaying(1)) {
//   Serial.print("Track 1 is playing\n");
   gLedState = 1;   // Turn on PB1 LED
        digitalWrite(LED23,gLedState);
  buttonNumber = 1;
//  Serial.println(buttonNumber);
//  Serial.print('\n');
//  Serial.println(lastButtonNumber);

        if (buttonNumber != lastButtonNumber) {
          delay(1000);
            DateTime now = rtc.now();
   
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.println();
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
        Serial.println();
    Serial.print(now.hour(), DEC);
        Serial.println();
    Serial.print(':');
    Serial.print(now.minute(), DEC);
        Serial.println();
    Serial.print(':');
    Serial.print(now.second(), DEC);
        Serial.println();
    Serial.print(',');
   
 //   Serial.print(" since midnight 1/1/1970 = ");
    Serial.print(now.unixtime());
 //   Serial.print("s = ");
 //   Serial.print(now.unixtime() / 86400L);
 //   Serial.println("d");
 Serial.print(',');
 Serial.print(buttonNumber);
 Serial.print('\n');

     
    logfile.print(now.year(), DEC);
    logfile.print('/');
    logfile.print(now.month(), DEC);
    logfile.print('/');
    logfile.print(now.day(), DEC);
    logfile.print(" (");
    logfile.print(daysOfTheWeek[now.dayOfTheWeek()]);
    logfile.print(") ");
    logfile.print(now.hour(), DEC);
    logfile.print(':');
    logfile.print(now.minute(), DEC);
    logfile.print(':');
    logfile.print(now.second(), DEC);
    logfile.print(',');
   
 //   Serial.print(" since midnight 1/1/1970 = ");
    logfile.print(now.unixtime());
 //   Serial.print("s = ");
 //   Serial.print(now.unixtime() / 86400L);
 //   Serial.println("d");
 logfile.print(',');
 logfile.print(buttonNumber);
 logfile.print('\n');
 logfile.flush(); // Added to force write to card without closing .csv file
    lastButtonNumber = buttonNumber;
        }
}
else if   (!wTrig.isTrackPlaying(1)) {
//      Serial.print("Track 1 is done\n");
      gLedState = 0;   // Turn off PB1 LED
                digitalWrite(LED23,gLedState);
                    DateTime now = rtc.now();

}


The code is basically the code copied from the DS3231 tutorial with the button sensing logic added (the Robersonics WAV Trigger talks to the Mega via Serial TX1/Rx1.

The unixtime is still not incrementing either

Igor_van_Dame
 
Posts: 20
Joined: Sun Jun 21, 2015 9:09 am

Re: DS3231 example/demo sketch - erratic time

by Igor_van_Dame on Sat Jul 22, 2017 5:54 pm

Sigh. I think I know what is the cause of the errors - not sure how to fix it yet.

Waaaay back in January I posted this forum question: viewtopic.php?f=31&t=110888
The question was directed at 'how' to use the DS3231 with the Datalogger shield. The response told me to ignore the logging shield - so I didn't worry about the PCF8523. I didn't/don't quite understand the use of the SQW/GPIO connection in the context of the example DS3231 example sketch or my program.

Here's what I did today. I had another DS3231 at home, so I added a header to it and connected it (without battery) to another Mega 2560 *without the datalogger shield attached*. I uploaded the example sketch, and voila the time/date is correct and the seconds are counting like they should. Puzzled, I removed the DS3231 from the Mega/Dataloger and swapped it out with the one on the Mega 2560 alone. *That worked perfectly* hmmm. I moved it back to the Mega/Logger ... same bogus time output.

Please note that my normal script for this project (not the example sketch, but using the same datetime logic) specifies that the RTC is a DS3231 ( RTC_DS3231 rtc; ) - so the library knows which section it should be using. It seems all that does is set the I2C address?

I disconnected the DS3231 from the Mega/Logger assembly and tried running the DS3231 example sketch again. The result was exactly like what I noted above/prevously - bogus dates wandering from what was set, and no seconds changing on the unixtime. But without the DS3231 connected it must be reading this from the PCF8523 that is on the DataLogger shield (!).

SOO ...
Contrary to the response from the post from January linked above, how does one *turn off/ignore* the RTC mounted on the Data Logger Shield and use an external one?

Unfortunately Adafruit does not sell a SD/logging shield unit (Similar to the Vellman VMA304 https://www.vellemanstore.com/en/vellem ... ino-2-pack but with a 32GB capacity) so I need to disable the PCF8523 and get the Mega to look to the SDA/SCL pins 20/21 instead of the board.

How do I do that?

Igor_van_Dame
 
Posts: 20
Joined: Sun Jun 21, 2015 9:09 am

Re: DS3231 example/demo sketch - erratic time

by adafruit_support_mike on Sun Jul 23, 2017 4:01 am

The easiest way to disable the PCF8523 on the FeatherWing would be to cut the trace from the SDA pin.

There is an address conflict between the PCA8532 and the DS3231 (0x64 in both cases), so you have to isolate the one you don't want from the I2C bus. Cutting the SDA trace will keep the PCA8532 from ever seeing its address, leaving the DS3231 free to oprerate.

adafruit_support_mike
 
Posts: 45111
Joined: Thu Feb 11, 2010 2:51 pm

Re: DS3231 example/demo sketch - erratic time

by Igor_van_Dame on Sun Jul 23, 2017 4:15 pm

This is the Adafruit Data Logging Shield (1141) and not the Feather Adalogger.

Part of my problem I believe stems from the fact that the SDA/SCL markings on the Mega 2560 appear only on the two pins next to TX1/RX1 (20/21). The 'other' SDA/SCL pins which mimic the UNO are next to the 2x3 header for ICMP connection to the USB and are not labelled on the circuitboard. So, I thought there was only one (20/21) and never quite realized that the connection to the shield was already made (in afterthought it would have to for it to function).

So, I cut/broke off the SDA pin and ran the DS3231 example - I was getting a date of 2165 and a month day of 165/145 hmmm. I then clipped the SCL .. and then pins A4 and A5 (which are the optional SDA/SCL pins ... and still got the bogus date. It turns out I had wired the Vin/G/SDA/SCL connections to the DS3231 to the 'other' four pins on the breakout board. Once corrected, the date/time worked as expected.

Running the PCF8523 example resulted in lots of binary on the serial port. Just mentioning it in case others have the result - means your SDA conneciton to the motherboard is bad.

In summary:
If you want to connect the Adafruit Logging Shield to a Mega 2560:
- Edit the SD.begin function to list pins 10, 51, 50, 52 (not 10,11,12,13 as stated in the tutorial)

If you want to bypass the PCF8523 on the Shield and use another (better) RTC,
- Remove the SDA header pin on the shield (2 pins to the left of the SD card holder) and connect your external RTC to pins 20/21 on the Mega 2560.

Igor_van_Dame
 
Posts: 20
Joined: Sun Jun 21, 2015 9:09 am

Please be positive and constructive with your questions and comments.