Sản phẩm đã được thêm vào giỏ hàng!.

Lập trình Arduino giao tiếp thẻ nhớ SD card.

Hôm nay dientuagv giới thiệu đến các bạn 6 bước giao tiếp dữ liệu từ thẻ nhớ thông qua board arduino.

Bước 1: Phần cứng bao gồm

  1. Arduino Uno
  2. USB Cable type A to B
  3. Micro Sd Card Module
  4. Female to male jumper wire
  5. SD Card

Bước 2: Kết nối phần cứng

Connect VCC with 5V in the Arduino.
Then, connect the GND of SD card to the ground of Arduino.
Connect CS to pin 14
Connect SCK to pin 13
MOSI connect to the pin 11
Lastly, connect MISO to pin 12

Bước 3: Mở chương trình mẫu từ thu viện ( tải thư viện tại đây)

Code mẫu:

#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 native USB port only
}
Serial.print(“Initializing SD card…”);

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(“r2.txt”);
if (myFile) {
Serial.println(“r2.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
}

Bước 4: Chọn cổng Com

Bước 5: Upload Souce Code

Bước 6: Kêt quả

Sản phẩm đã được thêm vào giỏ hàng!.