video

Lesson video

In progress...

Loading...

Hi, I'm Allen, your computer teacher for this unit, and it's one of my absolute favourites, it's physical computing.

And we're going to be using a BBC micro:bit.

You will need one of these, for this unit.

And you'll also need a USB cable to plug into your computer.

We're going to be using a piece of software called Mu, to write the programmes for these two.

So, you'll need to have that installed on your machine.

If you haven't, you may need a parent or carer to help you instal that before you get going.

If you can turn off all notifications and remove any distractions, and when you're ready, we'll get started.

Okay, in this lesson, we'll explore the micro:bit hardware components, we'll create our first programmes for the micro:bit, and we'll learn the process of flashing and running your programmes on the micro:bit.

So, the micro:bit is a tiny computer.

It's a microprocessor that can execute one programme at a time.

You can write programmes for the micro:bit on your computer and then transfer them to the micro:bit to be executed.

If we look at the front of the micro:bit, you can see there are a number of features.

So, there are two input buttons, which are A and B.

There's an LED display, which is the five by five matrix of lights on there that you can light up for showing messages or creating patterns or images.

There's also a light sensor, so it can determine how light or dark it is.

And across the bottom here, there are some GPIO pins or General Purpose Input/Output pins, that we can use to connect to the physical world.

And then if we turn around and look at the back, we have a temperature sensor.

Which we can use in our programmes.

There is a compass, an accelerometer, and there are also some radio communications for inputs or output as well.

So, as I mentioned in the introduction we'll be using a programme called Mu to code the programmes for our micro:bit.

So let's take a look at that environment here on the screen.

There's a mode button at the top left which will be able to select our BBC micro:bit mode, so that we can write MicroPython programmes in Mu, to be able to transfer to our micro:bit.

And here's an example programme that we can start and investigate and have a look at the structure of what's going on here.

So, at the start of every one of our programmes for the micro:bit we put, from micro:bit import star.

So, from the micro:bit module we want to kind of import everything that's available to us so that we can access the features on this device.

And then here, we've got a message that says display.

scroll, and then in brackets and quotes, we've got Hello there! So, display represents the micro:bit's five by five LED matrix.

And scroll is an action that you can perform on that display.

So, we can send messages scrolling across those LEDs.

With things like this, you can look up the other objects and the associated methods in the documentation, if you'd like to do so.

Flashing is the process of transferring one of the programmes in Mu across to your micro:bit using the USB cable.

So, when your programme is ready, you can flash it across and it will pretty much execute straight away.

If there are any syntax errors, then they will show up on the five by five display.

So, you may have to read the message that's running across the display, to find out the line where you may have a syntax error in your code.

If there are no syntax errors then your code should execute straight away.

So now, I'll demonstrate how to write that basic programme and flash it to your micro:bit.

Okay, so let's take a look at the Mu programme.

Here we have a mode button and we can make sure that we've got the BBC micro:bit mode selected.

So, we can write MicroPython code from micro:bit programmes.

And they're going to pop in here, the code that you saw in the demonstration, in the slides.

So, we've got those two lines that were explained before and I'm going to plug in my micro:bit There we go.

I'm going to plug it in, a light should come on and flush.

It's connecting, and then we'll get a box popping up, So, now opening file manager.

So, I can open it up, and I can see the files on there.

So, if I was to choose to save my file locally to the the machine, I'm working on here, I could drag it onto the micro:bit that way.

Alternatively, which is easier, I can click this flush button, which is up here, and that will flush the programme to my micro:bit.

And once it's flushed, it will say, "Hello world," across the screen there.

And that will only run once because I've only asked it to do it once, but if I wanted to again, I'll restart it, press the button on the back, and it will restart the micro:bit and rerun the programme.

And that's a basic introduction in writing a file and flashing it to your micro:bit.

Okay, so hopefully that demonstration was useful for you.

And now you're ready for your first task.

So task one, is to replicate what I just did there.

So, you're going to connect your micro:bit to your computer and using Mu.

If you've got it installed now, hopefully, you'll be able to code those two lines and flush it to your micro:bit and see your code working.

So, using the worksheet, follow the instructions and away you go.

Okay, how did you get along? Did your message you've work okay, and you've scrolled across the screen? And did you notice the difference when you chose to type in the word show, instead of scroll? So, the letters just appear one after the other, rather than scrolling smoothly across the screen.

Well, now we have another task.

So, we're going to display some images on that five by five display now.

So, using the worksheet, you've got some code and you can modify the code next to the displayed image.

As you can see on the right, it says display.

show Image.

HEART, while there are other images that you can see on there, such as HAPPY, SAD, YES, NO.

Using your worksheet, you can have a go at creating some of those images and displayed them on your micro:bit.

You can pause the video, and complete the task Okay, did you enjoy sharing those images on your micro:bit? There's quite a few, if you want to have a look in the documentation online there are plenty of others to experiment with as well.

As you know, from the beginning, when we looked at the features of the micro:bit, it has an accelerometer and that means it can detect movement on three axes.

So, it can detect on that one can detect it on that one and it can detect on that one.

So, three axes, three dimensions that it can detect movement on.

Looking at the programme opposite.

We're introducing an if statement.

So, we've got the usual from micro:bit import star and it says if something display, show image HAPPY.

So, that's the smiley face, otherwise clear.

So, the conditioning line two is missing for now, but you can see there are two possible branches showing happy when the condition is true or clearing the display when the condition is false.

Using the worksheet, copy the code on the right hand side and fill in the missing condition and see if you can get the programme working.

You can pause the video and complete the task.

Okay, so you can see on the screen in a second, what it should have looked like when you had your code working.

So, when you tilt the micro:bit one way the smiley face will disappear.

And then when you tilt it the other way, you can see the smiling face appear.

So, that's using the accelerometer to detect gestures on your micro:bit.

So, I hope you enjoyed that introductory lesson on physical computing with the micro:bit.

See you in lesson two, for some more physical computing.

I will introduce some more concepts and some more inputs and outputs.

I'll see you next time.