DS3231 RTC + Adafruit SCD30 + Notecarrier F + Feather M0 Adalogger causing hang

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:

  1. The DS3231 RTC with the SCD30 and the Notecarrier F (with the Feather Adalogger) causes this problem

  2. When it is only the RTC with the Notecarrier F and Feather, there is no problem

  3. When it is the RTC with the Notecarrier F and Feather and some other sensor such as BME280, there is no problem

  4. When it is only SCD30 and the Notecarrier F and Feather, there is no problem

  5. When it is SCD30 with the rest of the sensors such as BME280, there is no problem

  6. 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!

Hi @sbu,

The first thing I would check is to make sure there are no I2C address conflicts between any of your peripherals. Check the datasheets for each (and if there is, there is usually an alternative address you can use to avoid the conflict).

Rob

Hi,

I checked but there was no address conflict :frowning: Any other things I could try?

Thanks!

If both components work with the Notecarrier independently, there must be some conflict between them. Are you able to source an alternate sensor to replace the SCD30? What’s more confusing though, is if everything does work together for an hour first?

Hi ,

After lots of testing, I was able to narrow down the problem to the if statement. In the code, I use an if statement checking whether the time is equal to a certain time, and by using that if statement with the rtc call, for some reason the system hangs. However, when I run the system without it, and just print the time every minute (using delays), the code doesn’t hang. I even changed the if statement to a simpler one than what I was previously using, simply checking whether the minute was equal to a specific minute (removed the modulus). Does anyone have any ideas?

Thanks!

Hi @sbu,

Did you ever figure this problem out? It’s a very curious issue but it looks like the issue is with the RTC. This thread is an interesting potential solution too.

Rob