Cannot get Data Logger Shield's RTC to set using the example

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jpo43
 
Posts: 3
Joined: Tue Apr 17, 2018 2:16 pm

Cannot get Data Logger Shield's RTC to set using the example

Post by jpo43 »

Hi, I am having trouble getting the PCF8523 RTC to set on the data logger shield (the new one that uses the PCF8523 as opposed to the DS1307).

The first image is the COM output when the pcf8523 example code is uploaded, just as the data logger instructions specify.
RTCproblemImage1.png
RTCproblemImage1.png (360.96 KiB) Viewed 338 times
The second image is the COM output after uploading the same sketch and uncommenting: rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
RTCproblemImage2.png
RTCproblemImage2.png (334.8 KiB) Viewed 338 times
The third image is the COM output after manually inserting the time in the line: rtc.adjust(DateTime(2018, 4, 17, 11, 20, 0));
RTCproblemImage3.png
RTCproblemImage3.png (279.12 KiB) Viewed 338 times
All of them have crazy dates, not sure where to troubleshoot this issue.

Any help is much appreciated, thank you in advance.

Using a Due if that has anything to do with the problem.

User avatar
Franklin97355
 
Posts: 23940
Joined: Mon Apr 21, 2008 2:33 pm

Re: Cannot get Data Logger Shield's RTC to set using the exa

Post by Franklin97355 »

This might give you some help. If not please post some photos of the shield so we can take a look at the connections and soldering.
Arduino Due
The RTC is compatible (when using latest library). Accessing the SD card is possible with the addition of some jumper wires, but difficult due to the fact that the shield obscures the ICSP header where these wires must be connected.
Add jumper wire from pin 11 on shield to ICSP pin 4.
Add jumper wire from pin 12 to ICSP pin 1.
Add jumper wire from pin 13 to ICSP pin 3.
Use the standard SD library (not the Adafruit fork). Do NOT #define SOFTWARE_SPI or MEGA_SOFT_SPI in the library.
Pin and Address Reference
The shield uses the following pins:
+5V
GND
For SD card:
Digital pins 10-13 (Chip Select, MOSI, MISO, SCK, respectively)
For RTC:
SDA and SCL (on boards that have these pins)
Analog pins 4 and 5 (see notes below)
This shield can usually be stacked with others (including those using SPI or I²C), provided that each has a unique Chip Select pin (for SPI) and address (I²C), or is not using these interfaces. The RTC has a fixed address of 0x68.

Do not use Analog pins 4 or 5 with your project in combination with this shield, even on Arduino boards that use different pins for I²C communication (Leonardo, Mega, Due). For compatibility with “classic” (pre-R3) Arduino boards, the shield connects SDA and SCL to Analog pins 4 and 5, respectively; communication and analog readings would mutually interfere. Leonardo users should likewise avoid Digital pins 2 and 3 when using I²C.

User avatar
jpo43
 
Posts: 3
Joined: Tue Apr 17, 2018 2:16 pm

Re: Cannot get Data Logger Shield's RTC to set using the exa

Post by jpo43 »

Thank you for the help, I did not realize that I needed to connect SDA and SDL to analog in pins 4 and 5. Soldering those pins fixed the crazy date and times, but now another issue has come up. While I was able to adjust the date and time, once I disconnect the data logger + arduino from the PC, the clock does not keep time. In other words, my code calls for data to be recorded onto a new file and the first entry of that file is a time stamp. After disconnecting from the PC and using a wall outlet to power the unit on, the files generated all display the same time stamp as when it was uploaded from the PC. I am not sure whether this is a hardware or software issue, any guidance is deeply appreciated.

Below are the pics of the data logger shield
DataLogger1.JPG
DataLogger1.JPG (961.02 KiB) Viewed 314 times
DataLogger2.JPG
DataLogger2.JPG (994.77 KiB) Viewed 314 times
Below is my code...

Code: Select all


// included libraries
#include <SPI.h>
#include <SD.h>
#include "HX711.h"
#include "RTClib.h"
#include <Wire.h>

