10 June 2016

BBC Micro:bit - Downloading accelerometer data to a linux PC

If like me, you've finally managed to get hold of a BBC Micro:bit and want to try out the accelerometer data-logging function (as used in the Bloodhound competition), you might find it more difficult if you're using linux.

Well if you're using PC Linux OS, we can fix this.

First of all, use the Micro:bit website to program the device. I struggled to find the data-logging parts so I recommend you actually use the tutorial for this part.

Now for the hurdle. The tutorials I've seen for downloading the data suggest you use an old Windows-only terminal emulator program called Tera-Term. This is quite unique as it lets you copy the data in table format. I couldn't get it to work on linux (using wine) and found the micro:bit serial instructions for using linux to be very poor (and untested). My version presented here uses current software and HAS BEEN TESTED (at least on PC Linux OS 32-bit mate edition running on a Samsung NC10).

Was very useful for creating this fix

Go to synaptic package manager and install screen (terminal emulator)

Start a regular terminal
List connected ports using

dmesg | grep tty

should show... ttyACM0 : USB ACM device (this means the microbit is attached via port /dev/ttyACM0)

To connect to the microbit using screen, we therefore use the command:
screen /dev/ttyACM0 115200

which will most probably result in an error like this one...
error /home/*username*/tmp must have mode 700

To fix this:
mkdir -p /home/*username*/.screen
chmod 700 /home/*username*/.screen
cd /usr/bin
su root (enter password when prompted)
chmod u+s screen
chmod 700 /home/*username*/tmp
exit (superuser mode)

I then tried the screen command again and pressing the right button on the micro:bit actually downloaded the data to the terminal. From there you can use the edit -> select all and edit -> copy functions to grab the data for pasting into an empty text file or office document. I also found it useful to go back to the micro:bit code and add some additional images before and after the micro:bit -> export command just so you can tell when it is attempting to dowload.

I would also like to point out that I am not a linux expert and this fix was performed on a laptop which is not usually connected to the internet. Any use of this fix is at your own risk so go search that chmod command and try to figure out what you're actually changing.

The good thing about the micro:bit site is you can download your source code and also the (.hex) executables which are simply dragged-and-dropped onto the micro:bit. So once you have these, there's no need to go back to the code editor unless you want to change things. Internet access is only needed for installing the screen package which is why I'm not too worried about the permissions changes on my laptop. Please consult a linux expert if protecting your system is a higher priority.