Data logger shield/timestamp

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

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
hginvt
 
Posts: 13
Joined: Wed Aug 29, 2018 9:42 pm

Data logger shield/timestamp

Post by hginvt »

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

// 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

[The extension ino has been deactivated and can no longer be displayed.]

Last edited by adafruit_support_bill on Fri Aug 31, 2018 5:53 am, edited 1 time in total.
Reason: added code in-line

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Data logger shield/timestamp

Post by adafruit_support_bill »

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

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

Re: Data logger shield/timestamp

Post by hginvt »

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

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Data logger shield/timestamp

Post by adafruit_support_bill »

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?

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

Re: Data logger shield/timestamp

Post by hginvt »

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 550 times

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Data logger shield/timestamp

Post by adafruit_support_bill »

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?

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

Re: Data logger shield/timestamp

Post by hginvt »

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.

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Data logger shield/timestamp

Post by adafruit_support_bill »

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.

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

Re: Data logger shield/timestamp

Post by hginvt »

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?

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Data logger shield/timestamp

Post by adafruit_support_bill »

the 'crazy" date -- 13/10/2165
"2165" generally indicates an i2c communication problem.

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

Re: Data logger shield/timestamp

Post by hginvt »

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

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Data logger shield/timestamp

Post by adafruit_support_bill »

If you are seeing it on multiple processors, then it is likely a problem with the shield. If you contact [email protected] with a link to this thread we can send a replacement.

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

Re: Data logger shield/timestamp

Post by hginvt »

Sent request.

Thank you

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

Re: Data logger shield/timestamp

Post by hginvt »

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

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Data logger shield/timestamp

Post by adafruit_support_bill »

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

To log every minute, try:

Code: Select all

if ( now.second() == 0)
{
    // data logging code
}

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

Return to “Arduino Shields from Adafruit”