#define baud_rate 9600              // Serial communications bit rate
#define calibration_factor 4530     // This value is obtained using the "loadcell_calibration" script with data logger shield
#define DOUT 3                      // Pin # for data from load cell
#define CLK 2                       // Pin # for amplifier clock
#define ADAFRUIT_DATA_LOGGER 10     // Chip select pin for Adafruit data logger

HX711 scale(DOUT, CLK);

RTC_Millis rtc;

File logfile;

char filename[] = "HLTRK00.TXT";

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* 
 *  Setup Functions
 */
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void InitializeSerialCom()
{
  // initialize serial communication at specified baud rate
  Serial.begin(baud_rate);
  while (!Serial) 
  {
    ; // wait for serial port to connect
  }
  Serial.println("Serial communications initialized");
}

void SDcheck()
{
  Serial.println("Initializing SD card...");
  // check if SD is present and can be initialized
  if (!SD.begin(ADAFRUIT_DATA_LOGGER)) 
  {
    Serial.println("Card not present or initialization failure");
    // end program
    return;
  }
  Serial.println("Card initialized...");   
}

void SDcreateNewFile(char filename[])
{
  // open a new file:
  Serial.println("Creating file...");
  for (uint8_t i = 0; i < 100; i++) 
  {
    filename[5] = i/10 + '0';
    filename[6] = i%10 + '0';
    // only open a new file if it does not exist
    if (! SD.exists(filename)) 
    {
      logfile = SD.open(filename, FILE_WRITE);
      break;
    }
  }
  if (filename) 
  {
    Serial.println("file exists...");
  }
}

void InitializeLoadCell()
{
  // initialize the HX711 amplifier and zero the load cell
  scale.set_scale(calibration_factor);    // This value is obtained by using the SparkFun_HX711_Calibration sketch
  scale.tare();                           // Assuming there is no weight on the scale at start up, reset the scale to 0
}

void TimeStamp()
{
  // initialize the real time clock
  rtc.begin(DateTime(F(__DATE__), F(__TIME__)));
  DateTime now = rtc.now();

  // time stamp for the log file  
  logfile.print(now.year(), DEC);
  logfile.print('/');
  logfile.print(now.month(), DEC);
  logfile.print('/');
  logfile.print(now.day(), DEC);
  logfile.print(' ');
  logfile.print(now.hour(), DEC);
  logfile.print(':');
  logfile.print(now.minute(), DEC);
  logfile.print(':');
  logfile.print(now.second(), DEC);
  logfile.println();
  logfile.flush();

  // serial output
  Serial.println(filename);
  Serial.print(now.year(), DEC);
  Serial.print('/');
  Serial.print(now.month(), DEC);
  Serial.print('/');
  Serial.print(now.day(), DEC);
  Serial.print(' ');
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.println();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* 
 *  Loop Functions
 */
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void RecordForce()
{
  // make a string to log data
  String dataString = "";
  dataString += String(scale.get_units(), 0);
  dataString += ",";

  // open, log, and close file
  logfile = SD.open(filename, FILE_WRITE);
  logfile.println(dataString);
  logfile.close();

  Serial.print(scale.get_units(), 0);   // scale.get_units() returns a float
  Serial.print(" kg");                  // You can change this to kg but you'll need to refactor the calibration_factor
  Serial.println();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* 
 *  Arduino Program
 */
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void setup() 
{
  InitializeSerialCom();
  SDcheck();
  SDcreateNewFile(filename);
  InitializeLoadCell();
  TimeStamp();

  delay(1000);
  Serial.println("Readings:");
}

void loop() 
{
  RecordForce();
  delay(500);                         // delay for 500ms before next sample
}


User avatar
Franklin97355
 
Posts: 23940
Joined: Mon Apr 21, 2008 2:33 pm

Re: Cannot get Data Logger Shield's RTC to set using the exa

Post by Franklin97355 »

This line will set the clock to the time the program was compiled.

Code: Select all

  rtc.begin(DateTime(F(__DATE__), F(__TIME__)));
You only need to run it once to set the time and then not again. I have that line in a file by itself and compile and run that file when I need to reset an RTC.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”