ขอคนที่มาความรู้เรื่อง sd card module มาช่วยหน่อยคับ

กระทู้คำถาม
ผมใช้บอร์ด Arduino Mega + SD Card Module แล้วปัญหามันอยู่ว่าหลังจากที่ผมเคลื่อนย้ายอุปกรณ์ผ่านรถมอเตอร์ไซด์กลับบ้าน จากนั้นลองต่อสายและรันอีกที ในตอนแรกยังสามารถรันได้ปกติ แต่พอเวลาผ่านไปช่วงเวลาหนึ่ง ผลปรากฏว่า SD Card Module ไม่สามารถเขียนข้อความลงไปได้ ผมลองFormat ด้วย FAT32 ดูแล้ว 1 รอบก้ยังเป็นเหมือนเดิม คือไม่สามารถเขียนข้อความลงไปได้ ผมก็ลองเช็คว่าSD Card Module พร้อมที่จะทำงานรึป่าว ผลปรากฏว่า Initializing SD card...DONE แค่รอบเดียว หลังจากนั้นก็ Fail !!!
        ใครเคยเจอปัญหาหรืออาการแบบนี้ขอวิธีแก้ด้วยคับ
ปล.หวังว่าบอร์ด SD Card  ของผมยังไม่เสียนะ TT^TT
และนี้คือโปรแกรมคับ


#include <SD.h>

// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 53;

void setup()
{
// Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(53, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
}

void loop()
{
  // make a string for assembling the data to log:
  String dataString = "555";
  
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }  
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  }
}
แสดงความคิดเห็น
โปรดศึกษาและยอมรับนโยบายข้อมูลส่วนบุคคลก่อนเริ่มใช้งาน อ่านเพิ่มเติมได้ที่นี่