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

Thread: Teensy 4.1 Cannot access Internal SD card

  1. #1
    Junior Member
    Join Date
    May 2020
    Location
    North Carolina
    Posts
    7

    Teensy 4.1 Cannot access Internal SD card

    I am an experienced Arduino user making the switch to Teensy and finding it painful. I recently got the full featured 4.1 with built in SD card, but can find no way to access it.

    Arduino's SD library won't work
    SdFat won't work
    Examples sketches from forums using older boards won't work

    My card is a brand new SanDisk 32 gig, formatted Fat32. My PC reads/writes it perfectly.

    Don't bother asking for my source code, it's all garbage anyway.

    What I need is a GREATLY SIMPLIFIED set of tested examples of how to:

    1. #include the SD library, where in the sketch, and which library actually works in 4.1

    2. Syntax for begin, including CS pin is any - is the CS pin now selected by the 4.1 board for SD?

    3. Syntax for exists and !exists

    4. Syntax for file establishment, file open and file close.

    Something on the order of the way books are written on Arduino would be wonderful.

    I have done all this successfully on Arduino MEGA and built substantial projects using SD, memories, etc., but
    cannot get to first base with Teensy.

    Please keep it simple.
    Last edited by steamrocks; 05-25-2020 at 06:40 PM. Reason: grammar

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,669
    Use SD.begin(BUILTIN_SDCARD) to cause the SD library to access the SD socket on Teensy 4.1.

    The comments in all the SD library examples mention this only for Teensy 3.5 and 3.6. I've committed an update to also mention Teensy 4.1 in those comments.

    https://github.com/PaulStoffregen/SD...9f246b20be1282

  3. #3
    Junior Member
    Join Date
    May 2020
    Location
    North Carolina
    Posts
    7
    Adding to the list of things that DONT work, I talked to Paul and he said you have to put in a statement "chipSelect=BUILTIN_SDCARD
    in code for the 4.1, after which the usual SD libraries from Arduino should work. Below is my code for a simple test, only testing if the SD is functioning:

    #include <SD.h>
    #include <SPI.h>
    int chipSelect = BUILTIN_SDCARD;
    void setup() {

    if (!SD.begin()) Serial.println ("NO LUCK");
    else Serial.println ("SD WORKS!");
    }
    void loop() {
    // put your main code here, to run repeatedly:
    }

    The statement "NO LUCK" is repeated every time.

    Any and all help is appreciated.

  4. #4
    Junior Member
    Join Date
    May 2020
    Location
    North Carolina
    Posts
    7
    MANY THANX, PAUL! One line of written code is worth 1000 verbal descriptions! You can see from my code above that I misinterpreted the verbal info!
    I can get SD to open now, and now I'll mess with read/write tests.

    FYI this is for a fully programmable percussion sequencer or "Drum Machine" used for performance. It currently exists in Arduino format, with
    520 available rhythm patterns, capable of playing about 8 instruments at any given instant, a total palate of about 100. It is programmed via MIDI
    from Cakewalk, and outputs MIDI to the sound source of your choice. It has breaks, fills, intros, endings, drum cadenzas, and lots of other fun stuff.
    I currently have the first one built in the console of my theater organ, the Teensy version will be a portable.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,669
    If you're familiar with serial MIDI on Arduino Mega, one minor detail that commonly comes up is the need for different resistors with 3.3V signals. Details here:

    https://www.pjrc.com/teensy/td_libs_MIDI.html

    You might also be interested to know Teensy can do USB MIDI, both device and host modes. For USB device MIDI, this page has info:

    https://www.pjrc.com/teensy/td_midi.html

    For USB host MIDI, see the examples in the USBHost_t36 library. Usually host mode is used for connecting musical instruments that send MIDI, so perhaps not so useful for a sequencer that primarily transmits MIDI.

  6. #6
    I'm also trying to get the T4.1 to play nice with the built-in SD card slot and having nothing but trouble. After realizing neither SdFat.h nor SdFat-beta work, I tried the above method by using the following code:

    Code:
    #include <SD.h>
    #include <SPI.h>
    
    void setup()
    {
      if (!SD.begin(BUILTIN_SDCARD))
        Serial.println ("NO LUCK");
      else
        Serial.println ("SD WORKS!");
    }
    
    void loop()
    {
      // nothing
    }
    But unfortunately, I get "NO LUCK". Any ideas?

    Honestly, why is it so hard to get the SD card slot working for the T4.1?????

  7. #7
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,846
    Lets start with the basics.

    What brand of micro SD card is it? How many megabytes or gigabytes does it support? Can you read the file on another system? How was the card formatted?

    Micro SD cards come in different flavors:
    • https://en.wikipedia.org/wiki/SD_card
    • Original SD cards: Size up to 1 gigabyte, uses Microsoft FAT16 filesystem;
    • SDHC cards: Size 2 gigabytes up to 32 gigabytes, uses Microsoft FAT32 filesystem;
    • SDXC cards: Size 33 gigabytes up to 2 terabytes, uses Microsoft exFat filesystem;
    • SDUC cards: Evidently there is a SDUC version for sizes above 2 terabytes, and it uses the Microsoft exFat filesystem.


    I don't know whether either SD or SDfat-Beta supports SDXC cards or the exFat format. I have used a Samsung EVO Seletct 32GB card formatted with the FAT32 filesystem, using the standard SD.h library, so it supports SDHC.

    So verify that you have a usable card formatted to the FAT32 filesystem (using a card reader on your computer).

    If you have a digital camera that takes micro-SD cards (or it takes SD-cards and you have the adapter), trying formatting the card in the camera and take a shot. Note, use the format option, and not the delete all option if the camera has both. Or if your cellphone takes micro-SD cards, try using the card in the phone.

    If you have a second card, try that.

    It also might be possible that there is dirt on the contacts. If you have something small enough to fit in the slot, try to clean it out. Or perhaps one of those air blowers. Likewise try cleaning your card if you can't read it in other devices.

    If the card is new, perhaps it did not have an initial filesystem formatted on the card (some of the cards I've bought seemed to have no formatting). Try formatting it with your PC, camera, or phone.

    In terms of files on the card, it is generally a good idea to stick to the original Microsoft 8.3 naming connection.

  8. #8
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,752
    Quote Originally Posted by Power_Broker View Post

    Honestly, why is it so hard to get the SD card slot working for the T4.1?????
    I had never any problems with SdFat-beta. Maybe your "SdTerminal" (issue on Bill's github) is screwing up the code.

  9. #9
    Quote Originally Posted by WMXZ View Post
    I had never any problems with SdFat-beta. Maybe your "SdTerminal" (issue on Bill's github) is screwing up the code.
    It has nothing to do with "SdTerminal". The problem lies with "SdFat-beta" since the same library, well, SdFat.h, works flawlessly with "SdTerminal" with Teensy 3.5 and 3.6 boards, but can't compile for my Teensy 4.1.


    @MichaelMeissner :

    My SD card is a SanDisk ImageMate microSDXC card with 128GB of storage. I already formatted it manually with my PC with the exFAT file system with 128kB allocation unit size. It works perfectly with my PC, so I still don't know why I can't get the T4.1 card slot to work.

  10. #10
    Ok, so to get my card working with SdFat-Beta, I had to do the following (with help from here):

    Code:
    #include "SdFat.h"
    
    SdExFat sd;
    
    void setup()
    {
      if (!sd.begin(SdioConfig(FIFO_SDIO))) { // SdFat.h Ver 2.0.0 Beta
        Serial.println("m.SD initialization failed!");
      } else {
        Serial.println("m.SD initialization OK");
      }
    
      auto file = sd.open("hi.txt", FILE_WRITE);
      file.write("hi");
      file.close();
    }
    
    void loop()
    {
      
    }

    This still doesn't explain why the normal SD lib won't work - unless SD.h is incompatible with the exFAT file system?

    Seems like the whole SD card interface for T4.1 is a complete mess. Hopefully it will get fixed soon.

  11. #11
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,752
    Quote Originally Posted by Power_Broker View Post
    This still doesn't explain why the normal SD lib won't work - unless SD.h is incompatible with the exFAT file system?
    SD library does not support exFAT.

  12. #12
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,752
    I see in your code that you include SdFat.h
    Please note that SdFat.beta cannot be used in parallel to SD library and SdFat library, but is to be considered a replacement. They all use SdFat.h as include.
    Depending on include and link order you may have issues compiling and running.

    You can remove these original libraries or, what I do sometimes, rename the SdFat.h in the SdFat-beta library to SdFat-beta.h and include this file.

  13. #13
    I deleted the original SdFat library and replaced it with the beta - but still, this is a question about the normal SD lib, not the SdFat lib - I just wanted to spell out the source of my overall frustration with T4.1 SD issues (and, more recently, softwareserial issues).

  14. #14
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    7,625
    Quote Originally Posted by PaulStoffregen View Post
    Use SD.begin(BUILTIN_SDCARD) to cause the SD library to access the SD socket on Teensy 4.1.

    The comments in all the SD library examples mention this only for Teensy 3.5 and 3.6. I've committed an update to also mention Teensy 4.1 in those comments.

    https://github.com/PaulStoffregen/SD...9f246b20be1282
    Shouldn't this maybe also mention T4, if one uses the bottom pads to connect up an SDCard?

  15. #15
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    7,625
    Quote Originally Posted by Power_Broker View Post
    I deleted the original SdFat library and replaced it with the beta - but still, this is a question about the normal SD lib, not the SdFat lib - I just wanted to spell out the source of my overall frustration with T4.1 SD issues (and, more recently, softwareserial issues).
    Yes it would be great if SDFat Beta might some day be actually released. And we had versions that all had the same License type and the like, that we can all standardize on. Hopefully maybe at some point in the future have some standard file system setup, that all of like libraries derive from...

    But what is the issue with SoftwareSerial? For the most part on Teensy, we mostly use Hardware Serial. As we have many of them. Also as I have mentioned in a few threads, we can create SoftwareSerial like objects using FlexIO. Also with the system, you can remap the RX pin of a Hardware Serial port to any of the IO pins that are XBar pins... So there are lots of options. Question is what are you needing that these wont work for you?

  16. #16
    As for softwareserial, I need it to interface with a one-wire device (FrSky ASS-70 pitot tube sensor) via this library, but apparently, softwareserial only works in transmit only, and the previously linked lib requires transmit and receive...

  17. #17
    Quote Originally Posted by KurtE View Post
    Shouldn't this maybe also mention T4, if one uses the bottom pads to connect up an SDCard?
    Haven't tried - I don't own a T4

  18. #18
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,355
    Quote Originally Posted by Power_Broker View Post
    Haven't tried - I don't own a T4
    That @KurtE post was in reply to the PaulStoffregen note on this comment edit:: // Teensy 3.5 & 3.6 & 4.1 on-board: BUILTIN_SDCARD

    For those that do have a T_4.0 and wire SD Card to the under pads - the same usage note would apply:: // Teensy 3.5 & 3.6 & 4.1 on-board (& 4.0 under pads): BUILTIN_SDCARD

  19. #19
    Junior Member
    Join Date
    May 2020
    Location
    South East England
    Posts
    6
    Hi,
    I have a data capture project nearing completion, it started with a Teensy 3.2 and migrated to the Teensy 4. The software, hardware and PCB designs (now on Rev 3) have kept me busy for most of a year. The project monitors several instruments and sends the data to a laptop PC for storage and analysis. Some of my testers would rather have the data stored within the data capture module and leave the laptop back at base. (One less heavy item to carry, battery to charge, connectors to fail, cables to leave at base etc. etc.)


    One option is to use the Teensy 4.1 instead of the Teensy 4 and have the on-board SD card store the data until returning to base. I noted that the 28 pins nearest the T4.1 USB plug match the T4 footprint so I fitted two 14 pin SIL headers to a T4.1, plugged it into my motherboard and the existing software runs just fine; a bit of a kludge but it works. Fortunately the overhang of unused T4.1 connectors does not foul anything on the motherboard or the enclosure... lucky for once!


    Like 'steamrocks' says in his opening entry I cannot find any ready-to-use skeleton code for a T4.1 on which to build some simple data storage features. I've tried searching the forum and elsewhere to no avail,most likely I have not used the proper search terms or I have just been too dumb. Can anyone point me in the right direction?


    Although it puts the finances under a bit of pressure I have changed the BOM to specify a T4.1 instead of a T4 and the beta units now being assembled will at least be software upgrade-able to use on-board storage at a later date. However, it would be really good to have the field trials start in early October 2020 with a laptop free system.


    (Please excuse the rather vague project description, it is all under wraps until late in the year.)
    Last edited by RichardL; 09-16-2020 at 08:47 AM. Reason: Copy/Paste failure to work as expected.

  20. #20
    Junior Member
    Join Date
    Sep 2020
    Location
    Cincinnati, OH
    Posts
    6
    I am recognizing an SD card on the Teensy 4.1 internal.

    However, I get this warning:

    Multiple libraries were found for "SD.h"
    Used: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD
    Not used: /Applications/Teensyduino.app/Contents/Java/libraries/SD


    Which is correct?

Posting Permissions

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