“SKU:RB-02S018A TF卡读写模块”的版本间的差异

来自ALSROBOT WiKi
跳转至: 导航搜索
产品相关推荐
产品相关推荐
 
(未显示1个用户的12个中间版本)
第19行: 第19行:
 
# 数据传输指示灯:蓝色
 
# 数据传输指示灯:蓝色
  
==接口定义==
+
10.接口定义<br/>
 
* + :电源正
 
* + :电源正
 
* - :电源地
 
* - :电源地
第27行: 第27行:
 
* CS :片选信号,由控制器进行控制
 
* CS :片选信号,由控制器进行控制
 
[[文件:02S018A02.png|500px|有框|居中]]
 
[[文件:02S018A02.png|500px|有框|居中]]
==使用方法==
+
 
===工作原理===
+
==工作原理==
 
TF 卡模块使用 SPI 总线连接方式实现与 Arduino 控制器的通信,稳压芯片输出的 3.3V 为电平转换芯片、Micro SD 卡进行供电,电平转换电路往 Micro SD 卡方向的信号转换成 3.3V,Micro SD 卡往控制接口方向的 MISO 信号也转换成了 3.3V,一般 AVR 单片机系统都可以读取该信号,产品使用自弹式卡座,方便卡的插拔。<br/>
 
TF 卡模块使用 SPI 总线连接方式实现与 Arduino 控制器的通信,稳压芯片输出的 3.3V 为电平转换芯片、Micro SD 卡进行供电,电平转换电路往 Micro SD 卡方向的信号转换成 3.3V,Micro SD 卡往控制接口方向的 MISO 信号也转换成了 3.3V,一般 AVR 单片机系统都可以读取该信号,产品使用自弹式卡座,方便卡的插拔。<br/>
 
注意:Arduino 的 sd.h 库文件目前对 2G 及其以下的支持比较好,对 2G 以上的支持不好,所以在使用时,建议选用 2G 或以下的内存卡。
 
注意:Arduino 的 sd.h 库文件目前对 2G 及其以下的支持比较好,对 2G 以上的支持不好,所以在使用时,建议选用 2G 或以下的内存卡。
===编程原理===
+
==编程原理==
 
TF 卡模块共引出 6 个引脚,其中 DO、CK、DI 是 SPI 总线接口,“+”为电源正,“-”为电源 GND,CS 为片选端,实际使用时依照下面的接线图连接即可,使用 Arduino IDE 自带的例子程序就可以进行测试。
 
TF 卡模块共引出 6 个引脚,其中 DO、CK、DI 是 SPI 总线接口,“+”为电源正,“-”为电源 GND,CS 为片选端,实际使用时依照下面的接线图连接即可,使用 Arduino IDE 自带的例子程序就可以进行测试。
===连接示意图===
+
 
[[文件:02S018A03.png|700px|有框|居中]]
+
==使用方法==
===例子程序===
+
===example1_Arduino===
 +
* 主要硬件
 +
:Arduino UNO 控制器
 +
:传感器扩展板 V5.0
 +
:TF卡读写模块
 +
:单头防插反 3P 传感器连接线
 +
:USB 数据线
 +
 
 +
* 硬件连接
 +
[[文件:02S018A_1.png|660px|缩略图|居中]]
 +
 
 +
* 例子程序
 
<pre style='color:blue'>
 
<pre style='color:blue'>
 +
/*
 +
* TF 卡模块与 Arduino UNO的接线
 +
DI -- D11
 +
CS -- D4
 +
CK -- D13
 +
DO -- D12
 +
*/
 
#include <SPI.h>
 
#include <SPI.h>
 
#include <SD.h>
 
#include <SD.h>
第46行: 第64行:
 
const int chipSelect = 4;
 
const int chipSelect = 4;
  
