video

Lesson video

In progress...

Loading...

Hello, and welcome to lesson one of our selection in physical computing unit.

I'm Andy and in this lesson we're going to look at connecting Crumbles.

For this lesson, you'll need a Crumble Starter Kit, three double A batteries, and the Crumble software installed on your computer.

You might also find it useful to have something to write on and something to write to with.

So if you'd like to clear away any distractions, then we can start.

In this lesson, you'll control a simple circuit connected to a computer.

You'll build a simple circuit and connect it to a microcontroller.

And that will be connected to computer.

You'll programme the microcontroller to light an LED.

And you'll be able to explain why an infinite loop is used.

During this unit of learning we'll be using and programming a microcontroller.

What do you think the term microcontroller could mean? I'll give you a moment to think about it.

And there's a hint on the screen.

A microcontroller is made up of two words, micro, which means very small and controller, which is controlling things.

So a small controller for controlling things.

A microcontroller is a small device that can be programmed to control devices that are connected to it.

The microcontroller we'll be using is a Crumble controller, which we will use to control LEDs and motors.

So your first task is going to be to look at the Crumble controller.

You'll need to look at it and note down any observations you may have.

So look at the controller, look at it very carefully both sides and note down anything that you notice as you're looking at it.

So pause the video now.

I hope you found that interesting.

We'll have a little look at the Crumble together.

So this is the Crumble.

We've got the white board and then we have 12 hole around the edge.

The 12 holes have what looks like gold around them.

And they are connectors, they're called pads and that's where we connect things like the batteries to power it and the lights and LEDs and the motors that we connect up are connected with crocodile clips to those pads.

We've got this black thing in the middle.

This is a microchip, it's the microcontroller.

That actually is the thing we programme and our programme, then will control everything else that happens.

And you can see it's these legs connect onto.

If you look really carefully, you can see there are some lines down here, there are tracks.

So those are wires or light wires, which connect those legs to the various components and eventually, to these connectors on the edge.

So the tracks connect the microchip there, that microcontroller to eventually to the pads, which lets us control things.

At the top we have a micro USB connector, that lets us connect it to a computer to send programmes to it.

And then if we look carefully, we've got some symbols on here.

We've got a plus and a minus up at the top, this is where power is connected.

These are labelled A, B, C, and D.

these pads are for connecting other things like LEDs.

And down the bottom, we have one and two and plus, and minus, these are for connecting motors.

And actually there's two little white things here, they are LEDs that light up when we control motors.

So that's most of the top of the Crumble controller.

We'll just turn it over now and have a look at the other side.

So if I can just get that straight so you can see it.

Again you can see all the pads, you can see the pads that are labelled.

You can see that it needs a four and a half to five and a half volts power to make it work.

And it's got the version of the Crumble down here, it's version, two release four of the Crumble controller.

So we're going to move on to looking at something else now.

As you look at the screen, you can see a light flashing.

The little light that's flashing, is called an LED.

An LED is a light emitting diode.

When electricity is passed through an LED, it produces light.

The LED that was being controlled on the last slide, it was being controlled by a Crumble.

And it's called a sparkle.

Using crocodile clip connectors, we can connect the Crumble to the sparkle and that will provide power.

And also there is a wire which sends a signal, which controls it.

So if you look at this, you can see the pads around the edge of the sparkle.

So there's a positive connector and a negative connector for power.

There's a D pad on the side, and that is for the signal.

That's the control wire.

And the other side of the sparkle allows us to connect onto other sparkles if we want to.

You can also see at the bottom of the sparkle, there is a D.

The D indicates that, that's the bottom of the sparkle.

That's down.

So we are going to look at, connecting a sparkle to our Crumble and also connect to power.

So this is what the connections look like.

We have the battery pack on the left with two wires connecting to the Crumble.

And we have the sparkle with the three wires connected on the right.

You also have the grey cable at the top, which connects the Crumble to your computer.

The USB connection.

When you do make these connections, it's important that the sparkle and the Crumble are the right way around and the right way up.

So I've now got all the bits that I need and I'm going to connect them together so you can see how it should be connected.

There are five different wires.

It doesn't actually matter what colour the wires are, but it's easier to see if I use the same ones as the diagram.

So I'm going to start with the battery pack, that's my battery pack with three batteries in.

If I switch it on, I can check I've got power.

Turn it off again I don't want it on while I'm connecting.

And then I'm going to take the red lead and connect it to the positive.

You can just see on there, there's a little plus sign and I need to connect the red to the positive pad.

I'm then going to take the black lead and connect that to the negative pad.

You see, there's a line there separating the two.

