Serial Monitor "Call"--SD card reader programing

Hello, This may be an unusual question but I am hoping someone could help.

I have a project that is utilizing the Adafruit Data Logging Shield. I have all the writing capabilities working correctly, but there is one more issue that needs to be addressed.

The card reader begins writing to the SD card only once the serial monitor is called (when hooked up to the computer). Is there a way to "call" the serial monitor when the Arduino is not hooked up to a computer? I am envisioning using a tactile button that would be programmed to start the SD card writing. Any ideas?

The card reader begins writing to the SD card only once the serial monitor is called (when hooked up to the computer).

This (the opening of the serial monitor) generates a reset on the Arduino, so you can just push the reset button to get the same effect. If this doesn't work, post your code to enable us to find the bug.


Thank you for your response.
The reset button does not initiate the SD card writing. It would be perfect if that worked like that. As far as I can tell the reset only causes the Arduino to reconnect to the computer, but does not start the SD card record.

I am using the Leonardo, with a TransmogriShield which receives the Adafruit Data Logging Shield.

The code was pieced together from a couple examples and the data is being read correctly from A0-A3:
I was thinking maybe there was a way to call the Setup function from the main loop??

/*SD card datalogger
 This example shows how to log data from multiple analog sensors 
 to an SD card using the SD library.
 The circuit:
 * analog sensors on analog ins 0, 1, 2, and D4
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 10
 created  24 Nov 2010
 modified 9 Apr 2012 by Tom Igoe
 Adapted for use 21 Mar 2013 by Robert Bantz */

#include <Wire.h> // Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <SD.h>
#include "RTClib.h"

// the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 10;

RTC_DS1307 RTC; //Define RTC Clock name

void setup()
 // Open serial communications and wait for port to open:
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only

// If you want to set the aref to something other than 5v
analogReference(EXTERNAL); //This needed!

 //Initialize RTC Communitcation
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));

//Initialize SD card communication
  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:
  Serial.println("card initialized.");

void loop()
  DateTime now =; //Call RTC current time
  // make a string for assembling the data to log:
  String dataString = "";
  dataString +=now.year();
  dataString +="/";
  dataString +=now.month();
  dataString +="/";
  dataString +=",";
  dataString +=now.hour();
  dataString +=":";
  dataString +=now.minute();
  dataString +=":";
  dataString +=now.second();
  dataString +=",";
  // read three sensors and append "," to the string:
  for (int analogPin = 0; analogPin < 4; analogPin++) 
    int sensor = analogRead(analogPin);
    delay(10);//Added to Reduce analong pin interference
    dataString += String(sensor);
    if (analogPin < 3) 
      dataString += ","; 
    delay(10); //Added to reduce analog pin interference
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile ="datalog4.csv", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    // print to the serial port too:
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
 delay(1000); //Take readings every second

Remove that code. The fact that you're using a Leonardo is relevant because the Leonardo work differently in this area (USB connection).

   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only

The mentioned code waits till the Leonardo has initialized it's USB serial driver but if the Leonardo is not connected to a host or the port not opened this will never happen. This code ensures that all serial data is being sent to the host but you don't care. You can do the wait with a timeout if you want to keep the original functionality without loosing the debugging possibility.

Worked like a charm! Thank you a ton, Pylon.

Serious kudos :)