Skip to content

Commit 0c18740

Browse files
committed
daplink_flash: Add usage examples for write, read and info.
1 parent f2f31c9 commit 0c18740

3 files changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Display DAPLink Flash bridge status and filename."""
2+
3+
from machine import I2C
4+
from daplink_flash import DaplinkFlash
5+
6+
i2c = I2C(1)
7+
flash = DaplinkFlash(i2c)
8+
9+
print("=== DAPLink Flash Info ===")
10+
print("WHO_AM_I: 0x{:02X}".format(flash.device_id()))
11+
print("STATUS: 0x{:02X}".format(flash._status()))
12+
print("ERROR: 0x{:02X}".format(flash._error()))
13+
print("Busy: ", flash.busy())
14+
15+
name, ext = flash.get_filename()
16+
print("Filename: {}.{}".format(name, ext))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""Read and display the current file stored on flash."""
2+
3+
from machine import I2C
4+
from daplink_flash import DaplinkFlash
5+
6+
i2c = I2C(1)
7+
flash = DaplinkFlash(i2c)
8+
9+
name, ext = flash.get_filename()
10+
print("Reading file: {}.{}".format(name, ext))
11+
print()
12+
13+
content = flash.read()
14+
if len(content) == 0:
15+
print("(empty)")
16+
else:
17+
print(content.decode())
18+
print("---")
19+
print("{} bytes".format(len(content)))
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Write CSV data to flash via DAPLink bridge."""
2+
3+
from machine import I2C
4+
from time import sleep_ms
5+
from daplink_flash import DaplinkFlash
6+
7+
i2c = I2C(1)
8+
flash = DaplinkFlash(i2c)
9+
10+
print("WHO_AM_I:", hex(flash.device_id()))
11+
12+
# Set filename and erase
13+
flash.set_filename("DATA", "CSV")
14+
flash.clear_flash()
15+
sleep_ms(500)
16+
print("Flash erased.")
17+
18+
# Write CSV header + data
19+
flash.write_line("temperature;humidity;pressure")
20+
flash.write_line("25.3;48.2;1013.5")
21+
flash.write_line("25.5;47.8;1013.4")
22+
flash.write_line("25.4;48.0;1013.6")
23+
print("Data written.")
24+
25+
# Read back
26+
content = flash.read()
27+
print("File content:")
28+
print(content.decode())

0 commit comments

Comments
 (0)