SD data logger ain't logging to the SD card

Hi,

I have a SD data logger (based on the data logger in Adafruit) which is sending data to the serial port (using echo to serial) but it not actually logging anything into the SD card. The key issue is that the data on serial port is correct, including data, RTC timestamp, etc. But while the SD card CSV files have been created and correctly named, they have no data in them and the timestamp is 01/01/2000 @ 00:00. Here is a snippet of the serial port data;

Initializing SD card...card initialized.
Logging to: LOGGER01.CSV
millis,time,Light,Heat,angle
999, 2013/4/25 10:37:1, 2297.00, 436, -0.01
1998, 2013/4/25 10:37:2, 1847.00, 377, -0.02
3000, 2013/4/25 10:37:3, 1700.00, 347, -0.02
etc.

I have formatted the SD card both as FAT and also FAT32 (in case it made a difference). I am using Arduino Uno S/W version 1.0.3. Here is the code I am using;

// INCLUDE THE LIBRARIES
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"

// DEFINE PARAMETERS
#define LOG_INTERVAL  1000 // mills between entries
#define ECHO_TO_SERIAL   1 // echo data to serial port
#define WAIT_TO_START    0 // Wait for serial input in setup()
 
 
// DEFINE THE DIGITAL PINS THAT ARE CONNECTED TO THE LEDs
#define redLEDpin 3
#define greenLEDpin 4
 
// DEFINE THE ANALOG PINS THAT ARE CONNECTED TO THE STYLUS SENSORS
#define light_Pin 0 			// LDR connected to A0
int light_Reading; 			// the analog reading from the LDR
float light_Voltage;			// used to get value between 0 - 5000mV

#define heat_Pin 1 			// Thermistor connected to A1
int heat_Reading; 			// the analog reading from the temp
float heat_Voltage;			// used to get value between 0 - 5000mV

#define angle_Pin 2 			// Inclinometer connected to pin A2
int angle_Reading; 			// the analog reading from the angle
float angle_Voltage;			//turned into a voltage between 0 - 5000mV
float angle;				// angle in degrees +/-90deg


// REAL TIME CLOCK CODE

RTC_DS1307 RTC; // define the Real Time Clock object
// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;
 
// the logging file
File logfile;
 
void error(char *str)
{
  Serial.print("error: ");
  Serial.println(str);
  
  // red LED indicates error
  digitalWrite(redLEDpin, HIGH);
  
  while(1);
}

// SD CARD AND RTC SET UP

void setup(void)
{
  Serial.begin(9600);
  Serial.println();
  
#if WAIT_TO_START
  Serial.println("Type any character to start");
  while (!Serial.available());
#endif //WAIT_TO_START


// initialize the SD card
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
  
  // create a new file
  char filename[] = "LOGGER00.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!
    }
  }
  
  if (!logfile) 
  {
    error("couldnt create file");
  }
  
  Serial.print("Logging to: ");
  Serial.println(filename);


Wire.begin();
RTC.begin();
  if (!RTC.isrunning()) 
  {
    logfile.println("RTC failed");
#if ECHO_TO_SERIAL
    Serial.println("RTC failed");
#endif  //ECHO_TO_SERIAL
  }
  
  logfile.println("millis,time,Light,Heat,angle");    
#if ECHO_TO_SERIAL
  Serial.println("millis,time,Light,Heat,angle");
#endif //ECHO_TO_SERIAL
  
//#if ECHO_TO_SERIAL// attempt to write out the header to the file
//  if (logfile.writeError || !logfile.sync()) 
//  {
//   error("write header");
//  }
// #endif //ECHO_TO_SERIAL  

  pinMode(redLEDpin, OUTPUT);
  pinMode(greenLEDpin, OUTPUT);


  // If want to set the aref to something other than 5v
  //analogReference(EXTERNAL);
}


// MAIN CODE LOOP

void loop(void)
{
  DateTime now;
 
  // delay for the amount of time we want between readings
  delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
  
  digitalWrite(greenLEDpin, HIGH);
 
  // log milliseconds since starting
  uint32_t m = millis();
  logfile.print(m);           // milliseconds since start
  logfile.print(", ");    
#if ECHO_TO_SERIAL
  Serial.print(m);         // milliseconds since start
  Serial.print(", ");  
#endif
 
  // fetch the time
  now = RTC.now();
  // log time
 // logfile.print(now.get()); // seconds since 2000
 // logfile.print(", ");
  logfile.print(now.year(), DEC);
  logfile.print("/");
  logfile.print(now.month(), DEC);
  logfile.print("/");
  logfile.print(now.day(), DEC);
  logfile.print(" ");
  logfile.print(now.hour(), DEC);
  logfile.print(":");
  logfile.print(now.minute(), DEC);
  logfile.print(":");
  logfile.print(now.second(), DEC);
#if ECHO_TO_SERIAL
 // Serial.print(now.get()); // seconds since 2000
 // 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);
#endif //ECHO_TO_SERIAL


//GET READINGS FROM ANALOG INPUT PINS
light_Reading = analogRead(light_Pin);
delay(10);
heat_Reading = analogRead(heat_Pin);
delay(10);
angle_Reading = analogRead(angle_Pin);
delay(10);

//CODE FOR Light
light_Voltage = map(light_Reading, 0, 1023, 0, 5000);

//CODE FOR Heat
heat_Voltage = map(heat_Reading, 0, 1023, 0, 5000);

//CODE FOR INCLINOMETER
angle_Voltage = map(angle_Reading, 0, 1023, 0, 5000);
angle = ((angle_Voltage - 2500)/36000); //angle in degrees +/-90deg


// LOG THE DATA TO THE SD CARD FILE
  logfile.print(", ");    
  logfile.print(light_Voltage);
  logfile.print(", ");    
  logfile.print(heat_Reading);
  logfile.print(", ");    
  logfile.println(angle);
  
#if ECHO_TO_SERIAL
  Serial.print(", ");   
  Serial.print(light_Voltage);
  Serial.print(", ");    
  Serial.print(heat_Reading);
  Serial.print(", ");    
  Serial.println(angle);
#endif //ECHO_TO_SERIAL

digitalWrite(greenLEDpin, LOW);
}

Any help, advice, guidance or suggestions are kindly received.

Thanks,

Phil :slight_smile:

  delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
  
  digitalWrite(greenLEDpin, HIGH);
 
  // log milliseconds since starting
  uint32_t m = millis();

Really, now, is there some reason for using delay()?

Where do you close the file? If you never close the file, or flush the data in the buffer to the file, you can't really expect there to be good data in the file.

You sem to expect the SD to be open for writing all the time. It probably isn't. I think it is safer to bring all the filewrites together and have the process open-write-close each time round the loop. here is a working setup

/*  NO COSM HERE
EtherTen COM 4, Uno R3 COM 10 ON DESKTOP

//  This Arduino sketch reads DS18B20 "1-Wire" digital
//  temperature sensors.
//  http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html
//  Serial print commands are for PLX-DAQ
 size 22 894
 */
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>                  

#include <PCD8544.h>             // Nokia 5110
#include <SD.h>                  // SD card
#include <string.h>              // from Date As Filename 
#include "RTClib.h"              // from Date As Filename
#include "Wire.h"                // MUST HAVE lib for LCD disp, SD card, and serial

#define DS1307_ADDRESS 0x68

RTC_DS1307 RTC;
static PCD8544 lcd;

File myFile;
char filename[] = "00000000.CSV";

// Custom symbols
static const byte DEGREES_CHAR = 1;
static const byte degrees_glyph[] = { 0x00, 0x07, 0x05, 0x07, 0x00 };
static const byte SLASH_CHAR = 2;
static const byte slash_glyph[] = {0x00,0x20,0x10,0x08};

byte InThermo[8] =  {
  0x28, 0x69, 0xC2, 0xB0, 0x03, 0x00, 0x00, 0X9F};
byte OutThermo[8] = {
  0x28, 0x7A, 0x8B, 0xC0, 0x03, 0x00, 0x00, 0x2F};
byte DrainThermo[8] = {
  0x28, 0x09, 0xA9, 0xC0, 0x03, 0x00, 0x00, 0x95}; 

#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

int  second, minute, hour, weekDay, monthDay, month, year;

int k=0;
float InTemp, OutTemp, DrainTemp;    

