0

Data logger shield/timestamp
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Data logger shield/timestamp

by hginvt on Wed Aug 29, 2018 10:51 pm

I have added the latest version of the Adafruit Data Logger Shield, with the PFC 8523 real time clock to my Arduino Uno. I was able to code the unit to log data successfully. Then I added a timestamp. The situation appears to be that when the SD card is inserted, the correct time is no longer displayed. It is replaced with "2165/165/165, 165:165:85". The logging feature continues to work, however it records the incorrect timestamp.

Code: Select all | TOGGLE FULL SIZE
// Work in Progress 27 Aug 2018
// Developing first data logging sketch
// read temperature sensor and log readings of deg C and deg F to SD card
// 28 August-- sucessfully write data to SD card, next add switch to control data logging
// 29 August-- switch added. Jumper Pin 3 to 3.3 volts to logg data, jumper to GRN to not log data
//               note: need to "re-set" Arduino after re-inserting SD card
           



#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <SD.h>
#include <SPI.h>
#include "RTClib.h"


#define ONE_WIRE_BUS 7

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

 float Celcius=0;
 float Fahrenheit=0;
 
 int inputPin=3; // jumper Pin 3 to 3.3 volts to write data to SD card, to GRN to not write to SD

 int chipSelect = 4; // chipSlect pin for the SD card reader

 File myFirstData; //Data object you will write your sensor data to

 RTC_PCF8523 rtc;
 
void setup(void)
{

  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
 
  Serial.begin(9600);
  sensors.begin();
  rtc.begin();
 
  pinMode(inputPin, INPUT);

  pinMode(10, OUTPUT); //Must declare 10 an output and reserve it
  SD.begin(4); //Initialize the SD card reader
}

void loop(void)
{


 myFirstData=SD.open("My_Data.txt", FILE_WRITE);
 
  sensors.requestTemperatures();
  Celcius=sensors.getTempCByIndex(0);
  Fahrenheit=sensors.toFahrenheit(Celcius);
  //Serial.print(" C  ");

  DateTime now = rtc.now(); //get current date&time from rtc
  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.print(", ");

 
  Serial.print(Celcius);
  Serial.print(", ");
  //Serial.print(" F  ");
  Serial.println(Fahrenheit);

 
  delay(1000);
int dlSwitch = digitalRead(inputPin);
if (dlSwitch == 1)
{
  //Serial.print(" log data");
  myFirstData.print(now.year(), DEC);
  myFirstData.print("/");
  myFirstData.print(now.month(),DEC);
  myFirstData.print("/");
  myFirstData.print(now.day(), DEC);
  myFirstData.print(", ");
  myFirstData.print(now.hour(), DEC);
  myFirstData.print(":");
  myFirstData.print(now.minute(), DEC);
  myFirstData.print(":");
  myFirstData.print(now.second(), DEC);
  myFirstData.print(", ");

 
  myFirstData.print(Celcius);
  myFirstData.print(",");
  myFirstData.println(Fahrenheit);
  myFirstData.close();
}
}
Attachments
sketch_temperature1a_SD.ino
(2.49 KiB) Downloaded 34 times
Last edited by adafruit_support_bill on Fri Aug 31, 2018 5:53 am, edited 1 time in total.
Reason: added code in-line

hginvt
 
Posts: 13
Joined: Wed Aug 29, 2018 9:42 pm

Re: Data logger shield/timestamp

by adafruit_support_bill on Thu Aug 30, 2018 5:45 am

Please post photos showing your soldering and any connections to the shield.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: Data logger shield/timestamp

by hginvt on Thu Aug 30, 2018 4:40 pm

Thanks for assistance. Photos attached
Attachments
DataLoggerPhotos.pdf
(639.5 KiB) Downloaded 45 times

hginvt
 
Posts: 13
Joined: Wed Aug 29, 2018 9:42 pm

Re: Data logger shield/timestamp

by adafruit_support_bill on Fri Aug 31, 2018 5:59 am

The soldering on A0 and A5 looks like it needs some touch-up. http://learn.adafruit.com/adafruit-guid ... n-problems

But those pins are not in use here, so are not relevant to the problem we are looking at.

The situation appears to be that when the SD card is inserted, the correct time is no longer displayed. It is replaced with "2165/165/165, 165:165:85". The logging feature continues to work, however it records the incorrect timestamp.

That is curious, since the SD card circuit is entirely separate from the RTC circuit. SD uses the SPI bus and RTC uses i2c. What processor are you using and how are you powering the system?

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: Data logger shield/timestamp

