blob: e8b5d101daff72122bfdb225f797cb128e61d279 [file] [log] [blame]
Sebastian Plamauer35267162014-05-04 12:53:01 +02001# log the accelerometer values to a .csv-file on the SD-card
Damien Georgefd04bb32014-01-07 17:14:05 +00002
Sebastian Plamauer35267162014-05-04 12:53:01 +02003import pyb
Damien Georgefd04bb32014-01-07 17:14:05 +00004
Damien George69661f32020-02-27 15:36:53 +11005accel = pyb.Accel() # create object of accelerometer
6blue = pyb.LED(4) # create object of blue LED
Damien Georgefd04bb32014-01-07 17:14:05 +00007
Damien Georgea0441fc2020-02-27 15:25:48 +11008# open file to write data - /sd/ is the SD-card, /flash/ the internal memory
Damien George69661f32020-02-27 15:36:53 +11009log = open("/sd/log.csv", "w")
Damien Georgea0441fc2020-02-27 15:25:48 +110010
Damien George69661f32020-02-27 15:36:53 +110011blue.on() # turn on blue LED
Damien Georgefd04bb32014-01-07 17:14:05 +000012
Damien Georgea0441fc2020-02-27 15:25:48 +110013# do 100 times (if the board is connected via USB, you can't write longer because the PC tries to open the filesystem which messes up your file.)
14for i in range(100):
Damien George69661f32020-02-27 15:36:53 +110015 t = pyb.millis() # get time since reset
16 x, y, z = accel.filtered_xyz() # get acceleration data
17 log.write("{},{},{},{}\n".format(t, x, y, z)) # write data to file
Damien Georgefd04bb32014-01-07 17:14:05 +000018
Damien George69661f32020-02-27 15:36:53 +110019log.close() # close file
20blue.off() # turn off LED