Micropython on a Microbit using Mu

Today I have attended a CAS workshop as an computing professional at Lancaster University.

The object of the session was to network with teachers and have a play with Micropython on the Microbit. We worked in groups and finished the evening with a ‘show and tell’.

The reference manual for micropython on a microbit is here. While this is essential reading, I decided it would make things easier with a summary on a single sheet of paper next to me. I created a quick reference sheet.

There are two ways to use Python on a microbit – the online editor or the Mu editor. We chose to use Mu because it is more responsive and integrates better with the microbit.

Here is what we came up with at the end of the session:

cas

It is an active-low RGB LED wired up to the microbit using crocodile clips. You can change the colour by pressing different buttons on the microbit or by shaking the microbit.

Timelapse video on a Raspberry Pi

Here is an experiment I did on my Dad’s Raspberry Pi after reading an article in the MagPi.

To take a timelapse video:

$ mkdir pics
$ raspistill -w 1920 -h 1080 -t 120000 -tl 5000 -o pics/test%04d.jpg

where:

-t is the total time to run in milliseconds
-tl is the time interval in milliseconds between each picture

To record 10 hour timelapse starting at 7am tomorrow (pic every 60 secs):

$ at 7:00 AM tomorrow
raspistill -w 1920 -h 1080 -t 36000000 -tl 60000 -o pics/test%04d.jpg
Ctrl-D

To convert the individual pictures to a video:

$ cd pics
$ avconv -framerate 10 -i test%04d.jpg -crf 4 -b:v 10M video.webm

Here is the result (link)

Disable screen blanking in Raspbian LXDE

At the Raspberry Pi birthday bash this weekend, I had a Pi3 running an OpenOffice Impress presentation continuously in a loop all day on the bar. I had a problem with the screen blanking after several minutes. I fixed this using these commands in a terminal:

$ xset s noblank
$ xset s off
$ xset -dpms

(I discovered this by reading this)

If you want a more permanent solution then this may help you: (link)

Installing the latest Python from source

Here is a shell script to install the lastest version of Python under Debian / Raspbian (3.7.4 and Stretch/Buster at the time of writing):

#!/bin/sh
RELEASE=3.7.4

# install dependencies
sudo apt-get install libbz2-dev liblzma-dev libsqlite3-dev libncurses5-dev libgdbm-dev zlib1g-dev libreadline-dev libssl-dev tk-dev uuid-dev libffi-dev

# The following line is required for Buster but will fail harmlessly under Stretch
sudo apt-get install libgdbm-compat-dev

# download and build Python
mkdir ~/python3
cd ~/python3
wget https://www.python.org/ftp/python/$RELEASE/Python-$RELEASE.tar.xz
tar xvf Python-$RELEASE.tar.xz
cd Python-$RELEASE
./configure --enable-optimizations --enable-shared
make
sudo make altinstall
sudo ldconfig
sudo rm -rf ~/python3/Python-$RELEASE
cd ~

Changelog

  • Updated to work with both Stretch and Buster
  • Updated version of Python and updated dependencies
  • ‘make altinstall’ instead of ‘make install’ – note that doing this no longer sets the default python3 to the copy you are building – you have to use python3.x instead.  I tend to use virtual environments these days to have better control over the versions in use.
  • Added –enable-optimizations to the configure step.  This makes builds much slower but you can remove this if you are impatient.
  • Added —enable-shared to the configure step.  This was needed for mod_wsgi builds and is a default option in Debian package builds anyway.