SD card read/write with Arduino

...rest of the code:

 if (second == 0) {  // this code writes data to the sector_buffer every minute
   Serial.println("Writing data...");
   sector_buffer[WriteAddress] = day;
//   Serial.print(sector_buffer[WriteAddress]);
//   Serial.print(", day = ");
//   Serial.println(day);
   ++WriteAddress;
   sector_buffer[WriteAddress] = month;
//   Serial.print(sector_buffer[WriteAddress]);
//   Serial.print(", month = ");
//   Serial.println(month);
   ++WriteAddress;
   sector_buffer[WriteAddress] = (year-2000);
   ++WriteAddress;
   sector_buffer[WriteAddress] = hour;
   ++WriteAddress;
   sector_buffer[WriteAddress] = minute;
   ++WriteAddress;
   sector_buffer[WriteAddress] = byte(temperature);
   ++WriteAddress;
      span = 50;  unsigned int VBatt = 0;
      for (byte b = 0; b < span; b++) {        //loop to get average of 50 readings
        VBatt = VBatt + analogRead(1);
        }
      VBatt = VBatt / span;
   sector_buffer[WriteAddress] = byte(VBatt/79);
   ++WriteAddress;
   sector_buffer[WriteAddress] = byte(VBatt%79);
   ++WriteAddress;
// Note:
// The battery voltage on the divider ranges from 0 to 13.5 volts.
// The voltage on the arduino pin ranges from 0 to 5 volts using 2200- & 3900-ohm resistors.
// So an analogRead value of 1023 = 13 volts on the divider
// Therefore one bit is equal to 1024 divided by 13V = 78.769, rounded to 79.
      span = 50;  unsigned int VPanel = 0;
      for (byte P = 0; P < span; P++) {        //loop to get average of 50 readings
        VPanel = VPanel + analogRead(2);
        }
      VPanel = VPanel / span;
// *** NEED TO FIND OUT max V output of solar panel, divide 1024 by this, then replace 79 with the result. ***
   sector_buffer[WriteAddress] = byte(VPanel/79);
   ++WriteAddress;
   sector_buffer[WriteAddress] = byte(VPanel%79);
   ++WriteAddress;
   if (WriteAddress > 512) {
     SDWrite;
     ++sector;
     WriteAddress = 0;
   }
  }

  // check for any incoming serial input, then Dump Data only if 'd' is pressed
  if (Serial.available() > 0) {
    incomingByte = Serial.read();      
    if (incomingByte == 100) {
      DataDump();
    }
  }
 delay(1000);
}

There are a few redundunt bits & pieces, & lots of comments for my own benefit, but it shouldn't be real hard for the rest of you who are as new to this as I am to follow! :slight_smile:

Sorry, I've got to head out of the office now so this is a bit of a rushed response... If more info is required I'll check in again later today/tonight.

Thanks again,

JB.

-* EDIT *- After having a bit more time to digest your response I've made a couple of modifications to the code; it probably still has some gaping errors but it's semi-functional & allows for testing...