PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

85 lines
2.0KB

  1. /*
  2. SD card file dump
  3. This example shows how to read a file from the SD card using the
  4. SD library and send it over the serial port.
  5. The circuit:
  6. * SD card attached to SPI bus as follows:
  7. ** MOSI - pin 11, pin 7 on Teensy with audio board
  8. ** MISO - pin 12
  9. ** CLK - pin 13, pin 14 on Teensy with audio board
  10. ** CS - pin 4, pin 10 on Teensy with audio board
  11. created 22 December 2010
  12. by Limor Fried
  13. modified 9 Apr 2012
  14. by Tom Igoe
  15. This example code is in the public domain.
  16. */
  17. #include <SD.h>
  18. #include <SPI.h>
  19. // On the Ethernet Shield, CS is pin 4. Note that even if it's not
  20. // used as the CS pin, the hardware CS pin (10 on most Arduino boards,
  21. // 53 on the Mega) must be left as an output or the SD library
  22. // functions will not work.
  23. // change this to match your SD shield or module;
  24. // Arduino Ethernet shield: pin 4
  25. // Adafruit SD shields and modules: pin 10
  26. // Sparkfun SD shield: pin 8
  27. // Teensy audio board: pin 10
  28. // Teensy 3.5 & 3.6 & 4.1 on-board: BUILTIN_SDCARD
  29. // Wiz820+SD board: pin 4
  30. // Teensy 2.0: pin 0
  31. // Teensy++ 2.0: pin 20
  32. const int chipSelect = 4;
  33. void setup()
  34. {
  35. //UNCOMMENT THESE TWO LINES FOR TEENSY AUDIO BOARD:
  36. //SPI.setMOSI(7); // Audio shield has MOSI on pin 7
  37. //SPI.setSCK(14); // Audio shield has SCK on pin 14
  38. // Open serial communications and wait for port to open:
  39. Serial.begin(9600);
  40. while (!Serial) {
  41. ; // wait for serial port to connect.
  42. }
  43. Serial.print("Initializing SD card...");
  44. // see if the card is present and can be initialized:
  45. if (!SD.begin(chipSelect)) {
  46. Serial.println("Card failed, or not present");
  47. // don't do anything more:
  48. return;
  49. }
  50. Serial.println("card initialized.");
  51. // open the file.
  52. File dataFile = SD.open("datalog.txt");
  53. // if the file is available, write to it:
  54. if (dataFile) {
  55. while (dataFile.available()) {
  56. Serial.write(dataFile.read());
  57. }
  58. dataFile.close();
  59. }
  60. // if the file isn't open, pop up an error:
  61. else {
  62. Serial.println("error opening datalog.txt");
  63. }
  64. }
  65. void loop()
  66. {
  67. }