{"id":133,"date":"2022-09-01T20:08:20","date_gmt":"2022-09-01T19:08:20","guid":{"rendered":"https:\/\/stormappsonline.co.uk\/blog\/?p=133"},"modified":"2022-09-04T16:21:47","modified_gmt":"2022-09-04T15:21:47","slug":"microbit-basic-data-logging-3","status":"publish","type":"post","link":"https:\/\/stormappsonline.co.uk\/blog\/2022\/09\/01\/microbit-basic-data-logging-3\/","title":{"rendered":"micro:bit basic data logging 3"},"content":{"rendered":"\n<p><br>This program runs on a laptop and reads the files that have been stored on the micro:bit&#8217;s file system using the MicroFs system described in the <a href=\"https:\/\/stormappsonline.co.uk\/blog\/2022\/09\/01\/reading-microbit-files-from-a-laptop\/\">previous blog post<\/a>. <br><br>This is the third in a series of programs about using the micro:bit&#8217;s file system.<br>Program 1: <a href=\"https:\/\/stormappsonline.co.uk\/blog\/2022\/08\/21\/microbit-basic-data-logging-1\/\">Basic writing, and reading of text to a file<\/a><br>Program 2: <a href=\"http:\/\/stormappsonline.co.uk\/blog\/2022\/08\/21\/microbit-basic-data-logging-2\/\">Slightly more advanced version of program 1<\/a><br><br>I have used a Windows PC and Python, and I think it will also work on Linux and Apple Mac computers.<br><br>Note there seems to be a limitation with MicroFs (or my knowledge), in that the contents of files on the micro:bit can not be read directly \u2013 instead, they need to be copied onto a laptop first before being read<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"508\" height=\"374\" src=\"https:\/\/stormappsonline.co.uk\/blog\/wp-content\/uploads\/2022\/09\/log_program_3.jpg\" alt=\"\" class=\"wp-image-138\" srcset=\"https:\/\/stormappsonline.co.uk\/blog\/wp-content\/uploads\/2022\/09\/log_program_3.jpg 508w, https:\/\/stormappsonline.co.uk\/blog\/wp-content\/uploads\/2022\/09\/log_program_3-300x221.jpg 300w\" sizes=\"(max-width: 508px) 100vw, 508px\" \/><figcaption>Program to read files on a micro:bit from a laptop<\/figcaption><\/figure>\n\n\n\n<p><strong>Line 1<\/strong> This imports the MicroFs file system, which you need to have installed on your laptop. The documentation to this is <a href=\"https:\/\/microfs.readthedocs.io\/en\/latest\/\">here<\/a> and I have written about it <a href=\"https:\/\/stormappsonline.co.uk\/blog\/2022\/09\/01\/reading-microbit-files-from-a-laptop\/\">here<\/a><br><strong>Line 2<\/strong> imports os \u2013 used to delete the file afterwards<\/p>\n\n\n\n<p><strong>Lines 4 to 12<\/strong> the readData() function to read data (reused from <a href=\"http:\/\/stormappsonline.co.uk\/blog\/2022\/08\/21\/microbit-basic-data-logging-2\/\">Program 2<\/a>).<\/p>\n\n\n\n<p><strong>Line 14<\/strong> Gets the names of the files on the micro:bit (this is the same as the command &#8216;ufs ls&#8217;) and returns the names in a list<br><strong>Line 15<\/strong> Shows the names of the files that were found<\/p>\n\n\n\n<p><strong>Line 16 to 21<\/strong> Loop over each file (in the list) and print out the contents of the file<br><strong>Line 18<\/strong> copies the file from the micro:bit&#8217;s file system to the current directory (it seems a limitation of MicroFs that you can not access the files directly)<br><strong>Line 21<\/strong> call readData() to open the file, read each line of the file, and close the file afterwards<br><strong>Line 22<\/strong> delete the file from the local folder, to tidy up the local folder <br><br><em>This code has been created to be freely downloaded, adapted and used. If a school could mention our software for primary\/elementary students we would be very grateful <a href=\"https:\/\/www.stormeducational.co.uk\/\">stormeducational.co.uk<\/a> (with free online demos at\u00a0<a href=\"https:\/\/www.stormedapps.co.uk\/\"><em>stormedapps.co.uk<\/em><\/a>).<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This program runs on a laptop and reads the files that have been stored on the micro:bit&#8217;s file system using the MicroFs system described in the previous blog post. This is the third in a series of programs about using the micro:bit&#8217;s file system.Program 1: Basic writing, and reading of text to a fileProgram 2:&hellip; <a class=\"more-link\" href=\"https:\/\/stormappsonline.co.uk\/blog\/2022\/09\/01\/microbit-basic-data-logging-3\/\">Continue reading <span class=\"screen-reader-text\">micro:bit basic data logging 3<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[20,12,21],"tags":[15,13],"_links":{"self":[{"href":"https:\/\/stormappsonline.co.uk\/blog\/wp-json\/wp\/v2\/posts\/133"}],"collection":[{"href":"https:\/\/stormappsonline.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stormappsonline.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stormappsonline.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/stormappsonline.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=133"}],"version-history":[{"count":6,"href":"https:\/\/stormappsonline.co.uk\/blog\/wp-json\/wp\/v2\/posts\/133\/revisions"}],"predecessor-version":[{"id":152,"href":"https:\/\/stormappsonline.co.uk\/blog\/wp-json\/wp\/v2\/posts\/133\/revisions\/152"}],"wp:attachment":[{"href":"https:\/\/stormappsonline.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stormappsonline.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stormappsonline.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}