void setup()
+
void setup() {
{
+
 
   Serial.begin(9600);
 
   Serial.begin(9600);
 
   while (!Serial) {
 
   while (!Serial) {
     ; // wait for serial port to connect. Needed for Leonardo only
+
     ;  
 
   }
 
   }
 
 
   Serial.print("\nInitializing SD card...");
 
   Serial.print("\nInitializing SD card...");
 +
  if (!SD.begin(4)) {
 +
    Serial.println("initialization failed");
 +
    return;
 +
  }
 +
    Serial.println("Wiring is correct and a card is present.");
  
 
   if (!card.init(SPI_HALF_SPEED, chipSelect)) {
 
   if (!card.init(SPI_HALF_SPEED, chipSelect)) {
     Serial.println("initialization failed. Things to check:");
+
     Serial.println("initialization failed. Check: SD Card");
    Serial.println("* is a card inserted?");
+
    Serial.println("* is your wiring correct?");
+
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
+
 
     return;
 
     return;
 
   } else {
 
   } else {
     Serial.println("Wiring is correct and a card is present.");
+
     Serial.println("============= Card Information ==================");
 
   }
 
   }
 
+
Serial.print("Card type: ");
  Serial.print("\nCard type: ");
+
 
   switch (card.type()) {
 
   switch (card.type()) {
 
     case SD_CARD_TYPE_SD1:
 
     case SD_CARD_TYPE_SD1:
第77行: 第94行:
 
       break;
 
       break;
 
     default:
 
     default:
       Serial.println("Unknown");
+
       Serial.println("Unknow");
 
   }
 
   }
 
+
    if (!volume.init(card)) {
  if (!volume.init(card)) {
+
     Serial.println("Could not find FAT16/FAT32 partition.");
     Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
+
 
     return;
 
     return;
 
   }
 
   }
 
+
  // 顯示類型和 FAT 空間大小
 
+
 
   uint32_t volumesize;
 
   uint32_t volumesize;
   Serial.print("\nVolume type is FAT");
+
   Serial.print("Volume type is FAT");
 
   Serial.println(volume.fatType(), DEC);
 
   Serial.println(volume.fatType(), DEC);
 
   Serial.println();
 
   Serial.println();
第102行: 第117行:
 
   volumesize /= 1024;
 
   volumesize /= 1024;
 
   Serial.println(volumesize);
 
   Serial.println(volumesize);
 
  
 
   Serial.println("\nFiles found on the card (name, date and size in bytes): ");
 
   Serial.println("\nFiles found on the card (name, date and size in bytes): ");
第108行: 第122行:
  
 
   root.ls(LS_R | LS_DATE | LS_SIZE);
 
   root.ls(LS_R | LS_DATE | LS_SIZE);
 +
 +
  Serial.println("================= Finished =====================");
 
}
 
}
  
第115行: 第131行:
 
}
 
}
 
</pre>
 
</pre>
===程序效果===
+
 
 +
* 程序效果
 
程序编译上传无误之后,将准备好的 TF 卡插入到模块中,连接 TF 卡模块和 Arduino UNO 控制器,连接正常情况下,会显示出卡的信息,如下图所示:
 
程序编译上传无误之后,将准备好的 TF 卡插入到模块中,连接 TF 卡模块和 Arduino UNO 控制器,连接正常情况下,会显示出卡的信息,如下图所示:
[[文件:02S018A100.png|526px|缩略图|居中]]
+
[[文件:02S018A_2.png|530px|缩略图|居中]]
 +
 
 +
===example2_Arduino===
 +
* 主要硬件
 +
:Arduino UNO 控制器
 +
:传感器扩展板 V5.0
 +
:TF卡读写模块
 +
:单头防插反 3P 传感器连接线
 +
:USB 数据线
 +
 
 +
* 硬件连接
 +
[[文件:02S018A_1.png|660px|缩略图|居中]]
 +
 
 +
* 例子程序
 +
<pre style='color:blue'>
 +
/*
 +
* TF 卡模块与 Arduino UNO的接线
 +
DI -- D11
 +
CS -- D4
 +
CK -- D13
 +
DO -- D12
 +
*/
 +
 
 +
#include <SPI.h>
 +
#include <SD.h>
 +
 
 +
File myFile;
 +
 
 +
//设置功能变量
 +
Sd2Card card;
 +
SdVolume volume;
 +
SdFile root;
 +
 
 +
const int chipSelect = 4;
 +
 
 +
