Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. /*
  2. SD card test
  3.  
  4. This example shows how use the utility libraries on which the'
  5. SD library is based in order to get info about your SD card.
  6. Very useful for testing a card when you're not sure whether its working or not.
  7.  
  8. The circuit:
  9. SD card attached to SPI bus as follows:
  10. ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
  11. ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
  12. ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
  13. ** CS - depends on your SD card shield or module.
  14. Pin 4 used here for consistency with other Arduino examples
  15.  
  16.  
  17. created 28 Mar 2011
  18. by Limor Fried
  19. modified 9 Apr 2012
  20. by Tom Igoe
  21. */
  22. // include the SD library:
  23. #include <SPI.h>
  24. #include <SD.h>
  25. #include <SPI.h>
  26. #include <nRF24L01.h>
  27. #include <RF24.h>
  28. RF24 radio(31, 30); // CE, CSN
  29. const byte address[6] = "00001";
  30.  
  31. // set up variables using the SD utility library functions:
  32. Sd2Card card;
  33. SdVolume volume;
  34. SdFile root;
  35.  
  36. // change this to match your SD shield or module;
  37. // Arduino Ethernet shield: pin 4
  38. // Adafruit SD shields and modules: pin 10
  39. // Sparkfun SD shield: pin 8
  40. // MKRZero SD: SDCARD_SS_PIN
  41. const int chipSelect = 39;
  42.  
  43. void setup() {
  44. digitalWrite(30, HIGH); // NRF
  45. digitalWrite(31, HIGH); // NRF
  46. digitalWrite(39, HIGH); // SD card
  47. // Open serial communications and wait for port to open:
  48. radio.begin();
  49. radio.openWritingPipe(address);
  50. radio.setPALevel(RF24_PA_MIN);
  51. radio.stopListening();
  52.  
  53. delay(1000);
  54.  
  55.  
  56. Serial.begin(9600);
  57. while (!Serial) {
  58. ; // wait for serial port to connect. Needed for native USB port only
  59. }
  60.  
  61.  
  62. Serial.print("\nInitializing SD card...");
  63.  
  64. // we'll use the initialization code from the utility libraries
  65. // since we're just testing if the card is working!
  66. if (!card.init(SPI_HALF_SPEED, chipSelect)) {
  67. Serial.println("initialization failed. Things to check:");
  68. Serial.println("* is a card inserted?");
  69. Serial.println("* is your wiring correct?");
  70. Serial.println("* did you change the chipSelect pin to match your shield or module?");
  71. while (1);
  72. } else {
  73. Serial.println("Wiring is correct and a card is present.");
  74. }
  75.  
  76. // print the type of card
  77. Serial.println();
  78. Serial.print("Card type: ");
  79. switch (card.type()) {
  80. case SD_CARD_TYPE_SD1:
  81. Serial.println("SD1");
  82. break;
  83. case SD_CARD_TYPE_SD2:
  84. Serial.println("SD2");
  85. break;
  86. case SD_CARD_TYPE_SDHC:
  87. Serial.println("SDHC");
  88. break;
  89. default:
  90. Serial.println("Unknown");
  91. }
  92.  
  93. // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  94. if (!volume.init(card)) {
  95. Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
  96. while (1);
  97. }
  98.  
  99. Serial.print("Clusters: ");
  100. Serial.println(volume.clusterCount());
  101. Serial.print("Blocks x Cluster: ");
  102. Serial.println(volume.blocksPerCluster());
  103.  
  104. Serial.print("Total Blocks: ");
  105. Serial.println(volume.blocksPerCluster() * volume.clusterCount());
  106. Serial.println();
  107.  
  108. // print the type and size of the first FAT-type volume
  109. uint32_t volumesize;
  110. Serial.print("Volume type is: FAT");
  111. Serial.println(volume.fatType(), DEC);
  112.  
  113. volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
  114. volumesize *= volume.clusterCount(); // we'll have a lot of clusters
  115. volumesize /= 2; // SD card blocks are always 512 bytes (2 blocks are 1KB)
  116. Serial.print("Volume size (Kb): ");
  117. Serial.println(volumesize);
  118. Serial.print("Volume size (Mb): ");
  119. volumesize /= 1024;
  120. Serial.println(volumesize);
  121. Serial.print("Volume size (Gb): ");
  122. Serial.println((float)volumesize / 1024.0);
  123.  
  124. Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  125. root.openRoot(volume);
  126.  
  127. // list all files in the card with date and size
  128. root.ls(LS_R | LS_DATE | LS_SIZE);
  129. }
  130.  
  131. void loop(void) {
  132.  
  133. const char text[] = "Hello World";
  134. Serial.println("asd");
  135. radio.write(&text, sizeof(text));
  136. Serial.println("asd2");
  137. delay(1000);
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement