blob: bb711b05fa663de7db8bab759611956ffa3411b1 [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
Sebastian Plamauer35267162014-05-04 12:53:01 +02008log = open('1:/log.csv', 'w') # open file to write data - 1:/ ist the SD-card, 0:/ the internal memory
9blue.on() # turn on blue LED
Damien Georgefd04bb32014-01-07 17:14:05 +000010
Sebastian Plamauer35267162014-05-04 12:53:01 +020011for i in range(100): # 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.)
12 t = pyb.millis() # get time since reset
13 x, y, z = accel.filtered_xyz() # get acceleration data
14 log.write('{},{},{},{}\n'.format(t,x,y,z)) # write data to file
Damien Georgefd04bb32014-01-07 17:14:05 +000015
Sebastian Plamauer35267162014-05-04 12:53:01 +020016log.close() # close file
17blue.off() # turn off LED