Hi, the following code is from a program that is too big to be posted. I only posted part of it. The setup part is below in case it is required. I left everything even non related to RTC since simple RTC code work but not this. Maybe there is conflicting device in my bigger program.
It is a simple code that run on arduino uno that fetch time from a RTC DS1307 and send it to the serial port. Thing is, when I test it in a simple DS1307 code, it work fine but when I copy it to my bigger program, the two lines "Timestamp_date and Timestamp_Time don't return anything while the other time related lines returns correct time data. This suggest the RTC work fine but don't respond to the now.timestamp command.
I can't figure why it work in a test code and not anymore in the bigger code. Any suggestion?
PROBLEMATIC CODE HERE:
void Send_to_PC() {
// Send data to monitor
if (Serialport) {
// Fetch time data
DateTime now = rtc.now(); // fetch actual date and time
// Assembling and copying the data string
Serial.print(now.timestamp(DateTime::TIMESTAMP_DATE)); /// LINE NOT WORKING
Serial.print(" ");
Serial.print(now.timestamp(DateTime::TIMESTAMP_TIME)); /// LINE NOT WORKING
Serial.print(" ");
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(Ref_flag);
Serial.print(" ");
Serial.print(Cycle_completed);
Serial.print(" ");
Serial.print(Atm_temp);
Serial.print(" ");
Serial.print(Atm_Humi);
Serial.print(" ");
Serial.print(Atm_hPa);
Serial.print(" ");
Serial.print(Chamber_hPa); // hPa
Serial.print(" ");
Serial.print(Sensor_offset); // hPa
Serial.print(" ");
Serial.print(Bubble_vol); // mL
Serial.print(" ");
Serial.print(CH4_chamber); // %
Serial.print(" ");
Serial.print(DegreC); // %
Serial.print(" ");
Serial.println(z); // Compteur
}
SETUP CODE HERE JUST IN CASE:
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include "RTClib.h"
#include "Adafruit_MPRLS.h"
//#include <Adafruit_Sensor.h>
#include <BME280I2C.h>
RTC_DS1307 rtc; // define the Real Time Clock object
Adafruit_MPRLS MPRLS = Adafruit_MPRLS(); // MPRLS Object
BME280I2C bme; // Default : forced mode, standby time = 1000 ms
// Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,
int z;
int Event;
int Bubble_flag;
char daysOfTheWeek[7][24] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
float MPRLS_hPa;
float Chamber_hPa;
float Chamber_volume;
float Atm_hPa;
float Atm_temp;
float Atm_Humi;
float Bubble_vol;
bool Serialport;
bool Ref_flag; // 0 = Monitoring mode tag 1 = ref line tag
float Vol_threshold;
float DegreC;
float CH4_chamber;
float Sensor_offset;
int Cycle_completed;
int Relay_SGX = 2; // Heating the SGX sensor
int Relay_Vent = 3; // Open solenoid
int Relay_Pump = 4; // Pump air out
const int chipSelect = 10;
File logfile;
void setup() {
Serialport = 1; // Set to false when not testing
if (Serialport) {
Serial.begin(57600);
Serial.println("Serial connected");
}
pinMode(10, OUTPUT); // Chip select pin for SD card
pinMode(Relay_SGX, OUTPUT); // Relay SGX
pinMode(Relay_Vent, OUTPUT); // Relay Sol 1
pinMode(Relay_Pump, OUTPUT); // Relay Pump
MPRLS.begin();
bme.begin();
// Initializing RTC
Wire.begin();
///////////////////////////////
#ifndef ESP8266
while (!Serial); // wait for serial port to connect. Needed for native USB
#endif
///////////////////////////////
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1); // Will stop here if RTC have problem
}
Serial.println("RTC connected");
if (! MPRLS.begin()) {
Serial.println("Couldn't find MPRLS");
while (1); // Will stop here if MPRLS have problem
}
Serial.println("MPRLS connected");
if (! bme.begin()){
Serial.println("Couldn't find bme");
while (1); // will stop here if BME have problem
}
Serial.println("BME280 connected");
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
// Cette commande induit un délai d'environ 5 sec vs ordi
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
// SD card initialization
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present"); // Will stop here if the card have problem
}
Serial.println("SD card initialized.");
// create a new file on SD card
char filename[] = "BUBBLE00.CSV";
for (uint8_t i = 0; i < 100; i++) {
filename[6] = i / 10 + '0';
filename[7] = i % 10 + '0';
if (! SD.exists(filename)) {
// only open a new file if it doesn't exist
logfile = SD.open(filename, FILE_WRITE);
break; // leave the loop
}
}
// Monitoring info
Serial.print("Filename is: ");
Serial.println(filename);
Serial.println("File header is:");
Serial.println("Cycle_completed Atm_temp Humidity Atm_hPa Chamber_hPa Sensors_offset Bubble_volume CH4_chamber SGX_temp z"); // Put the correct Header here
logfile.println("Cycle_completed Atm_temp Humidity Atm_hPa Chamber_hPa Sensors_offset Bubble_volume CH4_chamber SGX_temp"); // Must be identical as previous line
Chamber_volume = 200; // Ajust this volume to match the chamber in mL
Sensor_offset = 0; // initial offset
Ref_flag = 1; // The program will start by adjusting the pressure offset between sensors
Cycle_completed = 0;
z = 0;
Bubble_flag = 0
Event = 0;
}
thank you for your help