Hello,
i have a problem. I want to build this temperature data logger:
As i can see there are some errors in the code.
The compilator says:
Compilation error: no matching function for call to 'DS3231::DS3231(const uint8_t&, const uint8_t&)'
Can someone help me fix this error?
And I want to use a DS1307-Module-V03 instead of a DS3231. But I don't think there should be much difference...
as @kolaha wonders, so do I. Have you installed the correct DS32321 library?
No matter which RTC you use, the code must compile first. It has no idea which module if any is in use.
Once it compiles, it is likely that the code needn't change, unless features of the DS3231 not available in this DS1307 are being exploited. This is somewhat rare.
Are you trying to get code you didn't write or mess with (yet) to work first?
First of all, thank you for your answers, I am relatively new to Arduino and am dealing with this code for the first time...
Yes, I have installed all the required libraries. But the program still cannot be compiled.
/*
* Program to demonstrate Data Logging/Visualisation using Arduino
*
* ###Connection with SD card module###
* Vcc->5V
* Gnd->Gnd
* MISO->pin 12
* MOSI->pin 11
* SCK-> pin 13
* CS-> pin 4
*
* ###Connection with DS3231###
* Vcc->5V
* Gns->Gnd
* SCL->pin A5
* SDA-> pin A4
*
* ###Connection with DT11###
* Vcc->5V
* Gnd->Gnd
* Out-> pin 7
*
*
*/
#include <DS3231.h> //Library for RTC module (Download from Link in article)
#include <SPI.h> //Library for SPI communication (Pre-Loaded into Arduino)
#include <SD.h> //Library for SD card (Pre-Loaded into Arduino)
#include <dht.h> //Library for dht11 Temperature and Humidity sensor (Download from Link in article)
#define DHT11_PIN 7 //Sensor output pin is connected to pin 7
dht DHT; //Sensor object named as DHT
const int chipSelect = 4; //SD card CS pin connected to pin 4 of Arduino
// Init the DS3231 using the hardware interface
DS3231 rtc(SDA, SCL);
void setup()
{
// Setup Serial connection
Serial.begin(9600);
Initialize_SDcard();
Initialize_RTC();
Initialize_PlxDaq();
}
void loop()
{
Read_DHT11();
Write_SDcard();
Write_PlxDaq();
delay(5000); //Wait for 5 seconds before writing the next data
}
void Write_PlxDaq()
{
Serial.print("DATA"); //always write "DATA" to Indicate the following as Data
Serial.print(","); //Move to next column using a ","
Serial.print("DATE"); //Store date on Excel
Serial.print(","); //Move to next column using a ","
Serial.print("TIME"); //Store date on Excel
Serial.print(","); //Move to next column using a ","
Serial.print(DHT.temperature); //Store date on Excel
Serial.print(","); //Move to next column using a ","
Serial.print(DHT.humidity); //Store date on Excel
Serial.print(","); //Move to next column using a ","
Serial.println(); //End of Row move to next row
}
void Initialize_PlxDaq()
{
Serial.println("CLEARDATA"); //clears up any data left from previous projects
Serial.println("LABEL,Date,Time,Temperature,Humidity"); //always write LABEL, to indicate it as first line
}
void Write_SDcard()
{
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("LoggerCD.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.print(rtc.getDateStr()); //Store date on SD card
dataFile.print(","); //Move to next column using a ","
dataFile.print(rtc.getTimeStr()); //Store date on SD card
dataFile.print(","); //Move to next column using a ","
dataFile.print(DHT.temperature); //Store date on SD card
dataFile.print(","); //Move to next column using a ","
dataFile.print(DHT.humidity); //Store date on SD card
dataFile.print(","); //Move to next column using a ","
dataFile.println(); //End of Row move to next row
dataFile.close(); //Close the file
}
else
Serial.println("OOPS!! SD card writing failed");
}
void Initialize_SDcard()
{
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("LoggerCD.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println("Date,Time,Temperature,Humidity"); //Write the first row of the excel file
dataFile.close();
}
}
void Initialize_RTC()
{
// Initialize the rtc object
rtc.begin();
//#### The following lines can be uncommented to set the date and time for the first time###
/*
rtc.setDOW(FRIDAY); // Set Day-of-Week to SUNDAY
rtc.setTime(18, 46, 45); // Set the time to 12:00:00 (24hr format)
rtc.setDate(6, 30, 2017); // Set the date to January 1st, 2014
*/
}
void Read_DHT11()
{
int chk = DHT.read11(DHT11_PIN);
}
/*void Read_DateTime()
{
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.println(rtc.getTimeStr());
}*/
/*void Read_TempHum()
{
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
// delay(1000);
}*/
/*
* Program to demonstrate Data Logging/Visualisation using Arduino
*
* ###Connection with SD card module###
* Vcc->5V
* Gnd->Gnd
* MISO->pin 12
* MOSI->pin 11
* SCK-> pin 13
* CS-> pin 4
*
* ###Connection with DS3231###
* Vcc->5V
* Gns->Gnd
* SCL->pin A5
* SDA-> pin A4
*
* ###Connection with DT11###
* Vcc->5V
* Gnd->Gnd
* Out-> pin 7
*
*
*/
#include <DS3231.h> //Library for RTC module (Download from Link in article)
#include <SPI.h> //Library for SPI communication (Pre-Loaded into Arduino)
#include <SD.h> //Library for SD card (Pre-Loaded into Arduino)
#include <dht.h> //Library for dht11 Temperature and Humidity sensor (Download from Link in article)
#define DHT11_PIN 7 //Sensor output pin is connected to pin 7
dht DHT; //Sensor object named as DHT
const int chipSelect = 4; //SD card CS pin connected to pin 4 of Arduino
// Init the DS3231 using the hardware interface
DS3231 rtc(SDA, SCL);
void setup()
{
// Setup Serial connection
Serial.begin(9600);
Initialize_SDcard();
Initialize_RTC();
Initialize_PlxDaq();
}
void loop()
{
Read_DHT11();
Write_SDcard();
Write_PlxDaq();
delay(5000); //Wait for 5 seconds before writing the next data
}
void Write_PlxDaq()
{
Serial.print("DATA"); //always write "DATA" to Indicate the following as Data
Serial.print(","); //Move to next column using a ","
Serial.print("DATE"); //Store date on Excel
Serial.print(","); //Move to next column using a ","
Serial.print("TIME"); //Store date on Excel
Serial.print(","); //Move to next column using a ","
Serial.print(DHT.temperature); //Store date on Excel
Serial.print(","); //Move to next column using a ","
Serial.print(DHT.humidity); //Store date on Excel
Serial.print(","); //Move to next column using a ","
Serial.println(); //End of Row move to next row
}
void Initialize_PlxDaq()
{
Serial.println("CLEARDATA"); //clears up any data left from previous projects
Serial.println("LABEL,Date,Time,Temperature,Humidity"); //always write LABEL, to indicate it as first line
}
void Write_SDcard()
{
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("LoggerCD.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.print(rtc.getDateStr()); //Store date on SD card
dataFile.print(","); //Move to next column using a ","
dataFile.print(rtc.getTimeStr()); //Store date on SD card
dataFile.print(","); //Move to next column using a ","
dataFile.print(DHT.temperature); //Store date on SD card
dataFile.print(","); //Move to next column using a ","
dataFile.print(DHT.humidity); //Store date on SD card
dataFile.print(","); //Move to next column using a ","
dataFile.println(); //End of Row move to next row
dataFile.close(); //Close the file
}
else
Serial.println("OOPS!! SD card writing failed");
}
void Initialize_SDcard()
{
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("LoggerCD.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println("Date,Time,Temperature,Humidity"); //Write the first row of the excel file
dataFile.close();
}
}
void Initialize_RTC()
{
// Initialize the rtc object
rtc.begin();
//#### The following lines can be uncommented to set the date and time for the first time###
/*
rtc.setDOW(FRIDAY); // Set Day-of-Week to SUNDAY
rtc.setTime(18, 46, 45); // Set the time to 12:00:00 (24hr format)
rtc.setDate(6, 30, 2017); // Set the date to January 1st, 2014
*/
}
void Read_DHT11()
{
int chk = DHT.read11(DHT11_PIN);
}
/*void Read_DateTime()
{
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.println(rtc.getTimeStr());
}*/
/*void Read_TempHum()
{
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
// delay(1000);
}*/
/*
Program to demonstrate Data Logging/Visualisation using Arduino
###Connection with SD card module###
Vcc->5V
Gnd->Gnd
MISO->pin 12
MOSI->pin 11
SCK-> pin 13
CS-> pin 4
###Connection with DS3231###
Vcc->5V
Gns->Gnd
SCL->pin A5
SDA-> pin A4
###Connection with DT11###
Vcc->5V
Gnd->Gnd
Out-> pin 7
*/
#include <RTClib.h> //Library for RTC module (Download from Link in article)
#include <Wire.h>
#include <SPI.h> //Library for SPI communication (Pre-Loaded into Arduino)
#include <SD.h> //Library for SD card (Pre-Loaded into Arduino)
#include <dht.h> //Library for dht11 Temperature and Humidity sensor (Download from Link in article)
#define DHT11_PIN 7 //Sensor output pin is connected to pin 7
dht DHT; //Sensor object named as DHT
RTC_DS3231 rtc;
const int chipSelect = 4; //SD card CS pin connected to pin 4 of Arduino
void setup() {
Serial.begin(9600);
Initialize_SDcard();
rtc.begin();
}
void loop() {
Write_SDcard();
delay(5000); //Wait for 5 seconds before writing the next data
}
void Write_SDcard() {
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
int chk = DHT.read11(DHT11_PIN);
DateTime now = rtc.now();
File dataFile = SD.open("LoggerCD.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
char bufer[50];
sprintf(bufer, "%02u.%02u.%02u,%02u:%02u:%02u,%01.1f,%01.1f\r\n",
now.year(),
now.month(),
now.day(),
now.hour(),
now.minute(),
now.second(),
DHT.temperature,
DHT.humidity
);
dataFile.print(bufer);
dataFile.close(); //Close the file
}
else
Serial.println("OOPS!! SD card writing failed");
}
void Initialize_SDcard() {
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("LoggerCD.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println("Date,Time,Temperature,Humidity"); //Write the first row of the excel file
dataFile.close();
}
}
txt file have nothing to do with setting the time.
you can upload RTC example, it will probably set local time and show it. after that upload logger sketch. you can use SD.exist() method to avoid adding "Date,Time,Temperature,Humidity" at every single start
void Write_SDcard() {
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
int chk = DHT.read11(DHT11_PIN);
float t= DHT.temperature;
float h=DHT.humidity;
Serial.println(t,1);
Serial.println(h,1);
DateTime now = rtc.now();
File dataFile = SD.open("LoggerCD.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
char bufer[50];
sprintf(bufer, "%02u.%02u.%02u,%02u:%02u:%02u,%0.1f,%0.1f\r\n",
now.year(),
now.month(),
now.day(),
now.hour(),
now.minute(),
now.second(),
t,
h
);
dataFile.print(bufer);
dataFile.close(); //Close the file
}
else
Serial.println("OOPS!! SD card writing failed");
}
Now the code looks like that.
But it still writes the same "? ?" like in post 16
Did I do everything correctly?
/*
Program to demonstrate Data Logging/Visualisation using Arduino
###Connection with SD card module###
Vcc->5V
Gnd->Gnd
MISO->pin 12
MOSI->pin 11
SCK-> pin 13
CS-> pin 4
###Connection with DS3231###
Vcc->5V
Gns->Gnd
SCL->pin A5
SDA-> pin A4
###Connection with DT11###
Vcc->5V
Gnd->Gnd
Out-> pin 7
*/
#include <RTClib.h> //Library for RTC module (Download from Link in article)
#include <Wire.h>
#include <SPI.h> //Library for SPI communication (Pre-Loaded into Arduino)
#include <SD.h> //Library for SD card (Pre-Loaded into Arduino)
#include <dht.h> //Library for dht11 Temperature and Humidity sensor (Download from Link in article)
#define DHT11_PIN 7 //Sensor output pin is connected to pin 7
dht DHT; //Sensor object named as DHT
RTC_DS3231 rtc;
const int chipSelect = 4; //SD card CS pin connected to pin 4 of Arduino
void setup() {
Serial.begin(9600);
Initialize_SDcard();
rtc.begin();
}
void loop() {
Write_SDcard();
delay(5000); //Wait for 5 seconds before writing the next data
}
void Write_SDcard() {
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
int chk = DHT.read11(DHT11_PIN);
float t= DHT.temperature;
float h=DHT.humidity;
Serial.println(t,1);
Serial.println(h,1);
DateTime now = rtc.now();
File dataFile = SD.open("LoggerCD.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
char bufer[50];
sprintf(bufer, "%02u.%02u.%02u,%02u:%02u:%02u,%0.1f,%0.1f\r\n",
now.year(),
now.month(),
now.day(),
now.hour(),
now.minute(),
now.second(),
t,
h
);
dataFile.print(bufer);
dataFile.close(); //Close the file
}
else
Serial.println("OOPS!! SD card writing failed");
}
void Initialize_SDcard() {
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("LoggerCD.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println("Date,Time,Temperature, Humidity"); //Write the first row of the excel file
dataFile.close();
}
}