Reading micro:bit files from a laptop

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 is because the files are stored in the microcontroller flash, which is not accessible through the USB mass storage interface (thanks to this stackoverflow contribution from carlosperate)

The way to read the files is to use a module called “MicroFs” which describes itself as “a simple command line tool and module for interacting with the limited file system provided by MicroPython on the BBC micro:bit ”
https://microfs.readthedocs.io/en/latest/

That page was a useful guide, but it took me a few tries to get it right – mainly getting my head around what MicroFs can and can not do.

pip install microfs
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’s too much detail)

Once microfs is installed, you can use the command line (press the Windows Start key > Windows System > Command Line), to list the names of the files on the device using
ufs ls
You can also copy files from the micro:bit to the current folder on a laptop using
ufs get storm.csv
(this copies a file named storm.csv)

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)

That’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 here

I am still learning python, and creating that program taught three things:
1) I am using notepad++ and running from the command line. The the Mu editor (https://codewith.mu), is recommended as a integrated GUI that also works with the micro:bit
2) In that program,
mFiles = ls()
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 ‘list’. I know about arrays of course, but there are some subtle differences about lists. This page: https://www.programiz.com/python-programming/list seemed to give a comprehensive guide, which I must read, not least as I don’t know what a tuple is at this stage!
3. One limitation of MicroFs is that files can not be read directly – they need to be copied onto the laptop first

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 stormeducational.co.uk (with free online demos at stormedapps.co.uk

Leave a comment