{"id":130,"date":"2022-09-01T20:10:07","date_gmt":"2022-09-01T19:10:07","guid":{"rendered":"https:\/\/stormappsonline.co.uk\/blog\/?p=130"},"modified":"2022-09-04T16:23:27","modified_gmt":"2022-09-04T15:23:27","slug":"reading-microbit-files-from-a-laptop","status":"publish","type":"post","link":"https:\/\/stormappsonline.co.uk\/blog\/2022\/09\/01\/reading-microbit-files-from-a-laptop\/","title":{"rendered":"Reading micro:bit files from a laptop"},"content":{"rendered":"\n<p>Following on from the program to log data on the micro:bit <a href=\"http:\/\/stormappsonline.co.uk\/blog\/2022\/08\/21\/microbit-basic-data-logging-2\/\">here<\/a>, I have been exploring how to read that data from a laptop.<br><br>Initially, I looked to see if I could access files on the micro:bit, through Windows Explorer. The micro:bit shows as a USB device, but clicking on it shows no files. This is because the files are stored in the microcontroller flash, which is not accessible through the USB mass storage interface (thanks to <a href=\"https:\/\/stackoverflow.com\/questions\/43368085\/how-to-get-files-written-by-the-microbit-to-the-pc\">this stackoverflow<\/a> contribution from carlosperate)<br><br>The way to read the files is to use a module called \u201cMicroFs\u201d which describes itself as \u201ca simple command line tool and module for interacting with the limited file system provided by MicroPython on the BBC micro:bit \u201d<br><a href=\"https:\/\/microfs.readthedocs.io\/en\/latest\/\">https:\/\/microfs.readthedocs.io\/en\/latest\/<\/a><br><br>That page was a useful guide, but it took me a few tries to get it right \u2013 mainly getting my head around what MicroFs can and can not do.<br><br><code>pip install microfs<\/code><br>installs MicroFs onto the laptop (I am not familiar enough to know whether it installs it within python, or just within the laptop, but that&#8217;s too much detail)<br><br>Once microfs is installed, you can use the command line (press the Windows Start key &gt; Windows System &gt; Command Line), to list the names of the files on the device using<br><code>ufs ls<\/code><br>You can also copy files from the micro:bit to the current folder on a laptop using<br><code>ufs get storm.csv<\/code><br>(this copies a file named storm.csv)<br><br>ufs has other commands such as put (to copy a file onto the micro:bit) and rm (to delete a file on the micro:bit)<br><br>That&#8217;s great, but I wanted to be able to read those files from within a program, and the next blog post describes a program to do just that is <a href=\"https:\/\/stormappsonline.co.uk\/blog\/2022\/09\/01\/microbit-basic-data-logging-3\/\">here<\/a><br><br>I am still learning python, and creating that program taught three things:<br>1) I am using notepad++ and running from the command line. The the Mu editor (<a href=\"https:\/\/codewith.mu\/\"><u>https:\/\/codewith.mu<\/u><\/a>), is recommended as a integrated GUI that also works with the micro:bit<br>2) In that program,<br>mFiles = ls()<br>returns the names of the files on the micro:bit (this is the same as ufs ls), and these are in the form of a &#8216;list&#8217;. I know about arrays of course, but there are some subtle differences about lists. This page: <a href=\"https:\/\/www.programiz.com\/python-programming\/list\">https:\/\/www.programiz.com\/python-programming\/list<\/a> seemed to give a comprehensive guide, which I must read, not least as I don&#8217;t know what a tuple is at this stage!<br>3. One limitation of MicroFs is that files can not be read directly \u2013 they need to be copied onto the laptop first<\/p>\n\n\n\n<p><em>This post has been created to help anyone using the micro:bit. 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>Following on from the program to log data on the micro:bit here, I have been exploring how to read that data from a laptop. Initially, I looked to see if I could access files on the micro:bit, through Windows Explorer. The micro:bit shows as a USB device, but clicking on it shows no files. This&hellip; <a class=\"more-link\" href=\"https:\/\/stormappsonline.co.uk\/blog\/2022\/09\/01\/reading-microbit-files-from-a-laptop\/\">Continue reading <span class=\"screen-reader-text\">Reading micro:bit files from a laptop<\/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\/130"}],"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=130"}],"version-history":[{"count":9,"href":"https:\/\/stormappsonline.co.uk\/blog\/wp-json\/wp\/v2\/posts\/130\/revisions"}],"predecessor-version":[{"id":154,"href":"https:\/\/stormappsonline.co.uk\/blog\/wp-json\/wp\/v2\/posts\/130\/revisions\/154"}],"wp:attachment":[{"href":"https:\/\/stormappsonline.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stormappsonline.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stormappsonline.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}