Micro:Bit and SPI display

I want to explore the full potential of the BBC Micro:bits my school has.

Making rock-paper-scissors games and the like is all well and good, and the students love it (for the most part), but it always feels a little bit gimmicky.  But when students really get engaged and suggest ideas for them (e.g. games, compass display), it all gets a little bit cramped and feels like it could kinda work, but not really.

Then I found out that all the tiny strips on the edge are actually GPIO pins, not just the fat 0, 1 and 2 ones.  Since then, I've wanted to explore what I can do with it.

Hence, over the last few days I have been trying to get the microbit to control a TFT display.

I first went for this 2.4" display with a touchscreen.  The SPI interface is just for the microSD, not for the screen but I didn't think that would be a problem because the micro:bit has so many pins.  After much frustration, I discovered that there are many of the pins you can't reliably use externally.  I used a flashing-LED program to test which pins I could turn on and off.  Even with the micro:bit's own LED display switched off, I could only get 9 pins to work (0-4, 12, and 14-16), and that's not enough for the 8 data lines plus the control lines. So.....meh.

So I bought this SPI one instead.  I went straight for trying to draw pixels and was quickly overwhelmed by the sheer number of things that could be wrong.  After a day or so of trying countless guess-combinations with no success, I figured I needed to find something - anything - that could work with the screen.

The AZ-Delivery ebook goes through how to use the Arduino IDE and TFT library, so I naively tried to compile it for the micro:bit using the instructions here.  No dice.  There were missing includes which looked like some kind of Arduino hardware abstraction.

However, I had an old Arduino Nano kicking around, so I wired the screen up to that and the TFT example ran straight away!

Thankfully, that gave me a list of initialisation commands and example drawing commands I could then translate into micropython for the micro:bit, and I got a green square drawn!  One green square...and it only took me 4 days' work! :/

Anyhow, here is the micropython which did the trick (with some debug junk scrolling across the built-in LED grid)

UPDATE: I cleaned up the code a bit (my aim was to make it a library, but mu-editor only flashes across a single .py file so it's all in one), and added some stuff to draw random colour rectangles in a reasonable time (but not quick :/)

New code is here.

Here's a video of it in action:




Comments

Popular posts from this blog

DCS World with TrackIR under Ubuntu

Cardboard Mock-up of USB Joystick