I have set up a temperature data logger with SD card on an Uno which works. Now I need to include an RTC for time stamps and well as logging at specific times of the day.
For the past week I have tried to add a DS1302 RTC.
I used a new sketch for the RTC on the same board with the data logger components connected. This worked as planned and gave me real time readings.
I inserted the RTC sketch into the Data logger sketch and it crashed.
I then copied parts of the RTC sketch until it crashed again.
My sketch refers:
The error occured after Line 40 RtcDateTime compiled = RtcDateTime(DATE, TIME);
When I used "printDateTime(compiled);" on line 41 I received the Error: "'printDateTime' was not declared in this scope"
Every attempt to access the Date time is foiled. Every working examples I have looked at with "DateTime now = rtc.now();" gives me "Not declared in this scope"
I have only been working with Arduino for 2 months so still learning.
Please point me in the right direction.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SD.h> //Load SD card library
#include<SPI.h> //Load SPI Library
//for RTC
#include <ThreeWire.h>
#include <RtcDS1302.h>
ThreeWire myWire(4, 5, 2); // RTC Data pin 4, SCLK pin 5, CE pin 2
RtcDS1302 Rtc(myWire);
// Data wire is plugged into digital pin (was 2) now 7 on the Arduino
#define ONE_WIRE_BUS 7
// Setup a oneWire instance to communicate with any OneWire device
OneWire oneWire(ONE_WIRE_BUS);
OneWire ds(7); //changed from 2 for RTC
// Pass oneWire reference to DallasTemperature library
DallasTemperature sensors(&oneWire);
float tempSensor1, tempSensor2, tempSensor3, tempSensor4, tempSensor5;
// Addresses of DS18B20s
uint8_t sensor1[8] = { 0x28, 0x28, 0xF6, 0x75, 0xD0, 0x01, 0x3C, 0xDA };
uint8_t sensor2[8] = { 0x28, 0x9D, 0x9C, 0x76, 0xE0, 0x01, 0x3C, 0xCC };
uint8_t sensor3[8] = { 0x28, 0x47, 0x2F, 0x75, 0xD0, 0x01, 0x3C, 0x90 };
uint8_t sensor4[8] = { 0x28, 0x9E, 0x42, 0x75, 0xD0, 0x01, 0x3C, 0x3F };
uint8_t sensor5[8] = { 0x28, 0xBF, 0x1C, 0x75, 0xD0, 0x01, 0x3C, 0x89 };
int chipSelect = 8; //chipSelect pin for the SD card Reader - Changed from 4 to cater for RTC
File mySensorData; //Data object for writing sesnor data to
void setup()
{
Serial.begin(9600);
Serial.print("compiled: ");
Serial.print(DATE);
Serial.println(TIME);
Rtc.Begin();
RtcDateTime compiled = RtcDateTime(DATE, TIME);
printDateTime(compiled); //ERROR MESSAGE printDateTime' was not declared in this scope
Serial.println();
sensors.begin();
SD.begin(8); //Initialize the SD card reader
}
void loop()
{
sensors.requestTemperatures();
tempSensor1 = sensors.getTempC(sensor1); // Ambient temperature
tempSensor2 = sensors.getTempC(sensor2); // Inlet temperature
tempSensor3 = sensors.getTempC(sensor3); // Inside Container temperature
tempSensor4 = sensors.getTempC(sensor4); // Top of Container temperature
tempSensor5 = sensors.getTempC(sensor5); // Top of Container temperature
Serial.print(" Inside_container:");
Serial.print(tempSensor3);
Serial.print(" Top_container:");
Serial.print(tempSensor4);
Serial.print(" Top_Chimney:");
Serial.print(tempSensor5);
Serial.println("");
delay(5000);
mySensorData = SD.open("PTData.txt", FILE_WRITE);
if (mySensorData)
{
mySensorData.print(tempSensor3); //write temperature 1 data to card
mySensorData.print(","); //write a commma
mySensorData.print(tempSensor4);
mySensorData.print(",");
mySensorData.println(tempSensor5);
mySensorData.close(); //close the file
}