title: Arduino SD card reader creating files but not writing to them with Nokia GLCD
body: <p>I have been busy on this for a few days and I have come up empty at every turn.
  a simple temp logging device is what Im trying to create.</p>
  
  <p>I have a working code for creating and writing to files using the serial monitor this works great but the moment I bring it into contact with any other devices ( Im using switches to navigat an LCD display it fails on the writing part)</p>
  
  <p>The code will create a file with the name I choose but will not write to that file This is my problem</p>
  
  <p>here is my code.</p>
  
  <pre><code>// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
  //A4 -- SDA
  //A5 -- SCL
  // 2 -- DS ///// Not needed really I dont think
  
  // It is assumed that the LCD module is connected to
  // the following pins using a levelshifter to get the
  // correct voltage to the module.
  //      SCK  - Pin 0
  //      MOSI - Pin 1
  //      DC   - Pin 2
  //      RST  - Pin 3
  //      CS   - Pin 5 
  //
  /*
  
   * SD card attached to SPI bus as follows:
   ** MOSI - pin 11
   ** MISO - pin 12
   ** CLK - pin 13
  
   ** CS - pin 10
  
   */
  
  
  #include &lt;LCD5110_Graph.h&gt;
  #include &lt;SD.h&gt;
  #include &lt;Wire.h&gt;
  #include "RTClib.h"
  
  LCD5110 myGLCD(0,1,2,3,5);
  RTC_DS1307 RTC;
  extern uint8_t SmallFont[];
  extern uint8_t TinyFont[];
  int up=6,down=8,enter=4,right=7,left=9; ////worked out new ones
  File root;
  char fileName[12];
  
  void setup()  
  {
    Wire.begin();
    RTC.begin();
    myGLCD.InitLCD();
    myGLCD.clrScr();
    myGLCD.setFont(SmallFont);
  
     while (! RTC.isrunning()) 
        {
          myGLCD.print("RTC NOT running!",CENTER,18);
          myGLCD.update();
          Wire.begin();
          RTC.begin();
        }  
      myGLCD.print("RTC NOW running!",CENTER,18);
      myGLCD.update();
      delay(1000);
      myGLCD.clrScr();
      myGLCD.print("Start",CENTER,18);
      myGLCD.update();
      delay(1000);
  
    pinMode(10, OUTPUT);
  
  if (!SD.begin(10)) 
  {
    myGLCD.print("FAILED!",CENTER,18);
    myGLCD.update();
    delay(1000);
  }
  else
  {
  myGLCD.print("DONE",CENTER,18);
  myGLCD.update();
  delay(1000);
  }
    pinMode(up,INPUT);
    pinMode(down,INPUT);
    pinMode(enter,INPUT);
    pinMode(left,INPUT);
    pinMode(right,INPUT);
    pinMode (A0,INPUT);
  
  
  }
  
  void loop()
  {
  myGLCD.print("Names now",CENTER,18);
  myGLCD.update();
  delay(1000);
  
  menu();
  
  float Temp
  
  root = SD.open(fileName,FILE_WRITE);
  DateTime now = RTC.now();
  
  if(root) {
    for(int p=0;p&lt;5;p++)
  {
     myGLCD.print("DONE 2",CENTER,18);
     myGLCD.update();
  
     delay(1000);
  
     /////////// Code to get the current temp
     Temp = log(((34611200/analogRead(A0)) - 33800));
     Temp = 1 / (0.000815883 + (0.000222435 * Temp) + (0.000000104 * Temp * Temp * Temp));
     Temp = Temp - 273.15;            // Convert Kelvin to Celcius
  
  
     myGLCD.clrScr();
     myGLCD.print("Temp",CENTER,18);
  
    myGLCD.update();
  
    pinMode(10,OUTPUT);
      root.print(Temp);
      root.print(" ---- ");
      root.print(now.hour());
      root.print(":");
      root.print(now.minute());
      root.print(" ");
      root.print(now.day());
      root.print("/");
      root.print(now.month());
      root.print("/");
      root.println(now.year());
    delay(2000);
  }
  
    root.close();   
  }
  else {
    myGLCD.print("Failed",CENTER,18);
    myGLCD.update();
    delay(1000);
  }
  root.close();
    }
  
  void menu()
  {
  //////////// menu to select what you want to do (create a file)
  /// then goes to picker to select name
  }
  void picker()
  {
  //// code to put a selection for a file name on the LCD USER selects this file name after that 
  ////////// .txt is added to the name
    }
  </code></pre>
  
  <p>Any help would be greatly appreciated.
  Thanks a lot :)</p>