Tuesday, 13 September 2016

How Big Can My Python Script Be?

We all know that the micro:bit has limits. The specs (available either on WikiPedia or the ARMmbed site) show that the memory limits are:
  • 16kB RAM
  • 256kB Flash 
That sounds like a decent amount of memory - it's not in the gigabytes range of even your most modest modern PC or Mac, but for an embedded processor a total of 282kB is not too bad. So surely we can load massive Python scripts onto our micro:bits, right? Wrong. The hard limit for a Python script is just a snip under 8k. Try and copy a script file larger than that and it will fail. Why is that?


Tuesday, 6 September 2016

What are .hex files?

You must have come across .hex files by now. Every time you compile a program on the micro:bit website you end up with one. You copy it to your device and the program runs. Every time we post a project on this blog we include a .hex file. Every time you hit the Flash button in Mu it silently and secretly creates a hex files and automatically copies it to your micro:bit. But what are .hex files, how do they work and why should we care about them?

Thursday, 1 September 2016

Tilt Maze

Son and I recently went off for a boy's weekend at the Grandparents. We knew that we'd be stuck on trains for a good few hours so we decided to take along the micro:bit so that we could embark upon our own Train Jam. Son chose to work on a maze game where you have to navigate your way to the exit. He also wanted keys and doors to make it more of a challenge.


We thought it might be tough to make this a fun game on such a limited device so we decided to keep things simple. With only 25 red LEDs it was tough to think how we could show the various elements of the maze. We decided that:
  1. The player would be a very bright pixel and always in the middle of the screen. The rest of the maze would scroll around you.
  2. Walls would be dim pixels.
  3. Doors would be slowly flashing pixels.
  4. Keys would be rapidly flashing pixels.
  5. The exit would be flashing in some cool way that made it look enticing.

Tuesday, 16 August 2016

Micro Alarm

This is our first hardware project - an alarm. It's (very) inspired by Tech Will Save Us' Micro Guardian. The project is pretty simple, but it's a fun one to make. We set up the micro:bit with a connection between pins 0 and 3v using crocodile clips attached to two strips of copper tape. The copper tape goes across the seal of a jar, making a connection when it's closed and breaking it when it's open. We detect this in the code and, when the connection is broken, we output a pulse to pin 1 which has a buzzer connected to it (the other connection of the buzzer goes to GND). We also used some of MicroPython's built-in images to show the micro:bit asleep face when the connection is closed, and alternating between angry face and sword (Son was insistent that the micro:bit show you that it is both angry and ready to fight you) when open.


Monday, 8 August 2016

Snake

Here's our second game, a version of the classic snake game. A bit of a challenge to fit this onto a 5x5 display with only two buttons but we think we've managed it. Drive the snake around the screen using the A and B buttons to turn left and right. The aim is to eat the food (the flashing pixel) but your snake gets longer each time it eats something. Eventually your snake tail will be so long that you'll crash into it and it's game over!


Friday, 5 August 2016

Non-Flappy Bird

Here we present our first micro:bit game - Non-Flappy Bird. We wanted to write a version of Flappy Bird, but on a 5x5 display there didn't feel like there was enough room for flapping. So instead of flapping, we made the A and B buttons move you left and right. Rows of lit pixels drop down the screen towards you and you'll need to dodge them. The game gets faster the more barriers you avoid.


Thursday, 4 August 2016

Custom Display Clear

MicroPython has a simple built-in command to clear the display: display.clear(). The results are equally simple - it instantly turns off every LED on the display. We don't need to be limited to such a simplistic way of clearing the screen though, we can write our own exciting fades, wipes and dissolves.


Wednesday, 3 August 2016

Built-in Images

The micro:bit's MicroPython has a big list of built-in images - 63 to be precise. But what do they all look like? Well, here's a handy chart! And as a bonus, we've also included a test program that cycles through all the images on the micro:bit's display.


Tuesday, 2 August 2016

Electronic Die

So here's our first program - an electronic die. OK, so technically this is the second program - we went from the ultra-simplicity of "Hello, World" straight to here. The program's operation is pretty simple - every time you shake the micro:bit you get a new random number displayed on the screen in the image of a traditional six side die. We found that the shake gesture was pretty hit-and-miss so we made it that you can also press the A button to roll. We expected the gesture recognition to be better, so maybe we're doing it wrong? Suggestions welcome!

Friday, 29 July 2016

Using MicroPython on the micro:bit

MicroPython on the micro:bit is a great language. It may be a cut down version of Python 3 - missing many of the libraries that ship with the full-sized version of Python and some that are included are cut down somewhat - but it's a prefect match to the micro:bit. The only real problems that I've found so far revolve around using the BBC's online editor. It's good for what it is (getting you started) but three big limitations hit quite quickly:
  • Flashing programs to the micro:bit is awkward. First you download the hex file from your browser, find where the browser stored it, open up the micro:bit drive, then you drag it to the micro:bit drive. Far too many steps.
  • Program errors are almost comically hard to trace as the micro:bit slowly scrolls the error messages across its tiny display.
  • Python programs are best developed in combination with access to the command line (which Python calls a REPL). This allows you to try out commands and snippets of code without having to write a test program. If you've ever used BASIC on an old computer - that essentially what the REPL gives you. The default micro:bit IDE does not give you any way to access the REPL.
Luckily, there is a solution that solves all of these problems in a snip: Mu.

Wednesday, 27 July 2016

Arrival

By mid-July it looked like the micro:bit should be available to buy, but every online shop was still showing them as out of stock. After a bit of a hunt, I found that Pimoroni showed them as available to order. Being of the slightly suspicious type I sent them a message and quite quickly the reply came back "yes, we actually got them in stock". Brilliant! I hurriedly placed the order.

A couple of days later a package arrived at our house. Nice work Pimoroni! Son saw the package first (what with me being at work and him being at home on school holiday) and guessed that there was a micro:bit inside.


Monday, 25 July 2016

Begin at the Beginning


I can't remember when we first heard about the BBC miro:bit, but it filled us both with excitement. I'm a software engineer who also dabbles in electronics, and Son is a school kid who likes to program in Scratch and who is also becoming interested in electronics. I wanted an to find an interesting platform that we could both to learn together. My wish list was something like: