Atomic TFCard Base

This is the driver library for the Atomic TFCard Base, which is used to mount TFCard.

Support the following products:

Atom TFCard

Atomic TFCard Base

UiFlow2 Example

TFCard mount

Open the atoms3r_tfcard_example.m5f2 project in UiFlow2.

This example demonstrates how to read/create a directory using Atomic TFCard Base.

UiFlow2 Code Block:

example.png

Example output:

Files in the /sd directory.

MicroPython Example

TFCard mount

This example demonstrates how to read/create a directory using Atomic TFCard Base.

MicroPython Code Block:

 1# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8from base import AtomicTFCardBase
 9import time
10
11
12title0 = None
13base_tfcard = None
14
15
16def setup():
17    global title0, base_tfcard
18
19    M5.begin()
20    title0 = Widgets.Title("TFCard e.g.", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
21
22    base_tfcard = AtomicTFCardBase(slot=3, width=1, sck=7, miso=8, mosi=6, freq=1000000)
23    os.chdir("/sd")
24    print((str("Current dir:") + str((os.getcwd()))))
25    print((str("list /sd/dir: ") + str((os.listdir("/sd/")))))
26    if not ("sdcard_test" in os.listdir("/sd/")):  # noqa: E713
27        print("Try create 'sdcard_test' directory in /sd/")
28        os.mkdir("/sd/sdcard_test")
29    print((str("'sdcard_test' is directory?:") + str((os.stat("/sd/sdcard_test")[0] == 0x4000))))
30    print((str("'sdcard_test' is file?:") + str((os.stat("/sd/sdcard_test")[0] == 0x8000))))
31    print("Delay 1s to delete 'sdcard_test' directory")
32    time.sleep(1)
33    os.rmdir("/sd/sdcard_test")
34    if not ("sdcard_test" in os.listdir("/sd/")):  # noqa: E713
35        print("Directory 'sdcard_test' deleted successfully")
36
37
38def loop():
39    global title0, base_tfcard
40    M5.update()
41
42
43if __name__ == "__main__":
44    try:
45        setup()
46        while True:
47            loop()
48    except (Exception, KeyboardInterrupt) as e:
49        try:
50            from utility import print_error_msg
51
52            print_error_msg(e)
53        except ImportError:
54            print("please update to latest firmware")

Example output:

Files in the /sd directory.

API

function AtomicTFCardBase

AtomicTFCardBase(slot=1, width=1, cd=None, wp=None, sck=None, miso=None, mosi=None, cs=None, freq=20000000)

This function is only used to initialize and mount the SD card to the /sd directory, and to try to unmount the existing SD card before mounting it. Other file operations (such as reading/writing files, creating directories, etc.) need to be performed by the os module.

Parameters:
  • slot (int) – Which of the available interfaces to use. The default value is 1.

  • width (int) – The bus width for the SD/MMC interface. The default value is 1.

  • cd (int) – The card-detect pin to use. The default value is None.

  • wp (int) – The write-protect pin to use. The default value is None.

  • sck (int) – The SPI clock pin to use. The default value is None.

  • miso (int) – The SPI miso pin to use. The default value is None.

  • mosi (int) – The SPI mosi pin to use. The default value is None.

  • cs (int) – The SPI chip select pin to use. The default value is None.

  • freq (int) – The SD/MMC interface frequency in Hz. The default value is 20000000.

Returns:

None

UiFlow2 Code Block:

init.png

MicroPython Code Block:

from base import AtomicTFCardBase
base_tfcard = AtomicTFCardBase(slot=3, width=1, sck=7, miso=8, mosi=6, freq=20000000)

See os – basic “operating system” for more details.