Data randomly stops printing to SD? help!


hi,

i have arduino pro 328 5v adafruit datalogging shield using log data 9 ds18b20 temperature sensors.

i have them connected same digital data pin 3, ground , power connections.

everything seems working fine, data stops printing sd card after somewhere between 5 , 30 minutes.

i need have log continuously @ 5 min intervals battery power (6 v sealed lead acid battery), , working scientific data collection.

not sure if have hardware or software problem. code below. appreciated!!

john


#include <wire.h>
#include <onewire.h>
#include <dallastemperature.h>
#include <spi.h>                 
#include <sd.h>'
#include "rtclib.h"     
rtc_ds1307 rtc; // define 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 variable store 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 = rtc.now();
 
//make date , 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 temperature measurement library
  sensors.begin();   
 // set resolution 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 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 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 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 = rtc.now();
  datetime compiled = datetime(__date__, __time__);
  if (now.unixtime() < compiled.unixtime()) {
    serial.println("rtc older compile time! updating");
    rtc.adjust(datetime(__date__, __time__));
  }
 
}

void loop()   
{
//datetime = rtc.now();
//log every minute
     //if (now.second() > 00 || now.second() < 10) {
     
   measure();
   myfile.flush();
   delay(60000);   
 
  }

the problem power supply. how connecting battery? minimum through barrel jack 7v.

you don't need set resolution, seem doing twice.

check please read posting code.


Arduino Forum > Topics > Science and Measurement > Data randomly stops printing to SD? help!


arduino

Comments