How to link teensy4.0 with micro sd card

As the Teensy 4.0 is already on 3.3V you don't need a voltage regulator and also no level shifter. Probably it works anyway. The according pins are found in the pin description of the Teensy: pins 10 ... 13
Connect CS to CS and so on. You could start with one of the SD examples in Teensyduino.

https://www.pjrc.com/store/teensy40.html
https://www.pjrc.com/store/teensy40_card10a_rev2.png
teensy40_card10a_rev2.png
 
OK I link the pins like this:

MicroSD card Adapter -> Teensy4.0
CS -> PIN 10
SDK -> PIN 13
MOSI -> PIN 11
MOSO -> PIN 12
VCC -> 3v
GND -> GND

why in the tool -> port I got on COM4(teenst3.2/3.1) ? when I select this port I got on initialization failed!
And when select COM4 serial(Teensy4.0) I got on " Error opening serial port 'usb:0/140000/0/3'. (Port busy) "

What is the error?

This is my code:

#include <SD.h>

File myFile;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}


Serial.print("Initializing SD card... \n");

if (!SD.begin()) {
Serial.println("initialization failed! \n");
return;
}
Serial.println("initialization done. \n");

// 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...\n");
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 \n");
}

// 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
}
 
Last edited:
Please could you give me the correct schematic? because I use it like this link http://mb-raw.blogspot.com/2017/07/teensy-tutorial-sd-card.htmlbut I cannot open the file

In that link there is a schematic for the Teensy 3.2 which stays the same for the Teensy 4.0 (as shown above pointing to the according pins).

You have to be more specific and describe your setup, make a photo of the connections, tell us what exactly is on your card and what is printed on the serial monitor...
 
That image is confused for sure. The 'Teensy Ports' is right for T_4.0 and should be used.

Something else on the computer seems to have the port open preventing access to that COM4.

If a sketch is built for board T_4.0 with VERIFY then doing a button press should cause it to upload as it reconnects after the button press.

Upload a sketch with USB Serial included and perhaps a blink sketch - but include some Serial.print once a second so that SerMon can connect and verify it works.
 
tell us what exactly is on your card and what is printed on the serial monitor...

The card have txt file (test.txt) and the output of serial monitor:
when I select (COM4(teenst3.2/3.1)) port I got on initialization failed!
And when select COM4 serial(Teensy4.0) I got on " Error opening serial port 'usb:0/140000/0/3'. (Port busy) "
 
Looks like no solder between Teensy and the pins.

nosolder.jpg

This will not give a reliable connection. The wires connect to the pins, but without solder you will have only an air gap between each pin and Teensy.
 
Another possible problem is the buffer chip speed. The web page says the buffer is 74LCV125A. But it also has 4 resistor, and no specific info about how those resistors are connected.

If the chip really is 74LCV125A, and the resistors are pullup or pulldown (connected between the signals and power) then this hardware should work well. 74LCV125A is fast enough.

But if the board was actually made with a slower / cheaper chip (many other people have reported issues with other similar SD boards have slow buffer chips), or if the resistors are connected in series, the hardware may be too slow for Teensy. Often these products are only tested with old boards like Arduino Uno which use much slower SPI clock speeds.

You can configure Teensy to use slower SPI clock. In Arduino, click File > Examples > SD > SdFat_Usage for details.

But before fiddling with clock speeds, make sure all 6 wires have solder between Teensy and the pin. Nothing can work if the pins are not soldered.
 
Unfortunately, no, this looks like "cold solder". Hopefully this info-graphic can help.

Soldering.jpg


You'll need to work on your soldering technique. Don't feel bad, cold solder joints are a very common mistake and often it can solved by just reheating the solder. Applying liquid flux before reheating can also *really* help.

