Home › Forums › Other Data Loggers › SD Data Recording
- This topic has 5 replies, 2 voices, and was last updated 2019-11-14 at 2:17 PM by Sara Damiano.
-
AuthorPosts
-
-
2019-11-04 at 5:14 PM #13303
Hi all,
I am trying to log data from a conductivity sensor to the SD card, for some reason it is not working. here is my code (I try to use code snippet but I could not make it look like how it suppose to be, I will try again when I am not too busy):
#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);
File Conductivity1 = SD.open(“Conductivity.txt”,FILE_WRITE);
Serial.println(“Conductivity = “);
Serial.println(voltage);
Conductivity1.println(LOGGERNAME);
Conductivity1.println(“Conductivity = “);
Conductivity1.println(voltage);
delay (1000);Please may everybody tell me what I am doing wrong, i would appreciate.
-
2019-11-08 at 6:03 PM #13315
I think
C++1File Conductivity1 = SD.open(“Conductivity.txt”,FILE_WRITE);should be
C++1Conductivity1 = SD.open(“Conductivity.txt”,FILE_WRITE);You also should have a
C++1Conductivity1.close()before the last delay.
Are you using a Mayfly? Are you using the built-in microSD card slot or the vertical adapter? What output do you get?
Did you ever get your program in your earlier thread to write to the SD card?
-
2019-11-14 at 9:56 AM #13335
Yes, I am using Mayfly. I am using the built-in microSD card slot. My output I get the values in the serial monitor but nothings gets written into the SD card. The last question is kind of confusing to me, but what I am thinking is that you are asking me if I ever put the code of the SD card somewhere else in this code then yeah, but I still get nothing written into the card.
-
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 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++123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051#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 lessSerial.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 saveddelay (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
-
2019-11-14 at 1:56 PM #13337
Oh… Well I decided to leave that thread for later because I wanted to focus on getting something recorded on the SD card. I see now the mistakes I did. I would change to SdFat if it makes things better, I was trying to get something to work first. The code is now working for me. Thank you very much! The Filename issue was the only thing that I did not knew.
-
2019-11-14 at 2:17 PM #13339
I’d completely forgotten about the filename issue, too. It’s definitely a “gotcha” that’s hard to catch.
-
-
AuthorPosts
- You must be logged in to reply to this topic.