Go Down

Topic: Unable to create a file on SD card using arduino UNO. (Read 743 times) previous topic - next topic

Vai777

I want to merge two different codes that is inserted below. When I merge them, the value obtained by analog input shows up on the serial monitor but does not get stored onto a file in the SD card. It would be great if you guys could help me out.

1) Code to create a new file on SD card

Code: [Select]

#include<SD.h>
#include<SPI.h>
File myFile;
int pinCS = 4;
void setup()
{
Serial.begin(19200);
pinMode(pinCS, OUTPUT);

if(SD.begin())
{
Serial.println("The SD card is ready");
}
else
{
Serial.println("The card initialization failed");
return;
}
}

void loop()
{
int sensorValue = analogRead(A0);
Serial.println(sensorValue);

myFile = SD.open("example.txt", FILE_WRITE);
delay(100);
if(myFile)
{
myFile.println(sensorValue);
myFile.close();
}
else
{
Serial.println("Error opening example.txt");
}
}



2) Code I want to merge with the above one.

Code: [Select]


//this code will enable all three Arduino timer interrupts.
//timer will interrupt at 1Hz

void setup()
{
Serial.begin(19200);
Serial.flush();

cli();

TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 61;
TCCR1B |= (1 << WGM12);
TCCR1B |= (1 << CS12) | (1 << CS10);
TIMSK1 |= (1 << OCIE1A);

sei();

}

ISR(TIMER1_COMPA_vect)

{
Serial.println(analogRead(A0));
}

void loop
{

}

Go Up