So I'll have the two sides, connect that to the negative.

It done so I can place that down.

I then need to connect onto the Crumble.

And this is the red one, the other end that was going to the positive.

So I connect to the positive on here.

And then the black connector was on the negative.

I'm connecting that to the negative on here.

I then need to connect the sparkle.

So I'm going to connect another red to positive.

Black to negative.

And the yellow to the D for the signal.

Sometimes these covers, these boots are a little bit slippy, try and keep them on.

Because we don't want the crocodile clips to touch each other and cause a circuit.

So it's quite important that they stay on.

And then I can pick up my sparkle, which is here.

And I've got plus, minus and the D at the bottom, positive, negative.

So positive is the red, plus connect with the red.

Black is the minus, negative connect that.

And then the yellow is the D the signal wire.

So I connect that to there.

There we go and if I lay it out, it's not quite straight, but you can see the connectors.

And then lastly, I'll need my micro USB connector to connect it to the computer.

So if I take that wire and then carefully put it in the right way around, it will only go in one way.

And as I connect it and it's in the computer.

It'll make a noise as the computer detects it.

So that's it, all connected up.

So your task now is connect the Crumble to the battery pack and to the sparkle and to your computer.

There's a diagram in the worksheet to remind you, which bit needs to be connected to which bit.

Pay extra attention to it and make sure that your Crumble and your sparkle are the right way up when you connect them.

So go make those connections, pause the video now.

So now we've got the Crumble all connected up and connected to the computer.

We can have a go at programming it.

So we use the Crumble software to programme the Crumble to make things happen.

So let's just have a moment looking at this.

So here is a Crumble programme, and I'll give you a moment to look at it and think about what the different commands might do.

So have a moment looking at it.

So we have a number of commands.

Some of it's quite similar to Scratch.

We have the programme start.

So that's clearly where it starts from.

And then we have a command here saying, set sparkles zero to red.

So that's a command to light up the first sparkle in the chain.

And the first one is actually called zero.

The second one is called one and so on.

So the first sparkle is zero.

It lights it up and then it waits for half a second.

And then it turns that same sparkle zero off, waits for half a second, and then should make it red.

It waits for half a second.

Turns it off.

Waits for half a second, makes it red.

Waits for half a second, turns it off.

So we're going to launch the software now and actually try that programme out.

So we've got the Crumble software running now, and you can see here, down at the bottom is a picture of what's going on on my desk as well.

So I need a programme start.

And then I'm going to use a set sparkle to zero.

Wait one second.

And turn sparkle zero off.

So it was set sparkle zero because there is only just the one sparkle and it's the first one in what could be a chain of them.

So the first one is zero.

We wait one second and turn it off.

So we are going to try that first.

If I go and press go, that will send the instructions to the sparkle and then run it.

And if you're watching down the corner, if I run it again, you see the sparkle lights red.

So I'm going to make it do that a little bit more.

I need to make it stay off for a second.

and then come back on.

And wait a further second.

And then switch off.

And then wait another second.

I need to remember all the waits.

And then we turn it back on.

And then we have another wait.

And then we turn it off.

And I'll add one more wait.

So we've got on, wait, off, wait, on, wait, off, wait, on, wait, off, wait.

So if I now go and press the green triangle it programmes it.

If you watched the corner, there we go the flash is on and off three times.

We'll just run that one more time.

Three.

So like Scratch, you can take codes apart.

If you do make an error where you miss something out, you can take it apart and you can remove things and you can put things back in.

So check it again.

Test it works.

One.

Two.

Three.

That's our programme running.

We've programmed the Crumble to control the sparkle and the sparkle flashes on and off three times with a red light.

So it's now your turn and over to you.

So open the Crumble software, add the programme that's shown on the worksheet and then run it on the Crumble.

So when you finished, your sparkle should light up red and switch off three times.

Pause the video now.

I hope you got that working.

If you didn't, then you first need to get back and check your code.

Check that your code matches the worksheet.

If it's all exactly the same and it doesn't work still, you'll need to go and check your wiring.

Make sure the Crumble is wired up correctly with the sparkle, that they're wired the right way around.

It needs to match the diagram exactly.

You may also need to check that the batteries are all right.

The battery holder should have a green light on it if the batteries have enough power.

So if it didn't work, go and check those things and see if you can get it to work and then we can carry on.

So you've had a look at the programme.

You made it do something, you perhaps even thought, "Oh, I wonder if I can change it?" So think about how you could modify this programme.

What would you do if you wanted to change the LED so it was a different colour? What would you need to change if you wanted it to wait for longer between switching on and switching off or switching off and switching on? And how would you make it flash more times? I'll give you one hint.

