Code your own bedroom door sign: python on a BBC micro:bit for beginners

Code your own bedroom door sign: python on a BBC micro:bit for beginners

This is a BBC micro:bit for beginners tutorial that shows you how to write some python code to turn a micro:bit into a sign you can stick to your bedroom door.

Python is a programming language that’s designed to let you write as little code as possible to make as much work as possible. Writing code on in python on a micro:bit is a great way to get your head around the essentials in python and hopefully have a lot of fun along the way too.

The micro:bit has an LED screen with just 5×5 pixels (dots). This isn’t much compared to the 2880×1800 pixels you might be used to if you’ve got a Macbook Pro but it’s big enough to display simple pictures and text one letter at a time.

Try it with code
Display code on a BBC micro:bit

We’re going to be using the create.withcode.uk microbit simulator to write and test our code. To run the code you can press Ctrl + Enter or click on the run button in the bottom right of the code window.

 

If you want to test your code on an actual micro:bit, run the code in the simulator first then click on the Download Hex button. This’ll download a my_code.hex file that will run on your micro:bit when you drag it and drop it as though you were copying a file to USB memory stick.

 

 

There are two ways of displaying text to the micro:bit screen: display.scroll() and display.show(). What’s the difference? Which do you prefer?

Let’s go through each of the lines in turn:

import microbit
microbit.display.scroll("Hello")
microbit.display.show("World")

Line 1 tells python to import the microbit module. That means that python loads some extra code which tells it how to control a microbit. Lines like this, where you’re importing a module, usually go at the top of your code.

import microbit
microbit.display.scroll("Hello")
microbit.display.show("World")

Inside the microbit module there’s another module called display. Inside display is a procedure called scroll. The round brackets after scroll tell python to call (run) that procedure.

 

string
A “string” of characters

Notice the text in the brackets is surrounded by quotation marks: we call this a string because it joins the characters together as though they were threaded on a string like a washing line.

The scroll procedure scrolls the text from right to left, moving it one pixel at a time.

 

 

import microbit
microbit.display.scroll("Hello")
microbit.display.show("World")

Line 3 is similar to line 2 but instead of scrolling the text pixel by pixel, we show one character at at time.

You might notice in some tutorials that instead of  import microbit you see  from microbit import *

Both of these tell python to load code from the microbit module, but the second means that you don’t have to write  microbit. every time you use the microbit module:

from microbit import *
display.scroll("Hello")
display.show("World")
import microbit
microbit.display.scroll("Hello")
microbit.display.show("World")

Both of the two programs above will do the same thing when they run. The top one is easier to write but some people prefer the bottom one to save confusion later in the development process.

What attracts you to computing

Making computing accessible for all (2/6): Challenging computing lessons

This post is the second of six in a series with ideas and resources on how to make computing lessons engaging and demanding for as many students as possible. Click here for the original post.

Challenging
Ideas and resources for challenging computing lessons

There’s no point making lessons fun just for the sake of it. Ok, maybe it’s acceptable in the odd lesson just before the Christmas holidays, but I’d rather my students left my lessons feeling like they’ve achieved something than leaving just feeling like they’ve enjoyed themselves.

Fun isn’t a dirty word, but it’s not an end in itself: it’s a natural bi-product of lessons with just the right amount of challenge.

Too much challenge and everyone leaves frustrated and demotivated. Too little and boredom is endemic.

Students don’t all have the same capability, pace, independence and resilience, which means setting the level of challenge is almost impossible to get right for everyone. But lessons / projects with a low floor and high ceiling – that start easy but don’t shy away from difficulty – mean that everyone is going to be suitably challenged at some point along the way.

Ideas:

  • Use templates for code / games rather than expecting students to always start with a blank canvas. Unfinished or deliberately broken code is great as it gives students a starting point to work from.

e.g. “There are 3 syntax errors in this code and one logical error for you to debug”

  • Get used to setting short challenges and puzzles – often at the start of the lesson. Start with something easy and get more difficult as your classes get used to problem solving

e.g. “Today’s learning objectives have been encoded with a caesar cipher: decode them and tell me the key: Avkhf dl’yl nvpun av slhyu ovd av bzl spzaz pu wfaovu”

  • Allow your students to choose different difficulty challenges for lesson / homework. Make sure the complexity of the work increases rather than just the quantity for the most able students.

e.g. “Beginners should make an animation on the micro:bit using built-in images like Image.HAPPY and Image.SAD. Anyone up for a challenge should define your own images to use in your animation

Key questions:

Who’s leaving my lesson feeling like a failure? Who’s leaving my lesson without having learnt anything new?

Example activity: Micro:bit animation

The code above simulates a BBC micro:bit to display an animation consisting of two images. There are three challenges of varying difficulty for students to experiment with lists to create their own animations.

 

Research and further reading

This paper looks at the challenges facing computing teachers, particularly when it comes to differentiation: stretching the top end whilst not leaving other behind.
Recommendations include:
-Unplugged activities
-Focusing on computational thinking concepts rather than syntax
-Scaffolding programming activities rather than starting from an empty file

Sentance, S. & Csizmadia, A. Educ Inf Technol (2017)
micro:bit Python Simulator

micro:bit Python Simulator

I’ve been following the hype around the BBC micro:bits since they were announced but it’s been notoriously difficult to get my hands on one. My Y7s have been waiting for their class set to arrive since they were promised in September and although I know there are plenty of schools out there who’ve received them, I’d pretty much given up hope this academic year.

Then, my lovely science technician told me she’d got some spare “computer gadget things” that came bundled in a in a kit that she wasn’t going to be needing and she wondered if some of my students would be interested.

Oh yes.

So, for the last week, I’ve set all sorts of different aged / ability students loose with the “computer gadget things” to see if they live up to the hype.

And they do.