Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. SdFat version: 20160719
  2.  
  3. Assuming the SD is the only SPI device.
  4. Edit DISABLE_CHIP_SELECT to disable another device.
  5.  
  6. Assuming the SD chip select pin is: 10
  7. Edit SD_CHIP_SELECT to change the SD chip select pin.
  8.  
  9. type any character to start
  10.  
  11. init time: 748 ms
  12.  
  13. Card type: SDHC
  14.  
  15. Manufacturer ID: 0X28
  16. OEM ID: BE
  17. Product: 68BHO
  18. Version: 0.8
  19. Serial number: 0XD50B3A66
  20. Manufacturing date: 11/2010
  21.  
  22. cardSize: 32026.66 MB (MB = 1,000,000 bytes)
  23. flashEraseSize: 128 blocks
  24. eraseSingleBlock: true
  25. OCR: 0XC0FF8000
  26.  
  27. SD Partition Table
  28. part,boot,type,start,length
  29. 1,0X0,0XC,8192,62543872
  30. 2,0X0,0X0,0,0
  31. 3,0X0,0X0,0,0
  32. 4,0X0,0X0,0,0
  33.  
  34. Volume is FAT32
  35. blocksPerCluster: 64
  36. clusterCount: 976992
  37. freeClusters: 976905
  38. freeSpace: 32011.22 MB (MB = 1,000,000 bytes)
  39. fatStartBlock: 9310
  40. fatCount: 2
  41. blocksPerFat: 7633
  42. rootDirStart: 2
  43. dataStartBlock: 24576
  44.  
  45. type any character to start
  46.  
  47. cardBegin failed
  48. SD errorCode: 0XA
  49. SD errorData: 0X5
  50.  
  51. #include <FreeStack.h>
  52. #include <MinimumSerial.h>
  53. #include <SdFat.h>
  54. #include <SdFatConfig.h>
  55. #include <SdFatUtil.h>
  56. #include <SystemInclude.h>
  57.  
  58. #include <Wire.h>
  59. #include <Adafruit_BMP085.h>
  60.  
  61. const uint8_t chipSelect = SS;
  62.  
  63. SdFat sd;
  64. SdFile file;
  65.  
  66. Adafruit_BMP085 bmp;
  67. float startingAltitude;
  68.  
  69. void setup() {
  70.  
  71. Serial.begin(9600);
  72.  
  73. if (!bmp.begin()) {
  74. Serial.println("Could not find a valid BMP085 sensor, check wiring!");
  75. }
  76.  
  77. float totalAltitude = 0;
  78. for(int x = 0; x < 10; x++){
  79. totalAltitude += bmp.readAltitude(102505.98);
  80. }
  81. startingAltitude = totalAltitude / 10;
  82.  
  83. Serial.println("*****DEBUG MESSAGES*****");
  84. // Alt
  85. Serial.print("Starting relative altitude: ");
  86. Serial.println(startingAltitude);
  87. // Temp
  88. Serial.print("Temperature = ");
  89. Serial.print(bmp.readTemperature());
  90. Serial.println(" *C");
  91. // Pressure
  92. Serial.print("Pressure at sealevel (calculated) = ");
  93. Serial.print(bmp.readSealevelPressure());
  94. Serial.println(" Pa");
  95. Serial.println("************************");
  96.  
  97. // SD init
  98. char fileName[10] = "data.csv";
  99. delay(1000);
  100. while (!Serial) {
  101. SysCall::yield();
  102. }
  103.  
  104. // Initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  105. // breadboards. use SPI_FULL_SPEED for better performance.
  106. if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
  107. sd.initErrorHalt();
  108. }
  109.  
  110. // Open file
  111. if (!file.open(fileName, O_CREAT | O_WRITE | O_EXCL)) {
  112. Serial.println("Error opening file!");
  113. }
  114.  
  115.  
  116.  
  117. }
  118.  
  119. void loop() {
  120.  
  121. Serial.print("Real altitude = ");
  122. Serial.print(bmp.readAltitude(102505.98));
  123. Serial.println(" meters");
  124.  
  125. float relAltitude = bmp.readAltitude(102505.98) - startingAltitude;
  126.  
  127. Serial.print("Relative altitude = ");
  128. Serial.print(relAltitude);
  129. Serial.println(" meters");
  130.  
  131. // Write into the SD card
  132.  
  133. file.print(relAltitude);
  134. file.close();
  135.  
  136. Serial.println();
  137. delay(100);
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement