Hi,
I have an Arduino Pro 328 5V with an adafruit datalogging shield which I am using to log data from 9 ds18b20 temperature sensors.
I have them all connected to the same digital data pin 3, with ground and power connections.
Everything seems to be working fine, but data just stops printing to the SD card after somewhere between 5 and 30 minutes.
I need to have this log continuously at 5 min intervals from battery power (6 V sealed lead acid battery), and get it working soon for scientific data collection.
Not sure if I have a hardware or software problem. My code is below. Any help is appreciated!!
John
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <SD.h>'
#include "RTClib.h"
RTC_DS1307 RTC; // define the Real Time Clock object
//RTC_Millis RTC;
File myFile;
#define ONE_WIRE_BUS_PIN 3
OneWire oneWire(ONE_WIRE_BUS_PIN);
DallasTemperature sensors(&oneWire);
//int numberOfDevices; // Number of temperature devices found
//DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address
const int chipSelect = 10;
//float tempC, Temp01, Temp02, Temp03, Temp04, Temp05, Temp06, Temp07, Temp08, Temp09;
DeviceAddress Probe01 = { 0x28, 0xFF, 0x5C, 0x37, 0x2E, 0x04, 0x00, 0x69 };
DeviceAddress Probe02 = { 0x28, 0xFF, 0x5D, 0x78, 0x65, 0x14, 0x01, 0x9C };
DeviceAddress Probe03 = { 0x28, 0xFF, 0x20, 0x80, 0x65, 0x14, 0x01, 0x70 };
DeviceAddress Probe04 = { 0x28, 0xFF, 0x03, 0x2F, 0x65, 0x14, 0x01, 0xF5 };
DeviceAddress Probe05 = { 0x28, 0xFF, 0x39, 0x92, 0x65, 0x14, 0x01, 0xC0 };
DeviceAddress Probe06 = { 0x28, 0xFF, 0x9B, 0x38, 0x65, 0x14, 0x01, 0xC2 };
DeviceAddress Probe07 = { 0x28, 0xFF, 0x0F, 0x38, 0x65, 0x14, 0x01, 0x6A };
DeviceAddress Probe08 = { 0x28, 0xFF, 0xE6, 0x68, 0x64, 0x14, 0x02, 0xD2 };
DeviceAddress Probe09 = { 0x28, 0xFF, 0x6D, 0xD1, 0x64, 0x14, 0x02, 0x6B };
void measure(){
char filename[] = "Testfile.CSV";
SD.begin(chipSelect);
myFile = SD.open(filename, FILE_WRITE);
//pinMode(10, OUTPUT);
DateTime now = RTC.now();
//make date and time
char dt[16];
char tm[16];
sprintf(dt, "%02d/%02d/%02d", now.year(),now.month(),now.day());
sprintf(tm, "%02d:%02d:%02d", now.hour(),now.minute(),now.second());
myFile.print(dt);
myFile.print(" ");
myFile.print(tm);
myFile.print(",");
Serial.print(dt);
Serial.print(" ");
Serial.print(tm);
Serial.print(",");
// Initialize the Temperature measurement library
sensors.begin();
// set the resolution to 12 bit
sensors.setResolution(Probe01, 12);
sensors.setResolution(Probe02, 12);
sensors.setResolution(Probe03, 12);
sensors.setResolution(Probe04, 12);
sensors.setResolution(Probe05, 12);
sensors.setResolution(Probe06, 12);
sensors.setResolution(Probe07, 12);
sensors.setResolution(Probe08, 12);
sensors.setResolution(Probe09, 12);
//Get temperature from sensors
sensors.requestTemperatures();
float Temp01 = sensors.getTempC(Probe01);
float Temp02 = sensors.getTempC(Probe02);
float Temp03 = sensors.getTempC(Probe03);
float Temp04 = sensors.getTempC(Probe04);
float Temp05 = sensors.getTempC(Probe05);
float Temp06 = sensors.getTempC(Probe06);
float Temp07 = sensors.getTempC(Probe07);
float Temp08 = sensors.getTempC(Probe08);
float Temp09 = sensors.getTempC(Probe09);
//Print temp to SD
myFile.print(Temp01);
myFile.print(",");
myFile.print(Temp02);
myFile.print(",");
myFile.print(Temp03);
myFile.print(",");
myFile.print(Temp04);
myFile.print(",");
myFile.print(Temp05);
myFile.print(",");
myFile.print(Temp06);
myFile.print(",");
myFile.print(Temp07);
myFile.print(",");
myFile.print(Temp08);
myFile.print(",");
myFile.print(Temp09);
myFile.println();
Serial.print(Temp01);
Serial.print(",");
Serial.print(Temp02);
Serial.print(",");
Serial.print(Temp03);
Serial.print(",");
Serial.print(Temp04);
Serial.print(",");
Serial.print(Temp05);
Serial.print(",");
Serial.print(Temp06);
Serial.print(",");
Serial.print(Temp07);
Serial.print(",");
Serial.print(Temp08);
Serial.print(",");
Serial.print(Temp09);
Serial.println();
}
void setup()
{
Serial.begin(9600);
delay(300);
Serial.print("Initializing Temperature Control Library Version ");
Serial.println(DALLASTEMPLIBVERSION);
Serial.print("Initializing");
delay(2000);
pinMode(10, OUTPUT);
//digitalWrite(10, HIGH);
delay(1);
if (!SD.begin(chipSelect))
{
Serial.print("failed!");
delay (2000);
return;
}
Serial.println(" init. OK!");
sensors.begin();
Serial.print("Number of Devices found on bus = ");
Serial.println(sensors.getDeviceCount());
char filename[] = "Testfile.CSV";
myFile = SD.open(filename, FILE_WRITE);
//Set addresses for digital sensors
sensors.setResolution(Probe01, 12);
sensors.setResolution(Probe02, 12);
sensors.setResolution(Probe03, 12);
sensors.setResolution(Probe04, 12);
sensors.setResolution(Probe05, 12);
sensors.setResolution(Probe06, 12);
sensors.setResolution(Probe07, 12);
sensors.setResolution(Probe08, 12);
sensors.setResolution(Probe09, 12);
Wire.begin();
if (!RTC.begin()) {
myFile.println("RTC failed");
Serial.println("RTC failed");
}
DateTime now = RTC.now();
DateTime compiled = DateTime(DATE, TIME);
if (now.unixtime() < compiled.unixtime()) {
Serial.println("RTC is older than compile time! Updating");
RTC.adjust(DateTime(DATE, TIME));
}
}
void loop()
{
//DateTime now = RTC.now();
//log every minute
//if (now.second() > 00 || now.second() < 10) {
measure();
myFile.flush();
delay(60000);
}