πŸ“¦ Archived documentation: r1 (committed 2026-07-24) View current documentation β†’

sd

Memory card access for custom log files.

The sd object reads and writes to the device memory card, letting you keep custom configurations or log files alongside the built-in datalogger β€” useful for raw text logs, CSV exports or audit trails.

SD cards must be formatted as Fat32. Cards up to 128GB.

To avoid long read and write delays we recommend keeping the directory structure small and avoiding large files.

Functions

sd.append()

sd.append(filename, data)

Appends a string to a file on the memory card, creating the file if needed.

Appends data to filename on the memory card. Convert numbers and objects with string() first, and terminate lines with "\n" yourself.

Pair with datetime().epoch for timestamped log lines.

Arguments

NameTypeRequiredDefaultDescription
filename string yes β€” File name on the memory card, e.g. "log.txt".
data string yes β€” Text to append. Use string() to convert numbers/objects.

Returns

number 0 = no error, >0 = error code

Example

// Timestamped log line: 1589247811:    ch3: 23.454
sd.append('log.txt', string(datetime().epoch) + ":    ch3: " + string(23.454) + "\n");

sd.read()

sd.read(file) -> object

Read file contents from SD Card

Read a file from the sd card and returns the result

Arguments

NameTypeRequiredDefaultDescription
filename string yes β€” e.g. "config.json"

Returns

object {error:0,data:"file contents"} 0 = No Error, data = file contents as a string

Example

let res = sd.read("hello.txt");
if(!res.error){
 print(res.data); // Prints the contents of hello.txt
} else {
  print("Failed to load file err=", string(res));
}

sd.write()

sd.write(filename,data)

Write to a file on the SD Card

Easily write your string to a file on the SD card.

If the file does not exist it will be automatically created, if it already exists it will be overwritten.

Arguments

NameTypeRequiredDefaultDescription
filename string yes β€” e.g. "config.json"
data string yes β€” Data to write to the file

Returns

number 0 = no error, >0 = error code

Example

sd.write("hello.txt","Hello World!");