SDCARD ISSUEEEE

Although the SD card is in fat32 format, the arduino mega 2560 does not save data and detects it as unformatted

You are aware that the SPI interface on the Mega is not on pins 11 / 12 / 13?

You don't indicate which library you're using; we should not have asked if you had posted your code (properly formatted and using code tags; see How to get the best out of this forum).

What is the size of the SD card? Make and model?

It's advised to format SD cards using the specific tool for it (SD Memory Card Formatter | SD Association).; did you?

The pins I inserted are correct. SDCARD is 32 gb and I downloaded it from the link you gave and formatted it. Brand of sd card toshiba 30MB/s microsd hc.

My code is like this

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <virtuabotixRTC.h>
#include <SPI.h>
#include <SD.h>

virtuabotixRTC myRTC(6,7,8);
LiquidCrystal_I2C lcd(0x27, 16, 2);

File myFile;
#define battery A1


int min_value = 246;
float percent= 0;
float value = 0;

int voltage = 0;

void setup()
{
  lcd.begin();
  
  lcd.backlight();
  
  lcd.setCursor(0,0);
  lcd.print("BATTERY METER");
  Serial.begin(9600);
  
  // myRTC.setDS1302Time(00,14,11,0,04,12,2022);
  
 
  Serial.println("Initializing SD card...");

  pinMode(53, OUTPUT);

  if(!SD.begin())
  {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  myFile = SD.open("test.txt", FILE_WRITE);
  if(myFile)
  {
    Serial.println("Writing to test.txt...");
    myFile.println(value);
    
    myFile.close();
    Serial.println("Done.");
  }
  else
  {
    Serial.println("error opening test.txt");
  }
  myFile = SD.open("test.txt");
  if(myFile)
  {
    Serial.println("test.txt:");
    while(myFile.available())
    {
      Serial.write(myFile.read());
    }
    myFile.close();
  }
  else
  {
    Serial.println("error opening test.txt");
  }

}

void loop()
{
  voltage = analogRead(battery);

  if(voltage >= 338)
  {
    voltage = 338; 
  }
  
  if(voltage <= 246)
  {
    voltage = 246;
  }

   percent = voltage - min_value;
   value = (100.00/92.00) * percent;

   lcd.setCursor(0,1);
   lcd.print("fullness: %");
   lcd.print(value);
   delay(500);

   myRTC.updateTime();
   Serial.print(myRTC.dayofmonth);
   Serial.print("/");
   Serial.print(myRTC.month);
   Serial.print("/");
   Serial.print(myRTC.year);
   Serial.print("  ");
   Serial.print(myRTC.hours);
   Serial.print(":");
   Serial.print(myRTC.minutes);
   Serial.print(":");
   Serial.println(myRTC.seconds);
   delay(1000);
  
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.