void setup() {
 +
 
 +
  Serial.begin(9600); 
 +
  while (!Serial) {   
 +
  }
 +
 
 +
  //----------- 写入文档
 +
  Serial.print("\nWaiting for SD card ready...");
 +
 
 +
  if (!SD.begin(4)) {
 +
    Serial.println("Fail!");
 +
    return;
 +
  }
 +
  Serial.println("Success!");
 +
 
 +
  myFile = SD.open("card.txt", FILE_WRITE);      // 开启文档,一次只能开启一个文档
 +
 
 +
  if (myFile) {                                  // 如果文档正常
 +
    Serial.print("Write to card.txt...");       
 +
    myFile.println("Test to write data to SD card...");  // 继续写在文档的后面
 +
    myFile.close();                              // 关闭文档
 +
    Serial.println("Completed!");
 +
  } else {
 +
    Serial.println("\n open file error ");    // 无法打开文档时,打印“open file error”
 +
  }
 +
 
 +
  //----------- 显示SD卡信息
 +
 
 +
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
 +
    Serial.println("initialization failed. Check: SD Card");
 +
    return;
 +
  } else {
 +
    Serial.println("============= Card Information ==================");
 +
  }
 +
 
 +
  // 显示 SD 卡类型
 +
 
 +
  Serial.print("Card type: ");
 +
  switch (card.type()) {
 +
    case SD_CARD_TYPE_SD1:
 +
      Serial.println("SD1");
 +
      break;
 +
    case SD_CARD_TYPE_SD2:
 +
      Serial.println("SD2");
 +
      break;
 +
    case SD_CARD_TYPE_SDHC:
 +
      Serial.println("SDHC");
 +
      break;
 +
    default:
 +
      Serial.println("Unknow");
 +
  }
 +
 
 +
  if (!volume.init(card)) {
 +
    Serial.println("Could not find FAT16/FAT32 partition.");
 +
    return;
 +
  }
 +
 
 +
  // 显示类型和FAT空间的大小
 +
  uint32_t volumesize;
 +
  Serial.print("Volume type is FAT");
 +
  Serial.println(volume.fatType(), DEC);
 +
  Serial.println();
 +
 
 +
  volumesize = volume.blocksPerCluster();   
 +
  volumesize *= volume.clusterCount();     
 +
  volumesize *= 512;                           
 +
  Serial.print("Volume size (bytes): ");
 +
  Serial.println(volumesize);
 +
  Serial.print("Volume size (Kbytes): ");
 +
  volumesize /= 1024;
 +
  Serial.println(volumesize);
 +
  Serial.print("Volume size (Mbytes): ");
 +
  volumesize /= 1024;
 +
  Serial.println(volumesize);
 +
 
 +
  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
 +
  root.openRoot(volume);
 +
 
 +
  // 列出卡内所有文件及 SD 卡的尺寸
 +
  root.ls(LS_R | LS_DATE | LS_SIZE);
 +
 
 +
  Serial.println("================= Finished =====================");
 +
}
 +
 
 +
void loop() {     
 +
}
 +
</pre>
 +
 
 +
* 程序效果
 +
程序编译上传无误之后,将准备好的 TF 卡插入到模块中,连接 TF 卡模块和 Arduino UNO 控制器,连接正常情况下,会显示出卡的信息,如下图所示:
 +
[[文件:02S018A_3.png|530px|缩略图|居中]]
  
 
==产品相关推荐==
 
==产品相关推荐==
 
[[文件:erweima.png|230px|无框|右]]
 
[[文件:erweima.png|230px|无框|右]]
===例子程序下载===
+
===资料下载===
下载链接:http://pan.baidu.com/s/1mikbyg4 密码:m59a
+
网盘链接: https://pan.baidu.com/s/1CiwpDShiB_Seityve6HVEQ
 +
提取码:i4dp
 +
 
 
===产品购买地址===
 
===产品购买地址===
 
Arduino TF卡读写存储模块:http://www.alsrobot.cn/goods-782.html
 
Arduino TF卡读写存储模块:http://www.alsrobot.cn/goods-782.html
 
===相关学习资料===
 
===相关学习资料===
 
[http://www.makerspace.cn/portal.php 奥松机器人技术论坛]<br/>
 
[http://www.makerspace.cn/portal.php 奥松机器人技术论坛]<br/>

2021年7月21日 (三) 11:39的最后版本

02S018A001.png

目录

产品概述

该模块(MicroSD Card Adapter)是Micro SD卡读写模块,通过文件系统及SPI接口驱动程序,单片机系统即可完成MicroSD卡内的文件进行读写。Arduino用户可直接使用Arduino IDE自带的SD卡程序库即可完成卡的初始化和读写。
模块特点如下:

  • 支持Micro SD卡、Micro SDHC卡(高速卡)
  • 板载电平转换电路,即接口电平可为5V或3.3V
  • 供电电源为4.5V - 5.5V,板载3.3V稳压电路
  • 通信接口为标准SPI接口
  • 4个M2螺丝定位孔,便于安装

规格参数

  1. 工作电压:3.3V - 5V
  2. 产品尺寸:40mm * 28mm
  3. 重量大小:3g
  4. 信号类型:模拟信号
  5. 固定孔:M3 * 4个
  6. 通信接口:标准 SPI 接口
  7. 支持卡类型:Micro SD 卡(< = 2G),Micro SDHC 卡(< = 32G)
  8. 电源指示灯:红色
  9. 数据传输指示灯:蓝色

10.接口定义

  • + :电源正
  • - :电源地
  • DI :串行数据输入
  • DO :串行数据输出
  • CK :串行时钟
  • CS :片选信号,由控制器进行控制
02S018A02.png

工作原理

TF 卡模块使用 SPI 总线连接方式实现与 Arduino 控制器的通信,稳压芯片输出的 3.3V 为电平转换芯片、Micro SD 卡进行供电,电平转换电路往 Micro SD 卡方向的信号转换成 3.3V,Micro SD 卡往控制接口方向的 MISO 信号也转换成了 3.3V,一般 AVR 单片机系统都可以读取该信号,产品使用自弹式卡座,方便卡的插拔。
注意:Arduino 的 sd.h 库文件目前对 2G 及其以下的支持比较好,对 2G 以上的支持不好,所以在使用时,建议选用 2G 或以下的内存卡。

编程原理

TF 卡模块共引出 6 个引脚,其中 DO、CK、DI 是 SPI 总线接口,“+”为电源正,“-”为电源 GND,CS 为片选端,实际使用时依照下面的接线图连接即可,使用 Arduino IDE 自带的例子程序就可以进行测试。

使用方法

example1_Arduino

  • 主要硬件
Arduino UNO 控制器
传感器扩展板 V5.0
TF卡读写模块
单头防插反 3P 传感器连接线
USB 数据线
  • 硬件连接
02S018A 1.png
  • 例子程序
/*
 * TF 卡模块与 Arduino UNO的接线
DI -- D11
CS -- D4
CK -- D13
DO -- D12
 */
#include <SPI.h>
#include <SD.h>

Sd2Card card;
SdVolume volume;
SdFile root;

const int chipSelect = 4;

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; 
  }
  Serial.print("\nInitializing SD card...");
  if (!SD.begin(4)) {
    Serial.println("initialization failed");
    return;
  } 
    Serial.println("Wiring is correct and a card is present.");

  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Check: SD Card");
    return;
  } else {
    Serial.println("============= Card Information ==================");
  }
 Serial.print("Card type: ");
  switch (card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknow");
  }
    if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.");
    return;
  }
  // 顯示類型和 FAT 空間大小
  uint32_t volumesize;
  Serial.print("Volume type is FAT");
  Serial.println(volume.fatType(), DEC);
  Serial.println();

  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize *= 512;                            // SD card blocks are always 512 bytes
  Serial.print("Volume size (bytes): ");
  Serial.println(volumesize);
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);

  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);

  root.ls(LS_R | LS_DATE | LS_SIZE);

  Serial.println("================= Finished =====================");
}


