Sebastian Plamauer | 3526716 | 2014-05-04 12:53:01 +0200 | [diff] [blame^] | 1 | # log the accelerometer values to a .csv-file on the SD-card |
Damien George | fd04bb3 | 2014-01-07 17:14:05 +0000 | [diff] [blame] | 2 | |
Sebastian Plamauer | 3526716 | 2014-05-04 12:53:01 +0200 | [diff] [blame^] | 3 | import pyb |
Damien George | fd04bb3 | 2014-01-07 17:14:05 +0000 | [diff] [blame] | 4 | |
Sebastian Plamauer | 3526716 | 2014-05-04 12:53:01 +0200 | [diff] [blame^] | 5 | accel = pyb.Accel() # create object of accelerometer |
| 6 | blue = pyb.LED(4) # create object of blue LED |
Damien George | fd04bb3 | 2014-01-07 17:14:05 +0000 | [diff] [blame] | 7 | |
Sebastian Plamauer | 3526716 | 2014-05-04 12:53:01 +0200 | [diff] [blame^] | 8 | log = open('1:/log.csv', 'w') # open file to write data - 1:/ ist the SD-card, 0:/ the internal memory |
| 9 | blue.on() # turn on blue LED |
Damien George | fd04bb3 | 2014-01-07 17:14:05 +0000 | [diff] [blame] | 10 | |
Sebastian Plamauer | 3526716 | 2014-05-04 12:53:01 +0200 | [diff] [blame^] | 11 | for 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 George | fd04bb3 | 2014-01-07 17:14:05 +0000 | [diff] [blame] | 15 | |
Sebastian Plamauer | 3526716 | 2014-05-04 12:53:01 +0200 | [diff] [blame^] | 16 | log.close() # close file |
| 17 | blue.off() # turn off LED |