void setup() {
   lcd.begin(84, 48);
     // Register the custom symbols...
  lcd.createChar(DEGREES_CHAR, degrees_glyph);
  lcd.createChar(SLASH_CHAR, slash_glyph);
  Wire.begin();
  Serial.begin(9600);
  Serial.print("    filename   ");
  delay(300);//Wait for newly restarted system to stabilize
  lcd.setCursor (0,0);
  lcd.print("Initializing");
  delay(2000);
  lcd.setCursor (0,1);

  pinMode(10, OUTPUT);

  if (!SD.begin(4)) 
  {
    lcd.print("failed!");
    delay (2000);
    return;
  }
  lcd.print("init. OK!");
  delay(2000);
      getFileName();
      Serial.println(filename);
  lcd.clear();

  Serial.println("LABEL,Time,InTemp,OutTemp,diff,DrainTemp");

  sensors.setResolution(InThermo, 12);
  sensors.setResolution(OutThermo, 12);
  sensors.setResolution(DrainThermo, 12);
}

void loop() {
  running();
  GetClock();
  if (hour == 0 && minute == 0 && second <2)
  {
    getFileName();
  }
 Serial.print("DATA,TIME,       "); 
  int ret=0;
  //get the values from the DS8B20's 
  sensors.requestTemperatures();

  float InTemp = (sensorValue(InThermo));
  float OutTemp = (sensorValue(OutThermo));  
  float DrainTemp = (sensorValue(DrainThermo)); 

  float diff = OutTemp - InTemp;

  Serial.print(InTemp);
  Serial.print(" ,  ");
  Serial.print(OutTemp);
  Serial.print(" ,  ");
  Serial.print(DrainTemp);
  Serial.println(" ,  ");

  lcd.setCursor(49,0);
  lcd.print(InTemp);
  lcd.setCursor(49,1);
  lcd.print (OutTemp);
  lcd.setCursor(49,2);
  lcd.print(DrainTemp);

  k=k+1;  

  if (k>9 )
  {  
  myFile = SD.open(filename, FILE_WRITE);//<<<<<<<<<<<<< OPEN
  myFile.print(hour);
  myFile.print(":");
  myFile.print(minute);
  myFile.print(":");
  myFile.print(second);
  myFile.print(",");

  myFile.print(InTemp);
  myFile.print(",");
  myFile.print(OutTemp);
  myFile.print(",");
  myFile.print(DrainTemp);
  myFile.print(",");
  myFile.println();
       myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE
       
      k=0;
  }
  delay(850);
}  // loop ends here

//sensorValue function
float sensorValue (byte deviceAddress[])
{
  float tempC = sensors.getTempC (deviceAddress);
  return tempC;
}

byte bcdToDec(byte val)  {
  // Convert binary coded decimal to normal decimal numbers
  return ( (val/16*10) + (val%16) );
}

void GetClock(){
  // Reset the register pointer
  Wire.beginTransmission(DS1307_ADDRESS);
  byte zero = 0x00;
  Wire.write(zero);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ADDRESS, 7);

  second = bcdToDec(Wire.read());
  minute = bcdToDec(Wire.read());
  hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  monthDay = bcdToDec(Wire.read());
  month = bcdToDec(Wire.read());
  year = bcdToDec(Wire.read());
}

void getFileName(){

  DateTime now = RTC.now();

  filename[0] = (now.year()/1000)%10 + '0'; //To get 1st digit from year()
  filename[1] = (now.year()/100)%10 + '0'; //To get 2nd digit from year()
  filename[2] = (now.year()/10)%10 + '0'; //To get 3rd digit from year()
  filename[3] = now.year()%10 + '0'; //To get 4th digit from year()
  filename[4] = now.month()/10 + '0'; //To get 1st digit from month()
  filename[5] = now.month()%10 + '0'; //To get 2nd digit from month()
  filename[6] = now.day()/10 + '0'; //To get 1st digit from day()
  filename[7] = now.day()%10 + '0'; //To get 2nd digit from day()
}

Hi all,

It is my first time with dataloggers and microSD cards.

Purchased a DFROBOT interface shield.

Have used the same code fom lady ada , and modified it to open and close files, because I also have noticed that they are not closing the files.

Also, they make a new file, everytime there is a reset.

And they are not taking into consideration, what happens when you want to stop logging.

So the result is, that I am having files without data, files that are impossible to open, with strange names.

