Home › Forums › Other Data Loggers › SD Data Recording › Reply To: SD Data Recording
2019-11-14 at 1:14 PM
#13336
In asking about “your other thread” I meant this: https://www.envirodiy.org/topic/sd-card-recording-data-issue/
You need to make the modifications I mentioned above. You also need to pi
In asking about “your other thread” I meant this: https://www.envirodiy.org/topic/sd-card-recording-data-issue/
You need to make the modifications I mentioned above. You also need to pick a file name that is less than 8 characters, ie, “cond.txt” instead of conductivity.txt. I’d forgotten about the filename issue.
Your new code would be:
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#include <Arduino.h> #include <math.h> #include <Wire.h> #include <SD.h> #include <SPI.h> //Digital pin 12 is the MicroSD slave select pin on the Mayfly #define SD_SS_PIN 12 //The data log file #define FILE_NAME "Conductivity.txt" //Data header (these lines get written to the beginning of a file when it’s created) #define LOGGERNAME "Mayfly microSD Card Tester" #define DATA_HEADER "Conductivity.txt" int pin12 = 12; File Conductivity1; int volta; float Division; void setup() { Serial.begin(9600); pinMode(SD_SS_PIN,OUTPUT); pinMode(22,OUTPUT); digitalWrite(22,HIGH); Division = 0.0048875; if (SD.begin(SD_SS_PIN)) { Serial.println("SD card on"); } else { Serial.println("SD card activation failed"); } } void loop() { volta = analogRead(A3); float voltage = (volta)*(Division); Conductivity1 = SD.open("Conducti.txt",FILE_WRITE); // NOTE: REMOVE "File" and choose a file name that is 8 characters or less Serial.println("Conductivity = "); Serial.println(voltage); Conductivity1.println(LOGGERNAME); Conductivity1.println("Conductivity = "); Conductivity1.println(voltage); Conductivity1.close(); // NOTE: Must close file or data will not be saved delay (1000); } |
I still recommend you use SdFat instead of SD, which would allow you to use longer filenames and to set the file timestamps. Look at the example for that library: https://github.com/greiman/SdFat/blob/master/examples/ReadWrite/ReadWrite.ino