Friday, March 25, 2016

Making the BBC micro:bit display the BBC Micro owl logo

Back in the 1980s I had a BBC Micro Model B. I still have that machine and repaired its power supply not long ago. The logo of the BBC Micro was a dot matrix owl:

Well, I was lucky enough to be lent (for one evening!) the most recent incarnation of the BBC's attempt to teach Britain's children to code: the BBC micro:bit. It's a lovely little machine and I hope many children have fun programming it. Unfortunately, I suffer from the Demon Machine problem: show me a computer and I have to make it do something.

Programming the device is really simple. There are multiple options and an online editor for each language. When you are ready to program the micro:bit it's trivial because the editor downloads a .hex file that you drag and drop onto the device (it appears mounted as a volume).

I chose to use MicroPython and write a small program that displays the (old) BBC Micro logo (the owl above) on the micro:bit's 5x5 LEDs. Since the owl is much larger than 5x5 pixels I've used the accelerometer to allow the user to scroll around the owl by tilting the micro:bit.

The code is here on Github. But to get a sense of how easy it is, here's the main loop that does all the work.

while True:
    lastx = ox
    lasty = oy
    xa = accelerometer.get_x()
    if abs(xa) > sensitivity:
        if xa > 0 and ox > 0:
            ox -= 1
        elif xa < 0 and ox < w - 5:
            ox += 1

    ya = accelerometer.get_y()
    if abs(ya) > sensitivity:
        if ya > 0 and oy > 0:
            oy -= 1
        elif ya < 0 and oy < h - 5:
            oy += 1

    if lastx != ox or lasty != oy:

The paint() function draws a 5x5 section of the owl (which is stored in an array) starting from position (ox, oy).  The height and width of the owl are stored in h and w.

def paint():
    for x in range(0, 5):
        for y in range(0, 5):
            display.set_pixel(x, y, 9 * owl[y+oy][x+ox])

And here's what that looks like on the micro:bit itself:

Hmm. I wonder if the micro:bit could be used as a game controller for Elite?

Thursday, March 10, 2016

Finding free images for commercial use

From time to time (especially when writing for the CloudFlare blog) I've needed to find an image that will help illustrate a piece of web writing. As I want to only use images to which I have a license and don't want to spend money the answer is... Creative Commons. And my first port of call is flickr which has nice options for searching for content by license.

Typically when using an image from flickr I will add a caption to the image with the license type, a direct link to the image page on flickr and a direct link to the person who took it.

For example, here are some Creative Commons cupcakes from flickr with an appropriate line of information about the image giving the license, image link and photographer.

Making an old USB printer support Apple AirPrint using a Raspberry Pi

There are longer tutorials on how to connect a USB printer to a Raspberry Pi and make it accessible via AirPrint but here's the minimal ...