2017-10-14 9 views
0

저는 Arduino Breakout Board와 함께 Intel Edison을 사용하고 있습니다. SD 카드에 파일을 저장하고 Arduino IDE에서 간단한 ReadWrite 예제를 실행합니다. 모든 것이 완벽하게 작동하며 출력이 있습니다.SD 카드에 파일을 저장하면 오류가 발생합니다.

SD 카드 초기화 중 ... 초기화가 완료되었습니다. test.txt ...에 글을 쓰고 있습니다. test.txt : testing 1, 2, 3.

하지만 SD 카드를 PC에 꽂으면 파일이 없거나 비어 있습니다. 내가

umount /media/sdcard 

을 마운트 해제하려면이 명령을 사용하고이 문제를 저장

#include <SPI.h> 
#include <SD.h> 

File myFile; 

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..."); 
    // On the Ethernet Shield, CS is pin 4. It's set as an output by default. 
    // Note that even if it's not used as the CS pin, the hardware SS pin 
    // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
    // or the SD library functions will not work. 
    pinMode(10, OUTPUT); 

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

    // open the file. note that only one file can be open at a time, 
    // so you have to close this one before opening another. 
    myFile = SD.open("test.txt", FILE_WRITE); 

    // if the file opened okay, write to it: 
    if (myFile) { 
    Serial.print("Writing to test.txt..."); 
    myFile.println("testing 1, 2, 3."); 
    // close the file: 
    myFile.close(); 
    Serial.println("done."); 
    } else { 
    // if the file didn't open, print an error: 
    Serial.println("error opening test.txt"); 
    } 

    // re-open the file for reading: 
    myFile = SD.open("test.txt"); 
    if (myFile) { 
    Serial.println("test.txt:"); 

    // read from the file until there's nothing else in it: 
    while (myFile.available()) { 
     Serial.write(myFile.read()); 
    } 
    // close the file: 
    myFile.close(); 
    } else { 
    // if the file didn't open, print an error: 
    Serial.println("error opening test.txt"); 
    } 
} 

void loop() 
{ 
    // nothing happens after setup 
} 
+0

1. 파일 객체에 * .flush() * 메소드가 있습니까? 그렇다면 * .close() * 전에 호출하십시오. 2. 두 번째 오프닝 (그리고 물론 관련 라인)을 주석 처리한다면 도움이 될까요? – 0andriy

답변