Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

10 лет назад
8 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. SD card test
  3. This example shows how use the utility libraries on which the'
  4. SD library is based in order to get info about your SD card.
  5. Very useful for testing a card when you're not sure whether its working or not.
  6. The circuit:
  7. * SD card attached to SPI bus as follows:
  8. ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila, pin 7 on Teensy with audio board
  9. ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
  10. ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila, pin 14 on Teensy with audio board
  11. ** CS - depends on your SD card shield or module - pin 10 on Teensy with audio board
  12. Pin 4 used here for consistency with other Arduino examples
  13. created 28 Mar 2011
  14. by Limor Fried
  15. modified 9 Apr 2012
  16. by Tom Igoe
  17. */
  18. // include the SD library:
  19. #include <SD.h>
  20. #include <SPI.h>
  21. // set up variables using the SD utility library functions:
  22. Sd2Card card;
  23. SdVolume volume;
  24. SdFile root;
  25. // change this to match your SD shield or module;
  26. // Arduino Ethernet shield: pin 4
  27. // Adafruit SD shields and modules: pin 10
  28. // Sparkfun SD shield: pin 8
  29. // Teensy audio board: pin 10
  30. // Teensy 3.5 & 3.6 on-board: BUILTIN_SDCARD
  31. // Wiz820+SD board: pin 4
  32. // Teensy 2.0: pin 0
  33. // Teensy++ 2.0: pin 20
  34. const int chipSelect = 4;
  35. void setup()
  36. {
  37. //UNCOMMENT THESE TWO LINES FOR TEENSY AUDIO BOARD:
  38. //SPI.setMOSI(7); // Audio shield has MOSI on pin 7
  39. //SPI.setSCK(14); // Audio shield has SCK on pin 14
  40. // Open serial communications and wait for port to open:
  41. Serial.begin(9600);
  42. while (!Serial) {
  43. ; // wait for serial port to connect. Needed for Leonardo only
  44. }
  45. Serial.print("\nInitializing SD card...");
  46. // we'll use the initialization code from the utility libraries
  47. // since we're just testing if the card is working!
  48. if (!card.init(SPI_HALF_SPEED, chipSelect)) {
  49. Serial.println("initialization failed. Things to check:");
  50. Serial.println("* is a card inserted?");
  51. Serial.println("* is your wiring correct?");
  52. Serial.println("* did you change the chipSelect pin to match your shield or module?");
  53. return;
  54. } else {
  55. Serial.println("Wiring is correct and a card is present.");
  56. }
  57. // print the type of card
  58. Serial.print("\nCard type: ");
  59. switch(card.type()) {
  60. case SD_CARD_TYPE_SD1:
  61. Serial.println("SD1");
  62. break;
  63. case SD_CARD_TYPE_SD2:
  64. Serial.println("SD2");
  65. break;
  66. case SD_CARD_TYPE_SDHC:
  67. Serial.println("SDHC");
  68. break;
  69. default:
  70. Serial.println("Unknown");
  71. }
  72. // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  73. if (!volume.init(card)) {
  74. Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
  75. return;
  76. }
  77. // print the type and size of the first FAT-type volume
  78. uint32_t volumesize;
  79. Serial.print("\nVolume type is FAT");
  80. Serial.println(volume.fatType(), DEC);
  81. Serial.println();
  82. volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
  83. volumesize *= volume.clusterCount(); // we'll have a lot of clusters
  84. if (volumesize < 8388608ul) {
  85. Serial.print("Volume size (bytes): ");
  86. Serial.println(volumesize * 512); // SD card blocks are always 512 bytes
  87. }
  88. Serial.print("Volume size (Kbytes): ");
  89. volumesize /= 2;
  90. Serial.println(volumesize);
  91. Serial.print("Volume size (Mbytes): ");
  92. volumesize /= 1024;
  93. Serial.println(volumesize);
  94. Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  95. root.openRoot(volume);
  96. // list all files in the card with date and size
  97. root.ls(LS_R | LS_DATE | LS_SIZE);
  98. }
  99. void loop(void) {
  100. }