summaryrefslogtreecommitdiffstatshomepage
path: root/examples/SDdatalogger
diff options
context:
space:
mode:
authorSebastian Plamauer <oepse@gmail.com>2014-05-04 19:07:17 +0200
committerSebastian Plamauer <oepse@gmail.com>2014-05-04 19:07:17 +0200
commit96e97ed2ceeda9de9ed0dab69a7ee4f701a42a40 (patch)
tree723354723af7bb9bdb5bbab59fc7da2371f1a809 /examples/SDdatalogger
parent5fc400ccdb17a7208fbf2d3ea93985d922b1a35d (diff)
downloadmicropython-96e97ed2ceeda9de9ed0dab69a7ee4f701a42a40.tar.gz
micropython-96e97ed2ceeda9de9ed0dab69a7ee4f701a42a40.zip
created SDdatalogger example
Diffstat (limited to 'examples/SDdatalogger')
-rw-r--r--examples/SDdatalogger/README.md4
-rw-r--r--examples/SDdatalogger/README.md~4
-rw-r--r--examples/SDdatalogger/boot.py24
-rw-r--r--examples/SDdatalogger/cardreader.py2
-rw-r--r--examples/SDdatalogger/datalogger.py29
5 files changed, 63 insertions, 0 deletions
diff --git a/examples/SDdatalogger/README.md b/examples/SDdatalogger/README.md
new file mode 100644
index 0000000000..24e69c87e0
--- /dev/null
+++ b/examples/SDdatalogger/README.md
@@ -0,0 +1,4 @@
+This is a SDdatalogger, to log data from the accelerometer to the SD-card. It also functions as card reader, so you can easily get the data on your PC.
+
+To run, put the boot.py, cardreader.py and datalogger.py files on either the flash or the SD-card of your pyboard.
+Upon reset, the datalogger script is run and logs the data. If you press the user button after reset and hold it until the orange LED goes out, you enter the cardreader mode and the filesystem is mounted to your PC.
diff --git a/examples/SDdatalogger/README.md~ b/examples/SDdatalogger/README.md~
new file mode 100644
index 0000000000..24e69c87e0
--- /dev/null
+++ b/examples/SDdatalogger/README.md~
@@ -0,0 +1,4 @@
+This is a SDdatalogger, to log data from the accelerometer to the SD-card. It also functions as card reader, so you can easily get the data on your PC.
+
+To run, put the boot.py, cardreader.py and datalogger.py files on either the flash or the SD-card of your pyboard.
+Upon reset, the datalogger script is run and logs the data. If you press the user button after reset and hold it until the orange LED goes out, you enter the cardreader mode and the filesystem is mounted to your PC.
diff --git a/examples/SDdatalogger/boot.py b/examples/SDdatalogger/boot.py
new file mode 100644
index 0000000000..f5006df932
--- /dev/null
+++ b/examples/SDdatalogger/boot.py
@@ -0,0 +1,24 @@
+# boot.py -- runs on boot-up
+# Let's you choose which script to run.
+# > To run 'datalogger.py':
+# * press reset and do nothing else
+# > To run 'cardreader.py':
+# * press reset
+# * press user switch and hold until orange LED goes out
+
+import pyb
+
+pyb.LED(3).on()
+pyb.delay(2000)
+pyb.LED(4).on()
+pyb.LED(3).off()
+switch = pyb.Switch() # check if switch was pressed decision phase
+
+if switch():
+ pyb.usb_mode('CDC+MSC')
+ pyb.main('cardreader.py') # if switch was pressed, run this
+else:
+ pyb.usb_mode('CDC+HID')
+ pyb.main('datalogger.py') # if switch wasn't pressed, run this
+
+pyb.LED(4).off()
diff --git a/examples/SDdatalogger/cardreader.py b/examples/SDdatalogger/cardreader.py
new file mode 100644
index 0000000000..98d7a37925
--- /dev/null
+++ b/examples/SDdatalogger/cardreader.py
@@ -0,0 +1,2 @@
+# cardread.py
+# This is called when the user enters cardreader mode. It does nothing.
diff --git a/examples/SDdatalogger/datalogger.py b/examples/SDdatalogger/datalogger.py
new file mode 100644
index 0000000000..dcac0091e8
--- /dev/null
+++ b/examples/SDdatalogger/datalogger.py
@@ -0,0 +1,29 @@
+# datalogger.py
+# Logs the data from the acceleromter to a file on the SD-card
+
+import pyb
+
+# creating objects
+accel = pyb.Accel()
+blue = pyb.LED(4)
+switch = pyb.Switch()
+
+# loop
+while True:
+
+ # start if switch is pressed
+ if switch():
+ pyb.delay(200) # delay avoids detection of multiple presses
+ blue.on() # blue LED indicates file open
+ log = open('1:/log.csv', 'w') # open file on SD (SD: '1:/', flash: '0/)
+
+ # until switch is pressed again
+ while not switch():
+ t = pyb.millis() # get time
+ x, y, z = accel.filtered_xyz() # get acceleration data
+ log.write('{},{},{},{}\n'.format(t,x,y,z)) # write data to file
+
+ # end after switch is pressed again
+ log.close() # close file
+ blue.off() # blue LED indicates file closed
+ pyb.delay(200) # delay avoids detection of multiple presses