Need help writing data to text file on SD card.

I'm currently using Arduino 1.0.1 for windows. I have a program to get the temperature from a DS1620 temp sensor. I first tested it by printing values on the serial monitor and it worked fine. When I try to write these values to the SD card however, it doesn't work. There is no error at compilation or when code is uploaded, but the text file is not created. I thought maybe it was an error with the SD.open() function but when I tried an example with the SD library, I was able to create new text files easily.

#include <DS1620.h>
#include <SD.h>
// Define pins for 3-wire serial communication
int dq = 5;
int clk = 7;
int rst = 3;

// Call DS1620 constructor using pin variables
DS1620 d = DS1620(dq, clk, rst);
File heatFile;

void setup()
{  
  // Start serial communications, 9600 baud
  Serial.begin(9600);
  
  while(!Serial)
  {
    ;
  }
  
  pinMode(10, OUTPUT);
  
  if(!SD.begin(4))
  {
    Serial.println("initialization failed!");
    return;
  }
  heatFile = SD.open("tempsensor.txt", FILE_WRITE);
  // Write TH and TL setpoints to DS1620 EEPROM  
  // Settings are retained even with no power
  d.write_th(30);
  d.write_tl(15);
  
  // Write config to DS1620 configuration/status register
  // Decimal 10 = Binary 00001010
  // Enables CPU-Mode and disables 1-Shot Mode.
  // See Datasheet for details
  d.write_config(10);
  
  // Start continuous temperature conversion
  // Readings can be read about once per second this way
  d.start_conv();

  // Print TH and TL to serial monitor
  Serial.print("TH = "); Serial.println(d.read_th());
  Serial.print("TL = "); Serial.println(d.read_tl());
  
  
  
  Serial.println(d.read_temp());
  
  int data = d.read_temp();
  heatFile.write(data);
  heatFile.close();
  // Wait 1 second (1000 ms) before reading next temperature
  delay(1000);
  
}

void loop()
{
  //  Read and print temperature (degrees C) to serial monitor
  
}

The filename is probably causing the trouble. You must use filenames with an 8.3 format with the SD library.
"tempsensor.txt" is 10.3

Pete

It worked. The values are now being successfully written to the file, no problems. For that format, all I really had to do was shorten the filename. Thank you for your help.

for the life of me i cannot get the ds1620 library/example to compile. i have tried installing it in a bunch of different places, no luck. it tells me HIGH is not defined and LOW is not defined, i try including like every other library i have, still no luck. i think it is because i am using 1.0 of the compiler and these were for <1 of the compiler because they are .pde this is the first code problem ive had that i havent been able to figure out, and searching all over and i cant figure out what i need to do. can anyone help?

i have tried installing it in a bunch of different places, no luck.

Only one place, the libraries folder in the folder where you store your sketches, is correct. No luck needed.

it tells me HIGH is not defined and LOW is not defined

That has nothing to do with where the library is installed.

i think it is because i am using 1.0 of the compiler and these were for <1 of the compiler

Yes, it is, and there have been thousands of posts explaining how to upgrade a pre-1.0 library for post 1.0 use. I don't intend to make this another one.