Cold solder happens when you don't leave the soldering iron in contact long enough (step #3) for all the parts to fully heat up to the same temperature. It can also be much worse if the solder isn't fed in close to the joint (step #2) because the flux chemical inside the solder tends to burn off before it can clean all the metal surfaces, which makes the solder tend to clump up rather than smoothly flow.

If you don't have liquid flux but you have time to order some, it's really worthwhile to get. Usually it comes in a small "flux pen" or in a huge bottle. A little goes a long way. When shopping, the main issue is getting liquid flux meant to be used with whatever type of solder you have (which has some flux mixed in).

Should also mention, if your flux type is water soluble organic acid, washing the flux off with hot water is essential. That type of flux makes soldering really easy and gives beautiful results, but the leftover residue is corrosive. Fortunately it's easy to wash off. The hard part is fully drying the leftover water, since it seeps into all small spaces.. Baking in a low temperature oven for 10 minutes is the most reliable way. Most rosin type flux can be left indefinitely. Usually these are called "no clean" flux. Either type is so much better than not using any at all, when attempting to reheat a cold solder joint.
 
Last edited:
1.jpg

I solder the board like the photo and link with SD card :
MicroSD card Adapter -> Teensy4.0
CS -> PIN 10
SDK -> PIN 13
MOSI -> PIN 11
MOSO -> PIN 12
VCC -> 3v
GND -> GND

But the same problem I cant read from SD card!
Any help please?

What about MOSO in MicroSD card Adapter ? is the same with MISO ?
 
Any help please?

Soldering in your latest photo (msg #12) looks good. But the photo doesn't show the wires (hidden underneath Teensy) nor the SD adaptor, so impossible to check if you're connected the wires properly.


What about MOSO in MicroSD card Adapter ? is the same with MISO ?

It's probably meant to be MISO. At least that's how it seems comparing the official documentation to your photo (msg #5).

Micro-SD-TF-Card-Module-Pinout-SPI.png

photo.jpg
 
If you show us a photo with your wiring, so we can actually see how each wire connects to both boards, we could at least help check if all the wires look like they're connected to the right places.

Also recall I mentioned in msg #9 about problems with slow buffer chips. According to the docs, this board should have 74LCX125 which is known to be fast enough. But since the board you have seems to have one of its signal labels with a spelling error, perhaps you're dealing with a low quality clone / counterfeit product? If so, and if it has a slow / cheap buffer chip, it probably still can work but only if using the special init method to slow the SPI clock speed. Maybe you could take a photo that shows the part number on the buffer chip? Might help to use a light and try different angles until you find a way your camera can capture the printing on the chip.
 
If you show us a photo with your wiring, so we can actually see how each wire connects to both boards, we could at least help check if all the wires look like they're connected to the right places.

Also recall I mentioned in msg #9 about problems with slow buffer chips. According to the docs, this board should have 74LCX125 which is known to be fast enough. But since the board you have seems to have one of its signal labels with a spelling error, perhaps you're dealing with a low quality clone / counterfeit product? If so, and if it has a slow / cheap buffer chip, it probably still can work but only if using the special init method to slow the SPI clock speed. Maybe you could take a photo that shows the part number on the buffer chip? Might help to use a light and try different angles until you find a way your camera can capture the printing on the chip.


This is my wiring:

0-02-05-2981b8a0c44d8077da8914f3683b2e7f8edf1a3de478c25e11f7e6a3a6ec524e_5ee7f3d99356c0e5.jpg

0-02-05-096dcadb50565e122175e3e41771908ae63dbf3730e2fe45c85a12ca7f5b1955_a58c33b5dce691fd.jpg

0-02-05-e8d9475da9c09025264f25b025fe90c2bbf2d4f588e90445df2c4ff657fbdde8_3bfee6dcc35b2ddd.jpg
 
Data wires look right.

I am not sure how this board exactly works with the level shifter and voltage regulator with 3.3V as VCC?
 
Let's explore whether that board has a slow buffer chip.

Here's a copy of the listfiles example with SD.begin() replaced by the special SD.sdfs.begin() that configures a slower SPI clock. The lines in green at the ones changed (so you can see how to adapt other SD examples...)

Does this help?

Code:
#include <SD.h>

const int chipSelect = 10;

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect.
  }
  Serial.print("Initializing SD card...");
  [COLOR="#008000"]bool ok = SD.sdfs.begin(SdSpiConfig(chipSelect, SHARED_SPI, SD_SCK_MHZ(4)));
  if (!ok) {[/COLOR]
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  File root = SD.open("/");
  
  printDirectory(root, 0);
  
  Serial.println("done!");
}

void loop()
{
  // nothing happens after setup finishes.
}

void printDirectory(File dir, int numSpaces) {
   while(true) {
     File entry = dir.openNextFile();
     if (! entry) {
       //Serial.println("** no more files **");
       break;
     }
     printSpaces(numSpaces);
     Serial.print(entry.name());
     if (entry.isDirectory()) {
       Serial.println("/");
       printDirectory(entry, numSpaces+2);
     } else {
       // files have sizes, directories do not
       int n = log10f(entry.size());
       if (n < 0) n = 10;
       if (n > 10) n = 10;
       printSpaces(50 - numSpaces - strlen(entry.name()) - n);
       Serial.print("  ");
       Serial.print(entry.size(), DEC);
       DateTimeFields datetime;
       if (entry.getModifyTime(datetime)) {
         printSpaces(4);
         printTime(datetime);
       }
       Serial.println();
     }
     entry.close();
   }
}

void printSpaces(int num) {
  for (int i=0; i < num; i++) {
    Serial.print(" ");
  }
}

void printTime(const DateTimeFields tm) {
  const char *months[12] = {
    "January","February","March","April","May","June",
    "July","August","September","October","November","December"
  };
  if (tm.hour < 10) Serial.print('0');
  Serial.print(tm.hour);
  Serial.print(':');
  if (tm.min < 10) Serial.print('0');
  Serial.print(tm.min);
  Serial.print("  ");
  Serial.print(tm.mon < 12 ? months[tm.mon] : "???");
  Serial.print(" ");
  Serial.print(tm.mday);
  Serial.print(", ");
  Serial.print(tm.year + 1900);
}
 
Last guess, any chance you powered that SD board with 5V when connected to the ESP (as shown on that page) but powered it with only 3.3V (3rd photo on msg #16) when connected to Teensy?

Maybe it only works properly with 5V power and can't power up the SD card with only 3.3V? The first page says "the module includes an onboard ultra-low dropout voltage regulator", but maybe the one you have actually as a not-so-low dropout voltage regulator which needs significantly more than 3.3V to work?
 
Back
Top