void loop(void) {

}
  • 程序效果

程序编译上传无误之后,将准备好的 TF 卡插入到模块中,连接 TF 卡模块和 Arduino UNO 控制器,连接正常情况下,会显示出卡的信息,如下图所示:

02S018A 2.png

example2_Arduino

  • 主要硬件
Arduino UNO 控制器
传感器扩展板 V5.0
TF卡读写模块
单头防插反 3P 传感器连接线
USB 数据线
  • 硬件连接
02S018A 1.png
  • 例子程序
/*
 * TF 卡模块与 Arduino UNO的接线
DI -- D11
CS -- D4
CK -- D13
DO -- D12
 */

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

File myFile;

//设置功能变量
Sd2Card card;
SdVolume volume;
SdFile root;

const int chipSelect = 4;

void setup() {

  Serial.begin(9600);  
  while (!Serial) {    
  }

  //----------- 写入文档
  Serial.print("\nWaiting for SD card ready...");

  if (!SD.begin(4)) {
    Serial.println("Fail!");
    return;
  }
  Serial.println("Success!");

  myFile = SD.open("card.txt", FILE_WRITE);       // 开启文档,一次只能开启一个文档
  
  if (myFile) {                                   // 如果文档正常
    Serial.print("Write to card.txt...");         
    myFile.println("Test to write data to SD card...");  // 继续写在文档的后面
    myFile.close();                               // 关闭文档
    Serial.println("Completed!");
  } else {
    Serial.println("\n open file error ");    // 无法打开文档时,打印“open file error”
  }
  
   //----------- 显示SD卡信息

  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Check: SD Card");
    return;
  } else {
    Serial.println("============= Card Information ==================");
  }

  // 显示 SD 卡类型

  Serial.print("Card type: ");
  switch (card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknow");
  }

  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.");
    return;
  }

  // 显示类型和FAT空间的大小
  uint32_t volumesize;
  Serial.print("Volume type is FAT");
  Serial.println(volume.fatType(), DEC);
  Serial.println();

  volumesize = volume.blocksPerCluster();    
  volumesize *= volume.clusterCount();       
  volumesize *= 512;                            
  Serial.print("Volume size (bytes): ");
  Serial.println(volumesize);
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);

  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);

  // 列出卡内所有文件及 SD 卡的尺寸
  root.ls(LS_R | LS_DATE | LS_SIZE);

  Serial.println("================= Finished =====================");
}

void loop() {      
}
  • 程序效果

程序编译上传无误之后,将准备好的 TF 卡插入到模块中,连接 TF 卡模块和 Arduino UNO 控制器,连接正常情况下,会显示出卡的信息,如下图所示:

02S018A 3.png

产品相关推荐

Erweima.png

资料下载

网盘链接: https://pan.baidu.com/s/1CiwpDShiB_Seityve6HVEQ 提取码:i4dp

产品购买地址

Arduino TF卡读写存储模块:http://www.alsrobot.cn/goods-782.html

相关学习资料

奥松机器人技术论坛