After this, I just tried to modify the code, because I am having problems regarding opening and closing files. In the examples when there is an error opening, or closing or writing they just stop logging and let the arduino in an infinite loop.

After changing this, when there is an error the arduino tries again.

But when I open the file with my computer, there are missing values in the data, so it is also not working.

Finally in the last attempt I have killed the microSD card (8 Gbytes), my computer can not read it, can not format it, etc...

Finally my 2 questions:

1.Which is the best arduino shield to use as a datalogger, and which is the best microSD card to be used?.
2. Is there another memory storage device, more suitable for datalogging?

Thanks a lot for your patience!

If I manage to build the datalogger I need, will post it here.

Hi all,

Thank you for the comments. I have worked on this all day and still can't get the code to do what I need it to. I tried the incrementing k=k+1 method which didn't work well for my code structure. However, this then developed into a for loop that takes 100 samples then dumps them to file and closes the file and opens a new one (at least I can now get something into the files!).

I have also tried to implement an off on switch through one of the digital inputs which I hope will allow me to control when the logger is logging. I can start & stop the sampling to the screen (serial port) using an "if(readDigital(ENABLE_PIN)==HIGH))" to make the micro only collect data when the ENABLE_PIN is pulled high, but can't figure out a way to close the file to get the data into the file (when I don't close it the data obviously never gets to the SD file so they end up empty).

I still need to find a way to couple these 2 codes together (that's what I have spent the last 4 hours failing to achieve). This would mean that pulling the ENABLE_PIN low would stop data collection and dump data to the SD file. Pulling the pin high again would open a new file and start data collection again.

My failed attempts include using the "break" command with the for loop using the ENABLE_PIN going low to break (didn't work), tried using the "if" and "if-else" statements for the ENABLE_PIN both inside and outside the for loop (didn't work), and lots of variations including "goto", etc, etc. I know I should put up the code for these, but I have tried so many things I doubt anyone would even read through them all.

Instead I have added the code that uses the "for loop" that gets 100 samples into a file and writes successive files (dropping some samples in between when the processor is busy writing the data to file). Perhaps someone could advise me on how to control this set-up with the ENABLE_PIN to start/stop data collection and dump data to the SD file when stopping?

// INCLUDE THE LIBRARIES
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"

// DEFINE PARAMETERS
#define LOG_INTERVAL  1000 // mills between entries
#define ECHO_TO_SERIAL   1 // echo data to serial port
#define WAIT_TO_START    0 // Wait for serial input in setup()
 
 
// DEFINE THE DIGITAL PINS THAT ARE CONNECTED TO THE LEDs
#define redLEDpin 3
#define greenLEDpin 4
#define ENABLE_PIN 5

// DEFINE THE ANALOG PINS THAT ARE CONNECTED TO THE STYLUS SENSORS
#define light_Pin 0 			// LDR connected to A0
int light_Reading; 			// the analog reading from the LDR
float light_Voltage;			// used to get value between 0 - 5000mV

#define heat_Pin 1 			// Thermistor connected to A1
int heat_Reading; 			// the analog reading from the temp
float heat_Voltage;			// used to get value between 0 - 5000mV

#define angle_Pin 2 			// Inclinometer connected to pin A2
int angle_Reading; 			// the analog reading from the angle
float angle_Voltage;			//turned into a voltage between 0 - 5000mV
float angle;				// angle in degrees +/-90deg


// REAL TIME CLOCK CODE

RTC_DS1307 RTC; // define the Real Time Clock object
// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;
 
// the logging file
File logfile;
 
void error(char *str)
{
  Serial.print("error: ");
  Serial.println(str);
  
  // red LED indicates error
  digitalWrite(redLEDpin, HIGH);
  
  while(1);
}

// SD CARD AND RTC SET UP

void setup(void)
{
  Serial.begin(9600);
  Serial.println();
// initialize the SD card
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
  
 Wire.begin();
RTC.begin();
  if (!RTC.isrunning()) 
  {
    logfile.println("RTC failed");
#if ECHO_TO_SERIAL
    Serial.println("RTC failed");
#endif  //ECHO_TO_SERIAL
  }
  RTC.adjust(DateTime(__DATE__, __TIME__));
}

// MAIN CODE LOOP

void loop(void)
{
   // create a new file
  char filename[] = "LOGGER00.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!
    }
  }
  
  if (!logfile) 
  {
    error("couldnt create file");
  }
  
  Serial.print("Logging to: ");
  Serial.println(filename);

  logfile.println("millis,time,Light,Heat,angle");    
