Welcome to EnviroDIY, a community for do-it-yourself environmental science and monitoring. EnviroDIY is part of WikiWatershed, a web toolkit designed to help citizens, conservation practitioners, municipal decision-makers, researchers, educators, and students advance knowledge and stewardship of fresh water. New to EnviroDIY? Start here

SD Data Recording

Home Forums Other Data Loggers SD Data Recording

Viewing 5 reply threads
  • Author
    Posts
    • #13303
      Gera
      Participant

      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.

    • #13315
      Sara Damiano
      Moderator

      I think

      should be

      You also should have a

      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?

    • #13335
      Gera
      Participant

      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.

    • #13336
      Sara Damiano
      Moderator

      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:

      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

    • #13337
      Gera
      Participant

      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.

    • #13339
      Sara Damiano
      Moderator

      I’d completely forgotten about the filename issue, too. It’s definitely a “gotcha” that’s hard to catch.

Viewing 5 reply threads
  • You must be logged in to reply to this topic.