File tree Expand file tree Collapse file tree
lib/daplink_flash/examples Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ))
Original file line number Diff line number Diff line change 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 )))
Original file line number Diff line number Diff line change 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 ())
You can’t perform that action at this time.
0 commit comments