by hginvt on Fri Aug 31, 2018 4:39 pm

I don't know how to answer the question of which processor, Attached is a photo; hopefully it holds the answer.

The setup is being powered through a USB cable from a computer with a Windows7 operating system.

I appreciate your support. I'll re-solder the pins to see what effect that has.
Attachments
ArduinoUno.JPG
ArduinoUno.JPG (800.28 KiB) Viewed 358 times

hginvt
 
Posts: 13
Joined: Wed Aug 29, 2018 9:42 pm

Re: Data logger shield/timestamp

by adafruit_support_bill on Sat Sep 01, 2018 7:32 am

I'm not familiar with that brand, but it looks like an Arduino UNO clone. Clones vary quite a bit in quality - depending on the source, but most are compatible.

From the photo, it looks like you are powering from your computer via USB? So power should not be a probem.

The situation appears to be that when the SD card is inserted, the correct time is no longer displayed.

So, if you run the identical code with no card inserted, the RTC returns valid times?

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: Data logger shield/timestamp

by hginvt on Sat Sep 01, 2018 3:36 pm

Yes, it is a Uno clone. I acquired two of them. Tried the second one it appears to be working as expected; displaying time properly (although 3 minutes behind computer clock) and logging data.

Is the Adarfruit data logger designed to allow ‘hot swapping’ of SD cards.?

Thank you for all your support.

hginvt
 
Posts: 13
Joined: Wed Aug 29, 2018 9:42 pm

Re: Data logger shield/timestamp

by adafruit_support_bill on Sat Sep 01, 2018 4:03 pm

Yes, it is a Uno clone. I acquired two of them. Tried the second one it appears to be working as expected; displaying time properly (although 3 minutes behind computer clock) and logging data.

Sounds like maybe something flakey with the i2c bus on one of the processors. With the example code, some time-lag is expected, since the clock is initialized with the time of the start of the compilation. The time lag represents the difference in time from when you started the compile until the uploaded sketch actually starts running on the Arduino.

Electrically, the cards can be hot-swapped without damage. From a data corruption perspective, the issue is making sure all your data is properly flushed to the card. The good news is that the SD library only caches one 512 byte block at a time, so the amount of data loss is limited. However, you do have to remember to close or flush the file periodically to assure that the directory is updated.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: Data logger shield/timestamp

by hginvt on Thu Sep 06, 2018 12:12 am

The unit is now displaying the 'crazy" date -- 13/10/2165 and the incorrect time again. It did it spontaneously. It had been properly displaying date and time and I came back to it latter and it was incorrect. The temperature signal it is displaying is correct. What could have happened?

hginvt
 
Posts: 13
Joined: Wed Aug 29, 2018 9:42 pm

Re: Data logger shield/timestamp

by adafruit_support_bill on Thu Sep 06, 2018 8:56 am

the 'crazy" date -- 13/10/2165

"2165" generally indicates an i2c communication problem.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: Data logger shield/timestamp

by hginvt on Thu Sep 06, 2018 10:36 am

How do you solve an I2C problem? (I’m a novice and don’t understand what that means) I tried the shield on my genuine UNO and experienced the same thing?

Should I look to correcting a ‘fault’ in the shield, the Arduino, or the coding?

Thank you

hginvt
 
Posts: 13
Joined: Wed Aug 29, 2018 9:42 pm

Re: Data logger shield/timestamp

by adafruit_support_bill on Thu Sep 06, 2018 11:41 am

If you are seeing it on multiple processors, then it is likely a problem with the shield. If you contact support@adafruit.com with a link to this thread we can send a replacement.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: Data logger shield/timestamp

by hginvt on Thu Sep 06, 2018 12:50 pm

Sent request.

Thank you

hginvt
 
Posts: 13
Joined: Wed Aug 29, 2018 9:42 pm

Re: Data logger shield/timestamp

by hginvt on Tue Sep 11, 2018 1:12 am

Received re[placement and now producing correct time. Thank you.

I'm trying to set it up to write to the SD card minutely. I've tried using an IF statement with mudulo divide and the now() function, neither one worked. I have used delay (60000) and that does work, but want to see the data although only record minutely. Could you suggest code that would write to the SD card every minute? Thanks again

hginvt
 
Posts: 13
Joined: Wed Aug 29, 2018 9:42 pm

Re: Data logger shield/timestamp

by adafruit_support_bill on Tue Sep 11, 2018 5:54 am

Good to hear that the new shield is working for you.

To log every minute, try:

Code: Select all | TOGGLE FULL SIZE
if ( now.second() == 0)
{
    // data logging code
}

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.