Arash (Customer) asked a question.

Hello, Could you please help with my question? Here is my code, I have been trying to add clock (exact time and date of temperature data acquisition). However, it says that there is no AnalogRTCLib.h ! I believe that I installed AnalogRTCLib from library.

#include <Arduino.h>

#include <P1AM.h>

#include <SPI.h>

#include <SD.h>

#include <Wire.h>

#include "RTClib.h"

 

RTC_DS1307 rtc; // create an instance of the RTC library

 

const int SD_CS_PIN = SDCARD_SS_PIN; // SD card CS pin connected to P1AM slot 1 pin 4

const float VCC = 3.3; // supply voltage of the voltage divider circuit

const float VREF = 5.0; // reference voltage of the P1AM input module

const float R_REF = 1000.0; // reference resistor value for the voltage divider circuit

const float R_0 = 1000.0; // resistance of the PT1000 sensor at 0 degrees Celsius

const float A = 3.9083e-6; // constant A for PT1000 RTD

const float B = -5.775e-7; // constant B for PT1000 RTD

 

float temperature[4]; // array to store temperature readings

float resistance[4]; // array to store resistance calculations

unsigned long previousMillis = 0; // variable to store the last time a data point was collected

const unsigned long interval = 5000; // interval between data collection in milliseconds

const unsigned long duration = 500000; // duration of data collection in milliseconds

 

File myFile; // file object for writing to SD card

const char P1_04RTD_CONFIG[] = { 0x40, 0x03, 0x60, 0x03, 0x20, 0x02, 0x80, 0x00 }; // PT1000 configuration

const int SLOT_NUMBER = 1; // slot number where the input module is connected

 

void setup() {

  Serial.begin(9600); // initialize serial communication at 9600 baud

  while (!P1.init()) {

    ; // wait for input module to initialize

  }

 

  P1.configureModule(P1_04RTD_CONFIG, SLOT_NUMBER); // configure input module with PT1000 settings for slot 1

 

  pinMode(SD_CS_PIN, OUTPUT); // set SD card CS pin as output

  if (!SD.begin(SD_CS_PIN)) { // initialize SD card

    Serial.println("SD card initialization failed!");

    while (1); // stop program if initialization fails

  }

 

  rtc.begin(); // initialize the RTC module

  if (!rtc.isrunning()) { // check if RTC module is running

    Serial.println("RTC is NOT running!");

  }

 

  myFile = SD.open("data.csv", FILE_WRITE); // open file for writing

  if (myFile) { // check if file opened successfully

    Serial.println("File opened for writing.");

    myFile.println("Date,Time,Channel,Temperature"); // write headers to file

  } else {

    Serial.println("Error opening file for writing!");

  }

}

 

void loop() {

  DateTime now = rtc.now(); // get current date and time from RTC module

  unsigned long currentMillis = millis(); // get the current time

  if (currentMillis - previousMillis >= interval) { // check if interval has elapsed

    previousMillis = currentMillis; // update previous time

 

    for (int i = 0; i < 4; i++) {

      temperature[i] = P1.readTemperature(1, i + 1); // read temperature from input channel i+1 in slot 1

      resistance[i] = (VCC * R_REF * temperature[i]) / (VREF * (VCC - temperature[i])); // calculate resistance using voltage divider circuit equation

 

      myFile.print(millis()); // write current time to file

      myFile.print(","); // separate time and temperature with comma

      myFile.print(i + 1); // write channel number to file

      myFile.print(",");

      myFile.println(temperature[i]); // write temperature to file and add newline character

 

      Serial.print("Channel "); // print a label for the temperature reading

      Serial.print(i + 1);

      Serial.print(": ");

      Serial.print(temperature[i]); // print the temperature value

      Serial.println(" degrees Celsius"); // print the unit of measurement for temperature

    }

  }

 

  if (currentMillis >= duration) { // check if duration has elapsed

    myFile.close(); // close file when program ends

    Serial.println("Data collection complete.");

    while (1); // stop program

  }

}

 


  • ADC Community_02 (Automationdirect.com)

    Your include is showing RTClib I believe it should be:

    1. #include <AnalogRTCLibrary.h>

     

  • Arash (Customer)

    Unfortunately, It didnt work!

  • Arash (Customer)

    I just want to report the time and date of the temperature data acquisition and put it in the excel file

  • Tinker (Customer)

    You wrote; " I believe that I installed AnalogRTCLib from library."

    I would double check that is actually the case, if so, I would try one of the example that come with the library and see if that works. If the library is not actually installed I'd try to install it again.