If you're looking at the colour, you can click on these little boxes, the red box there, and that will give you some choices.

So your task now is to go back and modify the programme.

Try and make the sparkle light in different colours, It could all be the same colour or different colours.

Try changing how long the wait is.

And try making the sparkle flush more times, a different number of times.

Pause the video now.

Hopefully you've known to do some of that, so we'll just have a look at it now.

So one of your tasks, your challenges was to change the colours.

So these are the colours of the sparkle.

I'm going to click on that one.

I'm going to change it to green.

And I'll leave that one as red.

And I'll change this one to a blue.

And we'll try that and see what that does.

Green.

Red.

Blue.

So I've got it showing different colours.

I'll just try it one more time.

Red and then blue.

Great! So the next thing was to try changing the time between them.

So there's how much time it's switched on for and how much time it switched off.

So I'm going to change those times to be less.

So I'm going to put half a second in for that one.

And half a second for that one.

And I'm going to put two seconds in for that one.

And I'll put half a second in for that one.

So let's give that a try.

So I've got half, half, two, two.

So it's on for half, off for half.

On for two seconds, off for two seconds.

Let's try that.

So you can see some of the flashes appeared to be quicker.

And some, it was on for longer.

So that's the different amounts of time.

I'm going to change these all to a half now to make it go through more quickly.

And then I'm going to try actually making it flash more times.

So I can take a set sparkle.

And I can set the colour.

Let's have this one as a purpley colour.

I don't know that will show on the film but we can try it.

And then we'll get it to wait for half a second.

And then I need to make sure it turns off.

And I need to wait for half a second.

So let's try that.

So now I've got more.

So one, two, three, four flashes.

And I can actually duplicate all the code.

So if I duplicate all of it and put at the end.

Now, if I try it, one, two, three, four, five, six, seven, eight, and we've got eight flashes.

So we can make all sorts of different changes in terms of colour, how long the lights stay on for, how long they stay off for and how many times it does or doesn't flash.

And we can also remove the extra times it flashes.

So we look at something else now.

So if we go back and look at our original programme, that was making the sparkle flash on and off, once, twice, three times.

You're going to have to think now about how you could make the sparkle flash continuously.

So on and off and on and off and just going on forever.

So at the minute it does it three times, you're going to have a look about a way of making it repeat and repeat forever.

So your task is to modify the programme and make it flash continuously.

Make it carry on flashing on and off and on and off.

So pause the video now and try that.

So that's how we'll look at that then.

So we had our current programme, which was switching the sparkle on and off on and off.

And it was happening three times.

I wanted to carry on flashing on and off forever.

If we look over here, we have something called a loop and there's one called, do forever loop.

So if I take that and drop that in, I can now put all those instructions in and try that out.

One, two, three, four, five, six, and it's just carrying on.

If we look very carefully at our code, we can actually see this switching on, waiting, off, waiting, is repeated here and repeated again there.

So we actually have more instructions than we need.

So if I take that set away.

And I take that set away.

You can see if I put them all side by side, you can see they're all the same.

I don't actually need these because it's doing that and that, and that lots and lots of times.

Rather than going through those, so I'm going to take those and put them over here.

And we'll just check that still works.

There we are it's flashing on and off and on and off.

I'm going to stop that, and we can even try putting different times in.

So I could put a quarter of a second.

And I'll try here another quarter a second.

And now we'll try that and see what that does.

Flashing slightly more quickly.

So this is using a forever, a do forever loop.

So it's repeatedly doing those instructions for forever or until I press stop.

So if you want to go back and try with the code anymore, now would be a good time to pause the video just before we get the last bit.

So if you want to try any other bits, do that now.

You can try altering your do forever loop and putting different things into it and see what happens.

The form of repetition you used to make the programme repeat forever, is called an infinite loop.

Why do you think it's called that? I'll give you a moment to think about it.

An infinite loop.

Infinity is something that goes on forever.

So an infinite loop goes on forever without end.

So that's why it's called an infinite loop.

Do forever loop is an infinite loop.

So in this lesson, you built a simple circuit using a microcontroller and connected it to a computer.

You programmed a microcontroller to light an LED in different ways.

And you use repetition in the form of an infinite loop.

If you'd like to share your work with Oak National you can.

They might be screenshots or photographs or little videos of your sparkle flashing.

If you'd like to do that, please ask your parents or carer to share your work on Instagram and Facebook or Twitter, tagging it at Oak National and with the hashtag, LearnwithOak.

That's it for this lesson.

See you next time.