“SKU:RB-02S018A TF卡讀寫模塊”的版本間的差異
(→?產(chǎn)品相關(guān)推薦) |
(→?例子程序) |
||
第37行: | 第37行: | ||
===例子程序=== | ===例子程序=== | ||
<pre style='color:blue'> | <pre style='color:blue'> | ||
? | #include < | + | #include <SD.h> |
? | #include < | + | #include <SPI.h> |
+ | File myFile; | ||
+ | void setup() | ||
+ | { | ||
+ | Serial.begin(9600); | ||
+ | while (!Serial) {; | ||
+ | } | ||
+ | Serial.print("Initializing SD card..."); | ||
+ | pinMode(10, OUTPUT); | ||
+ | if (!SD.begin(4)) { | ||
+ | Serial.println("initialization failed!"); | ||
+ | return; | ||
+ | } | ||
+ | Serial.println("initialization done."); | ||
+ | myFile = SD.open("test.txt", FILE_WRITE); | ||
+ | if (myFile) { | ||
+ | Serial.print("Writing to test.txt..."); | ||
+ | myFile.println("testing 1, 2, 3."); | ||
+ | myFile.close(); | ||
+ | Serial.println("done."); | ||
+ | } | ||
+ | else { | ||
+ | Serial.println("error opening test.txt"); | ||
+ | } | ||
+ | myFile = SD.open("test.txt"); | ||
+ | if (myFile) { | ||
+ | Serial.println("test.txt:"); | ||
+ | while (myFile.available()) { | ||
+ | Serial.write(myFile.read()); | ||
+ | } | ||
+ | myFile.close(); | ||
+ | } | ||
+ | else { | ||
+ | Serial.println("error opening test.txt"); | ||
+ | } | ||
+ | } | ||
? | + | void loop(){ | |
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | void | + | |
? | { | + | |
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
} | } | ||
+ | </pre> | ||
? | |||
? | |||
? | |||
? | |||
? | |||
===程序效果=== | ===程序效果=== | ||
程序編譯上傳無誤之后,將準備好的 TF 卡插入到模塊中,連接 TF 卡模塊和 Arduino UNO 控制器,連接正常情況下,會顯示出卡的信息,如下圖所示: | 程序編譯上傳無誤之后,將準備好的 TF 卡插入到模塊中,連接 TF 卡模塊和 Arduino UNO 控制器,連接正常情況下,會顯示出卡的信息,如下圖所示: |
2018年9月13日 (四) 17:21的版本
目錄 |
產(chǎn)品概述
該模塊(MicroSD Card Adapter)是Micro SD卡讀寫模塊,通過文件系統(tǒng)及SPI接口驅(qū)動程序,單片機系統(tǒng)即可完成MicroSD卡內(nèi)的文件進行讀寫。Arduino用戶可直接使用Arduino IDE自帶的SD卡程序庫即可完成卡的初始化和讀寫。
模塊特點如下:
- 支持Micro SD卡、Micro SDHC卡(高速卡)
- 板載電平轉(zhuǎn)換電路,即接口電平可為5V或3.3V
- 供電電源為4.5V - 5.5V,板載3.3V穩(wěn)壓電路
- 通信接口為標(biāo)準SPI接口
- 4個M2螺絲定位孔,便于安裝
規(guī)格參數(shù)
- 工作電壓:3.3V - 5V
- 產(chǎn)品尺寸:40mm * 28mm
- 重量大小:3g
- 信號類型:模擬信號
- 固定孔:M3 * 4個
- 通信接口:標(biāo)準 SPI 接口
- 支持卡類型:Micro SD 卡(< = 2G),Micro SDHC 卡(< = 32G)
- 電源指示燈:紅色
- 數(shù)據(jù)傳輸指示燈:藍色
接口定義
- + :電源正
- - :電源地
- DI :串行數(shù)據(jù)輸入
- DO :串行數(shù)據(jù)輸出
- CK :串行時鐘
- CS :片選信號,由控制器進行控制
使用方法
工作原理
TF 卡模塊使用 SPI 總線連接方式實現(xiàn)與 Arduino 控制器的通信,穩(wěn)壓芯片輸出的 3.3V 為電平轉(zhuǎn)換芯片、Micro SD 卡進行供電,電平轉(zhuǎn)換電路往 Micro SD 卡方向的信號轉(zhuǎn)換成 3.3V,Micro SD 卡往控制接口方向的 MISO 信號也轉(zhuǎn)換成了 3.3V,一般 AVR 單片機系統(tǒng)都可以讀取該信號,產(chǎn)品使用自彈式卡座,方便卡的插拔。
注意:Arduino 的 sd.h 庫文件目前對 2G 及其以下的支持比較好,對 2G 以上的支持不好,所以在使用時,建議選用 2G 或以下的內(nèi)存卡。
編程原理
TF 卡模塊共引出 6 個引腳,其中 DO、CK、DI 是 SPI 總線接口,“+”為電源正,“-”為電源 GND,CS 為片選端,實際使用時依照下面的接線圖連接即可,使用 Arduino IDE 自帶的例子程序就可以進行測試。
連接示意圖
例子程序
#include <SD.h> #include <SPI.h> File myFile; void setup() { Serial.begin(9600); while (!Serial) {; } Serial.print("Initializing SD card..."); pinMode(10, OUTPUT); if (!SD.begin(4)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); myFile = SD.open("test.txt", FILE_WRITE); if (myFile) { Serial.print("Writing to test.txt..."); myFile.println("testing 1, 2, 3."); myFile.close(); Serial.println("done."); } else { Serial.println("error opening test.txt"); } myFile = SD.open("test.txt"); if (myFile) { Serial.println("test.txt:"); while (myFile.available()) { Serial.write(myFile.read()); } myFile.close(); } else { Serial.println("error opening test.txt"); } } void loop(){ }
程序效果
程序編譯上傳無誤之后,將準備好的 TF 卡插入到模塊中,連接 TF 卡模塊和 Arduino UNO 控制器,連接正常情況下,會顯示出卡的信息,如下圖所示:
產(chǎn)品相關(guān)推薦
例子程序下載
下載鏈接:http://pan.baidu.com/s/1mikbyg4 密碼:m59a
產(chǎn)品購買地址
Arduino TF卡讀寫存儲模塊:http://gharee.com/goods-782.html