적절한 Arduino Uno R4 보드(예: Arduino Uno R4 WiFi)와 COM 포트를 선택합니다.
Arduino IDE에서 시리얼 모니터를 엽니다.
제공된 코드를 복사하여 Arduino IDE에 붙여넣습니다.
/* * 이 아두이노 우노 R4 코드는 newbiely.kr 에서 개발되었습니다 * 이 아두이노 우노 R4 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino-uno-r4/arduino-uno-r4-micro-sd-card */#include <SD.h>#define PIN_SPI_CS 4 // The Arduino UNO R4 pin connected to the CS pin of SDcard moduleFile myFile;voidsetup() {Serial.begin(9600);if (!SD.begin(PIN_SPI_CS)) {Serial.println(F("SD Card is either missing or has failed!"));while (1); // don't do anything more: }Serial.println(F("SD Card is ready"));if (!SD.exists("arduino.txt")) {Serial.println(F("arduino.txt doesn't exist. Creating arduino.txt file..."));// create a new file by opening a new file and immediately close it myFile = SD.open("arduino.txt", FILE_WRITE); myFile.close(); }// recheck if file is created or notif (SD.exists("arduino.txt"))Serial.println(F("arduino.txt exists on SD Card."));elseSerial.println(F("arduino.txt doesn't exist on SD Card."));}voidloop() {}
Arduino IDE에서 Upload 버튼을 눌러 코드를 Arduino UNO R4에 전송하세요.
첫 번째 업로드 후 결과를 확인하려면 시리얼 모니터를 확인하세요.
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
SD Card is ready
arduino.txt doesn't exist. Creating arduino.txt file...
arduino.txt exists on SD Card.
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2
다음 시도에 대한 결과는 시리얼 모니터에 표시됩니다.
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
SD Card is ready
arduino.txt exists on SD Card.
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2
※ 주의:
처음 업로드한 후 시리얼 모니터를 열면 출력을 보지 못할 수도 있습니다.
모듈에서 마이크로 SD 카드를 제거하십시오.
마이크로 SD 카드를 USB SD 카드 리더기에 넣으십시오.
USB SD 카드 리더기를 컴퓨터에 연결하십시오.
파일이 있는지 여부를 확인하십시오.
아두이노 UNO R4 - 마이크로 SD 카드에서 파일에 데이터를 쓰고/읽는 방법
이 코드는 다음 작업을 수행합니다:
정보를 파일에 저장
파일의 각 문자를 하나씩 시리얼 모니터에 로드하고 표시
/* * 이 아두이노 우노 R4 코드는 newbiely.kr 에서 개발되었습니다 * 이 아두이노 우노 R4 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino-uno-r4/arduino-uno-r4-micro-sd-card */#include <SD.h>#define PIN_SPI_CS 4 // The Arduino UNO R4 pin connected to the CS pin of SDcard moduleFile myFile;voidsetup() {Serial.begin(9600);if (!SD.begin(PIN_SPI_CS)) {Serial.println(F("SD Card is either missing or has failed!"));while (1); // don't do anything more: }Serial.println(F("SD Card is ready"));// open file for writing myFile = SD.open("arduino.txt", FILE_WRITE);if (myFile) { myFile.println("Created by newbiely.com"); // write a line to Arduino myFile.println("Learn Arduino and SD Card"); // write another line to Arduino myFile.close(); } else {Serial.print(F("Error: Unable to open file arduino.txt")); }// open file for reading myFile = SD.open("arduino.txt", FILE_READ);if (myFile) {while (myFile.available()) {char ch = myFile.read(); // read characters one by one from Micro SD CardSerial.print(ch); // print the character to Serial Monitor } myFile.close(); } else {Serial.print(F("Error: Unable to open file arduino.txt")); }}voidloop() {}
시리얼 모니터에 파일의 내용이 표시되었습니다.
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
Created by newbiely.com
Learn Arduino UNO R4 and SD Card
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2
※ 주의:
기본적으로 데이터는 파일의 끝에 추가됩니다. 주어진 코드를 사용하여 Arduino UNO R4를 다시 시작하면 텍스트가 다시 파일에 추가됩니다. 이는 시리얼 모니터에 다음과 같은 추가 줄이 표시됨을 의미합니다:
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
Created by newbiely.com
Learn Arduino UNO R4 and SD Card
Created by newbiely.com
Learn Arduino UNO R4 and SD Card
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2
모듈에서 Micro SD 카드를 제거하고 USB SD 카드 리더기를 사용하여 컴퓨터에서 파일을 볼 수도 있습니다.
Arduino UNO R4 - Micro SD 카드에서 파일을 한 줄씩 읽는 방법
/* * 이 아두이노 우노 R4 코드는 newbiely.kr 에서 개발되었습니다 * 이 아두이노 우노 R4 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino-uno-r4/arduino-uno-r4-micro-sd-card */#include <SD.h>#define PIN_SPI_CS 4 // The Arduino UNO R4 pin connected to the CS pin of SDcard moduleFile myFile;voidsetup() {Serial.begin(9600);if (!SD.begin(PIN_SPI_CS)) {Serial.println(F("SD Card is either missing or has failed!"));while (1); // don't do anything more: }Serial.println(F("SD Card is ready"));// open file for writing myFile = SD.open("arduino.txt", FILE_WRITE);if (myFile) { myFile.println("Created by newbiely.com"); // write a line to Arduino myFile.println("Learn Arduino and SD Card"); // write another line to Arduino myFile.close(); } else {Serial.print(F("Error: Unable to open file arduino.txt")); }// open file for reading myFile = SD.open("arduino.txt", FILE_READ);if (myFile) {int line_count = 0;while (myFile.available()) {char line[100]; // maximum is 100 characters, change it if neededint line_length = myFile.readBytesUntil('\n', line, 100); // read line-by-line from Micro SD Card line_count++;Serial.print(F("Line "));Serial.print(line_count);Serial.print(F(": "));Serial.write(line, line_length); // print the character to Serial Monitor// \n character is escaped by readBytesUntil functionSerial.write('\n'); // print a new line charactor } myFile.close(); } else {Serial.print(F("Error: Unable to open file arduino.txt")); }}voidloop() {}
직렬 모니터에 표시된 결과
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
SD Card is ready
Line 1: Created by newbiely.com
Line 2: Learn Arduino UNO R4 and SD Card
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2
※ 주의:
파일 내용을 미리 삭제하지 않으면, 시리얼 모니터에 추가 줄이 표시될 수 있습니다.
Arduino UNO R4 - Micro SD 카드에서 파일을 덮어쓰는 방법
보통 내용은 파일의 끝에 추가됩니다. 파일을 교체하려면 먼저 오래된 파일을 삭제한 후 동일한 이름으로 새 파일을 만드십시오.
/* * 이 아두이노 우노 R4 코드는 newbiely.kr 에서 개발되었습니다 * 이 아두이노 우노 R4 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino-uno-r4/arduino-uno-r4-micro-sd-card */#include <SD.h>#define PIN_SPI_CS 4 // The Arduino UNO R4 pin connected to the CS pin of SDcard moduleFile myFile;voidsetup() {Serial.begin(9600);if (!SD.begin(PIN_SPI_CS)) {Serial.println(F("SD Card is either missing or has failed!"));while (1); // don't do anything more: }Serial.println(F("SD Card is ready"));SD.remove("arduino.txt"); // delete the file if existed// create new file by opening file for writing myFile = SD.open("arduino.txt", FILE_WRITE);if (myFile) { myFile.println("Created by newbiely.com"); // write a line to Arduino myFile.println("Learn Arduino and SD Card"); // write another line to Arduino myFile.close(); } else {Serial.print(F("Error: Unable to open file arduino.txt")); }// open file for reading myFile = SD.open("arduino.txt", FILE_READ);if (myFile) {while (myFile.available()) {char ch = myFile.read(); // read characters one by one from Micro SD CardSerial.print(ch); // print the character to Serial Monitor } myFile.close(); } else {Serial.print(F("Error: Unable to open file arduino.txt")); }}voidloop() {}
시리얼 모니터의 출력
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
SD Card is ready
Created by newbiely.com
Learn Arduino UNO R4 and SD Card
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2
Arduino UNO R4 재시작
Serial Monitor의 파일 내용이 추가되었는지 확인하십시오.
또한 장치에서 Micro SD 카드를 제거하여 USB SD 카드 리더를 사용하여 컴퓨터에서 내용을 볼 수 있습니다.
동영상
비디오 제작은 시간이 많이 걸리는 작업입니다. 비디오 튜토리얼이 학습에 도움이 되었다면, YouTube 채널 을 구독하여 알려 주시기 바랍니다. 비디오에 대한 높은 수요가 있다면, 비디오를 만들기 위해 노력하겠습니다.