Not sure what's going on. Looked at tutorials and am failing to see the cause. I've checked wiring, formatted the SD card to FAT32. The serial monitors shows a successful initialization and that the data from the clock and analog sensor are fine. Pull the SD card and I show no files on it when inserted into my pc. Sketch below...Thanks in advance.
//Written by Shane Helsel Last update 041319
//Analog air pressure data logger with time stamp. Used to collect differential air pressure
//data for trouble shooting and process improvement in conveying material via air in a pipe.
//Modify delay function to alert sampling rate (time based).
//Pin Layout
//Air Pressure Sensor Pin 1 (Analog out) to A0, Pin 2 to Ground, Pin 3 to 5V
//DS3231 Module SDA to SDA, SCL to SCL, VCC to 5v, Ground to Ground
//SD Card Module Gnd to Gnd, VCC to 5v, CS to pin 10, SCK to pin 11, Mosi to pin 12, Miso to pin 13
#include <DS3231.h>
#include <SD.h>
#include <SPI.h>
File myFile;
int pinCS = 10;
DS3231 rtc(SDA, SCL); // Init the DS3231 using the hardware interface
int sensorValue = analogRead(A0);
void setup() {
Serial.begin(9600); // Setup Serial connection
pinMode(pinCS, OUTPUT);
rtc.begin(); // Initialize the rtc object
if (SD.begin ()) //Initialize SD Card
{
Serial.println("SD card is ready to use");
}else
{
Serial.println ("SD card initialization failed");
return;
}
}
void loop() {
int sensorValue = analogRead(A0);
//Write data to serial monitor for testing add // to turn off
Serial.print("sensorValue"); //write sensor value to serial monitor
Serial.print(", "); //column separator
Serial.print(rtc.getDateStr()); //write date to serial monitor
Serial.print(", "); //column separator
Serial.println(rtc.getTimeStr()); //write time to serial monitor
//Save data to SD Card
myFile = SD.open("Air Pressure.txt", FILE_WRITE);
if (myFile) {
myFile.print(rtc.getDateStr()); //save date
myFile.print(","); //column separator
myFile.print(rtc.getTimeStr()); //save time
myFile.print(","); //column separator
myFile.println(sensorValue); //save sensor value
myFile.close(); //close file
}
delay (3000); // Wait three seconds before repeating
}