โมดูลบันทึกข้อมูล Micro SD Card Module
โมดูลสำหรับบันทึกข้อมูลลง Micro SD Card , Micro SD Card Module ยี่ห้อ Catalex สำหรับเพิ่มความ
สามารถในการบันทึกข้อมูลต่าง ๆ จากบอร์ด Arduino ลงบน Micro SD Card มีอินเตอร์เฟสแบบ SPI ใช้
งานง่าย มีไลบารีสำเร็จรูปให้พร้อมใช้งาน มีวงจรเรกูเลต 3.3V มาให้ในตัวบอร์ด สามารถใช้ไฟได้ในช่วง
4.5V - 5.5V
Product Description
The module (MicroSD Card Adapter) is a Micro SD card reader module, through the file system
and the SPI interface driver, MCU to complete the file system to read and write MicroSD card.
Users can directly use IDE comes with an SD card to complete the library card initialization and
read-write
Module features are as follows:
1. Supports Micro SD cards, Micro SDHC card (high speed card)
2 level conversion circuit board that interfaces level for 5V or 3.3V
3 power supply is 4.5V ~ 5.5V, 3.3V voltage regulator circuit board
4 is a standard communication interface SPI interface
5.4 M2 screw positioning holes for easy installation
วิธีการต่ออุปกรณ์ สอนใช้งาน Arduino บันทึกข้อมูลลง SD Card
Arduino uno r3 -> โมดูลบันทึกข้อมูล SD Card Module
- 5V -> Vcc
- GND -> GND
- ขา4 -> CS
- ขา11 -> MOSI
- ขา12 -> MISO
- ขา13 -> SCK
โหลด library SD Card Module
วิธีลง Library ให้ดูตัวอย่างในบทความนี้
เปิด SD card ขึ้นมา แล้ว สร้างไฟล์ test.txt ขึ้นมา เพื่อให้ Arduino เขียนข้อมูล และ อ่านข้อมูล

ให้ต่ออุปกรณ์ตามรูปข้างบน แล้ว อัพโหลด โค้ดตัวอย่างด้านล่างลง Arduino uno r3
4
File myFile; // สร้างออฟเจก File สำหรับจัดการข้อมูล
5
const int chipSelect = 4;
11
; // รอจนกระทั่งเชื่อมต่อกับ Serial port แล้ว สำหรับ Arduino Leonardo เท่านั้น
15
Serial.print("Initializing SD card...");
18
if (!SD.begin(chipSelect)) {
19
Serial.println("initialization failed!");
22
Serial.println("initialization done.");
24
myFile = SD.open("test.txt", FILE_WRITE); // เปิดไฟล์ที่ชื่อ test.txt เพื่อเขียนข้อมูล โหมด FILE_WRITE
26
// ถ้าเปิดไฟล์สำเร็จ ให้เขียนข้อมูลเพิ่มลงไป
28
Serial.print("Writing to test.txt...");
29
myFile.println("12345"); // สั่งให้เขียนข้อมูล
30
myFile.println("www.myarduino.net");
31
myFile.close(); // ปิดไฟล์
32
Serial.println("done.");
34
// ถ้าเปิดไฟลืไม่สำเร็จ ให้แสดง error
35
Serial.println("error opening test.txt");
39
myFile = SD.open("test.txt"); // สั่งให้เปิดไฟล์ชื่อ test.txt เพื่ออ่านข้อมูล
41
Serial.println("test.txt:");
42
// อ่านข้อมูลทั้งหมดออกมา
43
while (myFile.available()) {
44
Serial.write(myFile.read());
46
myFile.close(); // เมื่ออ่านเสร็จ ปิดไฟล์
48
// ถ้าอ่านไม่สำเร็จ ให้แสดง error
49
Serial.println("error opening test.txt");

