Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 11 of 11

Thread: Teensy 3.6 SD card

  1. #1
    Junior Member
    Join Date
    Jan 2020
    Posts
    4

    Teensy 3.6 SD card

    Hello everyone
    Iím working on a Teensy 3.6 card in my project, and Iím using for that some sensors connected to the card by the I2C interface, so i want to save the data coming from the sensors to the SD card, and the problem is that i donít know how to do it i even donít know on which pins the SD card is connected so thatís the problem
    And thank you for replying

  2. #2
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,488
    Look at the example:
    • Examples -> SD -> ReadWrite


    You will need to change the chipSelect constant to 'BUILTIN_SDCARD' to use the built-in SD card in the Teensy 3.5 or 3.6.

    The cards should be formatted with the VFAT/FAT32 file system, which in turn implies using a card that is 32GB or smaller.

    I don't see an entry in the PJRC.COM library for the SD library, but there is the documentation from the Arduino library that Teensy uses:


    There is also a SdFat library.

  3. #3
    Junior Member
    Join Date
    Jan 2020
    Posts
    4
    Thank you for your reply
    So i tried it But it shows me every time i compile that the variable name is not known (BUILTIN_SDCARD)

  4. #4
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,230
    So, the example code does not work?

  5. #5
    Junior Member
    Join Date
    Jan 2020
    Posts
    4
    It doesnít recognize the variable name BUILTIN_SDCARD
    So it doesnít work

  6. #6
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,488
    Quote Originally Posted by sidiali View Post
    Thank you for your reply
    So i tried it But it shows me every time i compile that the variable name is not known (BUILTIN_SDCARD)
    That is a typical message if you select the wrong board (i.e. Tools -> Board -> Teensy 3.6). BUILTIN_SDCARD is only defined for the Teensy 3.5, 3.6, and 4.0 platforms. It could also be if you have an old SD directory in your Arduino directory.

    I just tried this example, modifying the chipSelect line on my Teensy 3.5 and it worked fine. It also compiled fine for Teensy 3.6. I tried it with TeensyDunuio 1.47, 1.48, and 1.49-beta4.

    Code:
    /*
      SD card read/write
     
     This example shows how to read and write data to and from an SD card file 	
     The circuit:
     * SD card attached to SPI bus as follows:
     ** MOSI - pin 11, pin 7 on Teensy with audio board
     ** MISO - pin 12
     ** CLK - pin 13, pin 14 on Teensy with audio board
     ** CS - pin 4, pin 10 on Teensy with audio board
     
     created   Nov 2010
     by David A. Mellis
     modified 9 Apr 2012
     by Tom Igoe
     
     This example code is in the public domain.
     	 
     */
     
    #include <SD.h>
    #include <SPI.h>
    
    File myFile;
    
    // 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
    // Teensy audio board: pin 10
    // Teensy 3.5 & 3.6 on-board: BUILTIN_SDCARD
    // Wiz820+SD board: pin 4
    // Teensy 2.0: pin 0
    // Teensy++ 2.0: pin 20
    const int chipSelect = BUILTIN_SDCARD;
    
    void setup()
    {
     //UNCOMMENT THESE TWO LINES FOR TEENSY AUDIO BOARD:
     //SPI.setMOSI(7);  // Audio shield has MOSI on pin 7
     //SPI.setSCK(14);  // Audio shield has SCK on pin 14
      
     // 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("Initializing SD card...");
    
      if (!SD.begin(chipSelect)) {
        Serial.println("initialization failed!");
        return;
      }
      Serial.println("initialization done.");
      
      // open the file. note that only one file can be open at a time,
      // so you have to close this one before opening another.
      myFile = SD.open("test.txt", FILE_WRITE);
      
      // if the file opened okay, write to it:
      if (myFile) {
        Serial.print("Writing to test.txt...");
        myFile.println("testing 1, 2, 3.");
    	// close the file:
        myFile.close();
        Serial.println("done.");
      } else {
        // if the file didn't open, print an error:
        Serial.println("error opening test.txt");
      }
      
      // re-open the file for reading:
      myFile = SD.open("test.txt");
      if (myFile) {
        Serial.println("test.txt:");
        
        // read from the file until there's nothing else in it:
        while (myFile.available()) {
        	Serial.write(myFile.read());
        }
        // close the file:
        myFile.close();
      } else {
      	// if the file didn't open, print an error:
        Serial.println("error opening test.txt");
      }
    }
    
    void loop()
    {
    	// nothing happens after setup
    }

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,354
    Quote Originally Posted by sidiali View Post
    So i tried it But it shows me every time i compile that the variable name is not known (BUILTIN_SDCARD)
    Maybe Arduino is using the wrong SD library.

    To check, click File > Preferences and turn on verbose output while compiling.

    The click Verify again, and scroll up to look for messages about which SD library Arduino is actually using. If you highlight the text, you can use CTRL-C (or Command-C on a Mac) to copy that text to the clipboard. Then you can paste it here in your forum message. We're much better at helping with those messages when we can see the actual text which appeared on your screen.

  8. #8
    Junior Member
    Join Date
    Jan 2020
    Posts
    4
    Thank you for your replies
    The problem was that the variable BUITLIN_SDCARD is not known ( not in blue as usual) i thought about working on an other pc and this time was something different,
    it shows while compiling that there are more than one library called SD.h (well this is the meaning of the error message, cause it is not in English to copy it here)

  9. #9
    Junior Member
    Join Date
    Jan 2020
    Posts
    3

    Picking wrong library

    I'm not the original poster, but am having the same problem with a fresh install of Arduino 1.8.10, Teensyduino 1.49 on MAC OS Catalina. Seems to be picking up the wrong library. Suggestions? Thanks!

    CardInfo:36: error: 'BUILTIN_SDCARD' was not declared in this scope
    const int chipSelect = BUILTIN_SDCARD;
    ^
    Multiple libraries were found for "SD.h"
    Used: /Users/sellensr/Documents/Arduino/libraries/SD
    Not used: /private/var/folders/3w/fph9nxcx59bgndf_ydyvphlr0000gn/T/AppTranslocation/8CC51EA0-F3D7-4247-9C0D-D4C1D1A31906/d/Teensyduino.app/Contents/Java/libraries/SD
    Not used: /private/var/folders/3w/fph9nxcx59bgndf_ydyvphlr0000gn/T/AppTranslocation/8CC51EA0-F3D7-4247-9C0D-D4C1D1A31906/d/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD
    Multiple libraries were found for "SPI.h"
    Used: /private/var/folders/3w/fph9nxcx59bgndf_ydyvphlr0000gn/T/AppTranslocation/8CC51EA0-F3D7-4247-9C0D-D4C1D1A31906/d/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SPI
    Using library SPI at version 1.0 in folder: /private/var/folders/3w/fph9nxcx59bgndf_ydyvphlr0000gn/T/AppTranslocation/8CC51EA0-F3D7-4247-9C0D-D4C1D1A31906/d/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SPI
    Using library SD at version 1.2.4 in folder: /Users/sellensr/Documents/Arduino/libraries/SD
    'BUILTIN_SDCARD' was not declared in this scope

    Quote Originally Posted by PaulStoffregen View Post
    Maybe Arduino is using the wrong SD library.

    To check, click File > Preferences and turn on verbose output while compiling.

    The click Verify again, and scroll up to look for messages about which SD library Arduino is actually using. If you highlight the text, you can use CTRL-C (or Command-C on a Mac) to copy that text to the clipboard. Then you can paste it here in your forum message. We're much better at helping with those messages when we can see the actual text which appeared on your screen.

  10. #10
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,218
    You should remove this:
    /Users/sellensr/Documents/Arduino/libraries/SD
    It shouldnt be in your libraries folder unless you specifically put it there purposely for some testing or usage

    The library folder takes priority over the core libraries

  11. #11
    Junior Member
    Join Date
    Jan 2020
    Posts
    3
    Thanks! Solves the problem, but will that missing SD library cause compile issues for other platforms?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •