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:
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.
 
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.
 
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.
 
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?????
 
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.
 
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.
 
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.
 
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.
 
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).
 
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?
 
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...
 
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
 
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:
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?
 
I also confirm multiple problems with SDCARD on Teensy 4.1, i followed all the tips given in this article, even formatting my SDCARD with a camera, nothing works, sdcard is recognized once on 10 times with cardinfo, showing a SD1 model card, but never recognize any FAT formatted partition. When i take the same card on a Mac, or Windows, or Ubuntu, the card is perfectly recognized and useable as FAT32 card (32gb Sandisk).
 
I also confirm multiple problems with SDCARD on Teensy 4.1, i followed all the tips given in this article, even formatting my SDCARD with a camera, nothing works, sdcard is recognized once on 10 times with cardinfo, showing a SD1 model card, but never recognize any FAT formatted partition. When i take the same card on a Mac, or Windows, or Ubuntu, the card is perfectly recognized and useable as FAT32 card (32gb Sandisk).
It often helps to have additional information, like: Arduino version, Teensyduino version, what SD library are you using? Are you using the SD on the T4.1?

My assumption is you are using SD library as you mentioned Card Info. But again a guess.
Also I assume you changed the chipSelecte = BUILTIN_SDCARD

Also assuming that when you built it did not say something like: it used a different SD library.

Note: the older SD Fat library may not have supported all of the variants of FAT like EXFat, ...

There is newer versions going into the latest beta build of Teensyduino.

Also you can get more extended FAT support by installing some of the SDFat libraries like:
https://github.com/greiman/SdFat-beta
or
https://github.com/greiman/SdFat
 
I also confirm multiple problems with SDCARD on Teensy 4.1

Hi. I have the SD card working fine, although I have actually only used one card.

The EXTMEM, on the other hand....

My question concerned the status of the SD libraries. Whenever I have any kind of error in the code writing to the SD card, I get a compiler message that there are multiple SD libraries. Whichever one the Big C chooses works OK. But, I am confused as to the status of the various SD libraries.
 
Hello, just checked the sample coming with the sdfat library, these are working now correctly, so i think for teensy 4.1 it is mandatory to use the sdfat library, not the SD one, and also, BUILTIN_SDCARD stuff is not necessary there...
Thanks a lot for your help, have a nice day all...
 
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?

That isn't a 'WARNING' to be concerned with - unless the one chosen is WRONG - more of informative feedback - actually added to the Arduino system by Paul@PJRC

Depending on how the environment is setup for one or more boards - there may be multiple libraries installed and some default libraries are included with the IDE

TeensyDuino installs libraries appropriate for 'best' expected use with Teensy so they should be noted as :: "Used: .../hardware/teensy/avr/libraries/..."

If the wrong library is chosen and the build fails or it doesn't work that information can lead to a solution where a 'Sketchbook Installed' library or other copy may override an intended one.


As for SD.h as KurtE notes "There is newer versions going into the latest beta build of Teensyduino." :
This is TeensyDuino 1.54 currently in Beta 5 with beta 6 coming ... the prior SD.h library in TeensyDuino is being replaced with a much more efficient and feature filled release of "SD Fat Ver #2" - that was the long term prior 'SD Fat Beta' from B Greiman. ( note a new SD Fat Beta toward 2.1 is underway )
 
Back
Top