Hi I am trying to create a circuit that takes carbon dioxide readings every 4th minute of the hour but the problem is that when I put it in loop, after about approximately an hour, the code begins to hang and though everything is still powered on, nothing is functioning anymore. I ran a few tests to see what is causing the problem and came to this conclusion:
-
The DS3231 RTC with the SCD30 and the Notecarrier F (with the Feather Adalogger) causes this problem
-
When it is only the RTC with the Notecarrier F and Feather, there is no problem
-
When it is the RTC with the Notecarrier F and Feather and some other sensor such as BME280, there is no problem
-
When it is only SCD30 and the Notecarrier F and Feather, there is no problem
-
When it is SCD30 with the rest of the sensors such as BME280, there is no problem
-
When it is only the SCD30 and the RTC (controlled with an Arduino Nano), there is no problem
I am not sure what to do in terms of fixing it though, even though I narrowed down the combination that is causing the problem.
This is my code:
#include <RTClib.h>
#include <Wire.h>
#include <Adafruit_SCD30.h>
#include <Notecard.h>
#include <SD.h>
#include <SPI.h>
RTC_DS3231 rtc;
Notecard notecard;
File dataFile;
Adafruit_SCD30 scd30;
double temp;
double hum;
double co2;
const int chipSelect = 4;
String file_name;
#define productUID “com.gmail.aparna.bulusu:soil_co2_flux_”
void setUpConnectionNotehub(){
notecard.begin();
notecard.setDebugOutputStream(Serial);
J *req = notecard.newRequest(“hub.set”);
JAddStringToObject(req, “product”, productUID);
JAddStringToObject(req, “mode”, “continuous”);
notecard.sendRequest(req);
}
String setUpRTC(){
Wire.begin();
rtc.begin();
//rtc.adjust(DateTime(F(DATE),F(TIME)));
DateTime time1 = rtc.now();
Serial.println(“in setup rtc method”);
String date = String(time1.month()) + “/” + String(time1.day()) + “/” + String(time1.year()) + " " + String(time1.hour())+ “:” + String(time1.minute())+ “:” + String(time1.second());
Serial.println(date);
//time1 = date;
return date;
}
void printSCD30(){
if (scd30.dataReady()) {
if (!scd30.read()){ Serial.println(“Error reading sensor data”); return; }
double co2_ppm = scd30.CO2;
Serial.print(“CO2 Level: “);
Serial.print(co2_ppm);
co2 = scd30.CO2;
Serial.println(” ppm”);
Serial.print("Temperature: ");
Serial.print(scd30.temperature);
double temperature = scd30.temperature;
temp = scd30.temperature;
Serial.println(" degrees C");
Serial.print("Relative Humidity: ");
Serial.print(scd30.relative_humidity);
double humidity = scd30.relative_humidity;
hum = scd30.relative_humidity;
Serial.println(" %");
}
else{
Serial.println(“data not ready”);
}
}
void setup() {
setUpConnectionNotehub();
// put your setup code here, to run once:
String time1 = setUpRTC();
Serial.begin(9600);
file_name = “rtccur.txt”;
if (!scd30.begin()) {
Serial.println(“Failed to find SCD30 sensor!”);
while (1);
}
Serial.println(“scd30 found!”);
//delay(2000);
if (!scd30.startContinuousMeasurement()){
Serial.println(“Failed to start continuous measurement”);
while(1){ delay(10);}
}
scd30.setMeasurementInterval(2); // Set measurement interval to 4 seconds
if (scd30.dataReady()) {
if (!scd30.read()){ Serial.println(“Error reading sensor data”); return; }
double co2_ppm = scd30.CO2;
Serial.print(“CO2 Level: “);
Serial.print(co2_ppm);
//co2 = scd30.CO2;
Serial.println(” ppm”);
Serial.print("Temperature: ");
Serial.print(scd30.temperature);
double temperature = scd30.temperature;
//temp = scd30.temperature;
Serial.println(" degrees C");
Serial.print("Relative Humidity: ");
Serial.print(scd30.relative_humidity);
double humidity = scd30.relative_humidity;
//hum = scd30.relative_humidity;
Serial.println(" %");
}
else{
Serial.println(“data not ready”);
}
}
void loop() {
// put your main code here, to run repeatedly:
DateTime time1 = rtc.now();
if((time1.minute()%2)==0 && time1.second()==0){
Serial.println(“printed time at 2nd minute”);
String date = String(time1.hour())+ “:” + String(time1.minute())+ “:” + String(time1.second());
if (scd30.dataReady()) {
if (!scd30.read()){ Serial.println("Error reading sensor data"); return; }
double co2_ppm = scd30.CO2;
Serial.print("CO2 Level: ");
Serial.print(co2_ppm);
co2 = scd30.CO2;
Serial.println(" ppm");
Serial.print("Temperature: ");
Serial.print(scd30.temperature);
double temperature = scd30.temperature;
temp = scd30.temperature;
Serial.println(" degrees C");
Serial.print("Relative Humidity: ");
Serial.print(scd30.relative_humidity);
double humidity = scd30.relative_humidity;
hum = scd30.relative_humidity;
Serial.println(" %");
}
else{
Serial.println(“data not ready”);
}
//printSCD30();
delay(60000);
}
}
Thanks!