🛠 Logger sur carte SD via le port SDIO natif du Teensy 4.1

Teensy 4.1 · intermediaire · Schéma : le connecteur SD monté sous le Teensy 4.1, relié au bus SDIO 4 bits indépendant du SPI ; à côté, le contrôleur i.MX RT1062 avec ses 32 canaux DMA généraux et le DMA dédié du périphérique SD.

Objectives

The Teensy 4.1 is the only board in the family with an SD connector under the board, connected to a native 4-bit SDIO port: no SPI bus sharing, no chip-select pin to wire, and a dedicated DMA in the peripheral. This tutorial sets up a data logger capable of writing continuously without blocking the rest of the program.

Hardware

Key points

Complete code

#include <SD.h>

const uint8_t LED = 13;

void setup {
  Serial.begin(9600);
  while (!Serial && millis < 3000);
  if (!SD.begin(BUILTIN_SDCARD)) {
    Serial.println("SD absente (FAT32, <= 32 Go)");
    while (true) { digitalWrite(LED, !digitalRead(LED)); delay(200); }
  }
  Serial.println("SD prête sur SDIO");
}

void loop {
  File log = SD.open("log.txt", FILE_WRITE);
  if (log) {
    log.print(millis);
    log.print(" A0=");
    log.println(analogRead(14));
    log.close;
  }
  delay(1000);
}

Expected verification

SD ready on SDIO appears on the first run; after reconnecting, log.txt contains one line per second. Remove the card and reconnect the power: LED 13 blinks rapidly, indicating that SD.begin failed — your fallback program is doing its job.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials