Example 24: SD Card Read/Write
Example 24: SD Card Read/Write
Experiment Overview
Read/write SD/TF cards via SPI or SDIO interface for data storage, logging and configuration file management. FastBee has reserved the SDIO peripheral type (type 37) and configuration framework, but runtime SD card mounting and file read/write actions are not yet built-in.
Note: This experiment document provides wiring and configuration placeholders. Actually enabling SD card read/write is recommended in Full or custom builds with file actions added, to avoid excessive resource usage in Lite firmware.
Hardware Wiring
SPI Mode
| Board Label | GPIO Pin | SD Card Pin |
|---|---|---|
| MOSI | GPIO23 | DI (CMD) |
| MISO | GPIO19 | DO (DAT0) |
| CLK | GPIO18 | CLK |
| CS | GPIO5 | CS (DAT3) |
SDIO Mode (Faster)
| Board Label | GPIO Pin | SD Card Pin |
|---|---|---|
| CLK | GPIO14 | CLK |
| CMD | GPIO15 | CMD |
| D0 | GPIO2 | DAT0 |
| D1 | GPIO4 | DAT1 |
| D2 | GPIO12 | DAT2 |
| D3 | GPIO13 | DAT3 |
JSON Configuration Example
SPI Mode
{
"peripherals": [
{
"id": "sd_spi",
"name": "SD Card-SPI",
"type": 37,
"enabled": false,
"pins": [23, 19, 18, 5],
"params": {}
}
]
}SDIO Mode
{
"peripherals": [
{
"id": "sd_sdio",
"name": "SD Card-SDIO",
"type": 37,
"enabled": false,
"pins": [14, 15, 2, 4, 12, 13],
"params": {}
}
]
}Peripheral Execution Linkage
⚠️ Note: Peripheral execution currently does not have built-in
file_append/file_writefile actions. Below is the future expansion direction.
Future Scenario: Temperature Data Log (Timer Trigger)
Function: Read temperature every 60 seconds and write to SD card log file
Expected Configuration Steps (pending firmware support):
- Create rule, name:
Temperature Data Log - Trigger configuration:
- Trigger Type: Select Timer Trigger
- Timer Mode: Select Fixed Interval
- Interval Time:
60000(60 seconds)
- Action configuration:
- Action 1: Read Sensor →
dht_01 - Action 2: File Append →
/sd/temperature_log.csv
- Action 1: Read Sensor →
Expected Log Format:
Timestamp,Temperature(°C),Humidity(%)
2024-01-01 08:00:00,25.3,60
2024-01-01 08:01:00,25.4,59Notes
- Format: SD card must be formatted as FAT32 (<32GB) or exFAT (≥32GB)
- Power: SD card working current can reach 100mA, ensure stable 3.3V supply
- SPI Sharing: When SD card uses SPI bus, CS pin is used for device selection
- GPIO12 Conflict: In SDIO mode GPIO12 is DAT2, must not be HIGH during boot
- Write Frequency: Avoid too frequent write operations, recommend batch writing
- File System: FastBee uses LittleFS for internal Flash, SD card uses FAT file system
- Hot Swap: Not supported, SD card must be inserted/removed when powered off
- Current Status: Configuration framework ready, runtime driver and file actions pending