#if ECHO_TO_SERIAL
  Serial.println("millis,time,Light,Heat,angle");
#endif //ECHO_TO_SERIAL
  
//#if ECHO_TO_SERIAL// attempt to write out the header to the file
//  if (logfile.writeError || !logfile.sync()) 
//  {
//   error("write header");
//  }
// #endif //ECHO_TO_SERIAL  

  pinMode(redLEDpin, OUTPUT);
  pinMode(greenLEDpin, OUTPUT);



for(int j=0; j<100; j++) // <<<<<<<<<<<<<<<<<<<START OF FOR LOOP
{
 
  DateTime now;
  digitalWrite(greenLEDpin, HIGH);
  now = RTC.now();
  
  uint32_t m = millis();
  logfile.print(m);           // milliseconds since start
  logfile.print(", ");    
#if ECHO_TO_SERIAL
  Serial.print(m);         // milliseconds since start
  Serial.print(", ");  
#endif
 
 //GET READINGS FROM ANALOG INPUT PINS
light_Reading = analogRead(light_Pin);
delay(10);
heat_Reading = analogRead(heat_Pin);
delay(10);
angle_Reading = analogRead(angle_Pin);
delay(10);

//CODE FOR Light
light_Voltage = map(light_Reading, 0, 1023, 0, 5000);

//CODE FOR Heat
heat_Voltage = map(heat_Reading, 0, 1023, 0, 5000);

//CODE FOR INCLINOMETER
angle_Voltage = map(angle_Reading, 0, 1023, 0, 5000);
angle = ((angle_Voltage - 2500)/36000); //angle in degrees +/-90deg

// LOG THE TIME & DATE DATA TO SD CARD FILE
  logfile.print(now.year(), DEC);
  logfile.print("/");
  logfile.print(now.month(), DEC);
  logfile.print("/");
  logfile.print(now.day(), DEC);
  logfile.print(" ");
  logfile.print(now.hour(), DEC);
  logfile.print(":");
  logfile.print(now.minute(), DEC);
  logfile.print(":");
  logfile.print(now.second(), DEC);
#if ECHO_TO_SERIAL
  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);
#endif //ECHO_TO_SERIAL


// LOG THE SENSOR DATA TO SD CARD FILE
  logfile.print(", ");    
  logfile.print(light_Voltage);
  logfile.print(", ");    
  logfile.print(heat_Reading);
  logfile.print(", ");    
  logfile.println(angle);
  
#if ECHO_TO_SERIAL
  Serial.print(", ");   
  Serial.print(light_Voltage);
  Serial.print(", ");    
  Serial.print(heat_Reading);
  Serial.print(", ");    
  Serial.println(angle);
#endif //ECHO_TO_SERIAL
} 
  
logfile.close();//>>>>>>>>>>>>>>>>>>>>>>CLOSE
 
digitalWrite(greenLEDpin, LOW);

}

thanks,

Phil

I would point out the I use the k=k+1 only because, while there is a display print every trip through the loop, the write to file is only on every tenth trip. Sorry if there was any confusion there.

I fail to see why you need to accumulate data and then send it to file. It just seems a lot of angst for no known purpose. It isn't clear whether you are trying to use an on/off switch because you want to, or because you feel you have to in order to get some sort of result, but aren't getting it anyway.

If the former, then the latter clearly doesn't bear thinking about. all you need to do is:

.
.
.
read the clock
read the data
open SD
file.print as required
close SD
.
.

as nauseam, or for ever.

I would probably need an off on switch as I plan to log data at specific times. I can't find a way (that works in practice) that closes the file on demand.

Thanks,

Phil

PhilUWB:
I would probably need an off on switch as I plan to log data at specific times.

fair enuff. You could use a clock.

I can't find a way (that works in practice) that closes the file on demand.

You demand the file closes with the command

logfile.close();

In practice, this works every time, without fail.

I would probably need an off on switch as I plan to log data at specific times.

Not really. The switch could, using the state change detection example, toggle a boolean (and an LED pin) that defines whether you are logging, or not.

If you are, you open the file when the switch is pressed once, and close it when the switch is pressed again.

On the other passes through loop(), you simply check the flag:

if(logging)
{
  // Write to the SD card
}

I as trying to use the if logging method, but I either got one reading per file or the header line in between each line of reading. reading. That's what has been frustrating me, I feel I have tried every permutation of brackets around different code in the if statement and moving sections of code around. Hence I ended up on the forums soliciting help.

Thanks,

Phil

I as trying to use the if logging method, but I either got one reading per file or the header line in between each line of reading. reading. That's what has been frustrating me, I feel I have tried every permutation of brackets around different code in the if statement and moving sections of code around. Hence I ended up on the forums soliciting help.

So, you are changing code, and we are supposed to know what you are changing without seeing it? We've hired a psychic, but his start date is the 12th of never. If you need help before then...

PhilUWB:
I feel I have tried every permutation of brackets around different code in the if statement and moving sections of code around.

There is only just so much code you can use, and you probably have too many brackets. It might help to get rid of all the ifs and as many brackets as you can. Read my reply #5 again, it really is that simple, so that you just read the data and record it every time you go round the loop. Once that's doing the its job, you can start adding if conditions - if and as required.

That way you get a stream of data recorded, and then you will know what to delete when it goes pear-shaped. Indeed, once there, the if and as may amount to unlikely and rarely.

Getting rid of the LEDs, and all that echo stuff won't go astray either.

PaulS:

I as trying to use the if logging method, but I either got one reading per file or the header line in between each line of reading. reading. That's what has been frustrating me, I feel I have tried every permutation of brackets around different code in the if statement and moving sections of code around. Hence I ended up on the forums soliciting help.

So, you are changing code, and we are supposed to know what you are changing without seeing it? We've hired a psychic, but his start date is the 12th of never. If you need help before then...

I thought he was starting real soon on April 31? When did you change his starting date? :stuck_out_tongue:

PaulS:

I as trying to use the if logging method, but I either got one reading per file or the header line in between each line of reading. reading. That's what has been frustrating me, I feel I have tried every permutation of brackets around different code in the if statement and moving sections of code around. Hence I ended up on the forums soliciting help.

So, you are changing code, and we are supposed to know what you are changing without seeing it? We've hired a psychic, but his start date is the 12th of never. If you need help before then...

Thanks, I was essentially looking guidance on how to take my current code (posted) and make it have a start stop function. If posting pages of code with one or two changes is encouraged then I would need to post multiple, almost identical, scripts with a line added/removed/altered in the hope that someone has 10 hours to kill and reads all my code (I also didn't document and save every little change I made as it was typically worse than the base code I posted). I was trying to be efficient with forum space while maximising the chance of someone reading it and responding. I already knew that my multiple changes didn't work any better than the code I posted, so I didn't see the value in filling the thread needlessly.

Would you agree PaulS, or do you see merit in me documenting and posting all my tweaks?

Thanks,

Phil

Would you agree PaulS

No, I don't. You have some code that doesn't work. Your have three choices, as I see it.

One is to keep making random changes in the hope that something works.

Another is to study all the functions and statements that you are using, to understand exactly what they are doing. Typically, this involves making small changes, predicting the effect, and observing the results. The closer the results are to the predictions, the more likely it is that you understand what you are doing, and are well on your way to becoming a proficient coder.

The third is to post your code, describing what you expect it to do and what it actually does. We review it, and make some suggestions and maybe point out things that are wrong. You make the suggested changes, one at a time, and observe the effects. If something we suggest is clearly not working, let us know, and post the code. We can then determine whether you made the suggested change correctly, with the correct curly brace positioning, etc.

If something does work, let us know.

The choices are yours. We get paid the same regardless. Nothing, that is.

You have no code to prevent the creation of a new file each time that the loop() function starts. Test the state of ENABLE_PIN before creating a new file at the start of loop(). If it is LOW then don't create a new file, take any readings or attempt to file them, else, do what you do now.

UKHeliBob:
You have no code to prevent the creation of a new file each time that the loop() function starts. Test the state of ENABLE_PIN before creating a new file at the start of loop(). If it is LOW then don't create a new file, take any readings or attempt to file them, else, do what you do now.

Now sorted, thanks!