blob: a2fbe1437d7e36e2603c627d92b70ecc2c2f3a5c [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
Sebastian Plamauer35267162014-05-04 12:53:01 +02005accel = 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
9log = open('/sd/log.csv', 'w')
10
Sebastian Plamauer35267162014-05-04 12:53:01 +020011blue.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):
Sebastian Plamauer35267162014-05-04 12:53:01 +020015 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
Sebastian Plamauer35267162014-05-04 12:53:01 +020019log.close() # close file
20blue.off() # turn off LED