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
}