首页 > 其他分享 >arduino操作SD

arduino操作SD

时间:2022-10-17 23:38:05浏览次数:54  
标签:pin arduino volumesize println 操作 Serial card SD


以下是arduino ide中SD模块示例:

  • 采用3.3v电压

[codesyntax lang="cpp" lines="normal"]


/* SD card test This example shows how use the utility libraries on which the' SD library is based in order to get info about your SD card. Very useful for testing a card when you're not sure whether its working or not. The circuit: * SD card attached to SPI bus as follows: ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila ** CS - depends on your SD card shield or module. Pin 4 used here for consistency with other Arduino examples created 28 Mar 2011 by Limor Fried modified 9 Apr 2012 by Tom Igoe */ // include the SD library: #include <SD.h> // set up variables using the SD utility library functions: Sd2Card card; SdVolume volume; SdFile root; // change this to match your SD shield or module; // Arduino Ethernet shield: pin 4 // Adafruit SD shields and modules: pin 10 // Sparkfun SD shield: pin 8 const int chipSelect = 4; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } Serial.print("\nInitializing SD card..."); // On the Ethernet Shield, CS is pin 4. It's set as an output by default. // Note that even if it's not used as the CS pin, the hardware SS pin // (10 on most Arduino boards, 53 on the Mega) must be left as an output // or the SD library functions will not work. pinMode(10, OUTPUT); // change this to 53 on a mega // we'll use the initialization code from the utility libraries // since we're just testing if the card is working! if (!card.init(SPI_HALF_SPEED, chipSelect)) { Serial.println("initialization failed. Things to check:"); Serial.println("* is a card is inserted?"); Serial.println("* Is your wiring correct?"); Serial.println("* did you change the chipSelect pin to match your shield or module?"); return; } else { Serial.println("Wiring is correct and a card is present."); } // print the type of card Serial.print("\nCard 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("Unknown"); } // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32 if (!volume.init(card)) { Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"); return; } // print the type and size of the first FAT-type volume uint32_t volumesize; Serial.print("\nVolume 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); // // // list all files in the card with date and size // root.ls(LS_R | LS_DATE | LS_SIZE); } void loop(void) { }


[/codesyntax]

标签:pin,arduino,volumesize,println,操作,Serial,card,SD
From: https://blog.51cto.com/suren/5764664

相关文章

  • arduino中断
    [codesyntaxlang="cpp"lines="normal"]#defineLED13#definePIN2#defineTEST3volatileintstate=LOW;voidsetup(){Serial.begin(9600);pinMode......
  • 【LeetCode】1486. 数组异或操作(C++)
    1486.数组异或操作(C++)​​1题目描述​​​​2示例描述​​​​2.1示例1​​​​2.2示例2​​​​2.3示例3​​​​2.4示例4​​​​3解题提示​​​​4源码详......
  • 用声网 Android UIKit 为实时视频通话应用添加自定义背景丨声网 SDK 教程
     使用声网SDK和UIKit创建视频推流应用非常简单,而且声网还有许多功能,可以提高视频通话的质量和便利性。例如,我们可以在视频通话过程中使用虚拟背景,为视频通话增添趣......
  • SDN小测2
    1.下列哪项属于控制器的基本功能层?() 协议适配解析:协议适配的作用是根据网络实际情况,选用合适的协议优化网络;云服务属于应用服务层;交换机管理和主机管理属于网络基础......
  • SDN网络编排与服务
    网络编排是指在业务需求的驱动下,对各种逻辑网络服务单元进行有序的安排和组织,通过控制器最终形成能够满足业务需求的网络服务。网络编排通过抽象实现业务和逻辑网络、逻辑网......
  • Selenium4Web自动化4-鼠标键盘模拟操作
    一、Web元素交互参考官方文档:https://www.selenium.dev/zh-cn/documentation/webdriver/elements/interactions/用于操纵表单的高级指令集.仅有五种基本命令可用于元......
  • 记一次代码合并操作.
    当前的项目开发中,使用的版本管理工具为GIT,这个工具也是很多公司在使用的工具。在以前接触过的项目中,经常使用的开发方式是使用一个主干进行开发,或者是使用一个分支进......
  • arduino操作PN532
    介绍参考​​http://www.arduino.cn/thread-5960-1-1.html​​​......
  • Python 遍历指定文件夹下所有文件批量操作的方法
    Python中进行程序开发时,有些文件操作的需求可能需要我们对文件夹下的所有文件进行批量操作。本文主要介绍一下Python中对指定文件夹下所有文件进行批量操作的方法。原文地......
  • 【LeetCode】1758. 生成交替二进制字符串的最少操作数(C++)
    1758.生成交替二进制字符串的最少操作数(C++)​​1题目描述​​​​2示例描述​​​​2.1示例1​​​​2.2示例2​​​​2.3示例3​​​​3解题提示​​​​4解题思路......