Loading...
Hi, I'm Rebecca, your computing teacher.
Now, you're in for a treat this lesson 'cause you are going to be starting to look at something called a Sense HAT.
Now you aren't going to need to use a physical Sense HAT because I've got an emulator for you to use which is on a website called Trinket, which I'm going to show you how to use.
Now you do need to ask your parent or carers permission before you set up a Trinket account and I'll show you how to use that later, but if you did have a Raspberry Pi computer and you've got your own Sense HAT as well, then you might want to do that for this lesson.
For this lesson and the next one, you might want to use the physical computing aspects of this lesson rather than the emulator.
Now if you do, you must make sure you follow the safety instructions to do that.
Before attaching your Sense HAT to your Raspberry Pi computer, you need to make sure that you completely powered down your computer, there should be no power cables into it whatsoever.
You also need to make sure that you really, really carefully put the Sense HAT on top and it goes like this and if you look, there are pins all the way down here and slots all the way down here and you must make sure that they line up perfectly before you starting very, very gently pushing that down, okay? And once you've done that and you're really happy that it's all done, none of the pins bent, then you can go ahead and plug your Raspberry Pi computer back in and you can do it on your Raspberry Pi instead, but don't worry, you do not need a Raspberry Pi computer and a Sense HAT for this lesson, because we're going to be using the emulator in Trinket.
And don't forget, pen and paper's always, always handy and making sure you remove as many distractions as possible so that you can really focus on this lesson.
Once you've got that ready, you can begin.
In this lesson, you will use a Sense HAT to display text and you'll use a list to display pixel animations on a Sense HAT.
Start with a quick question then.
So arrays versus lists, what's the difference? What are the key differences between an array and a list in programming? Pause the video while you think about your answer.
So an array is static, it has a fixed size and all elements within it are the same data type.
And a list is dynamic, it's size can change during execution and it can hold data of different types.
So what is a Sense HAT then? The Sense HAT is an add-on board for the Raspberry Pi computer that was designed for the Astro Pi space mission.
There are currently two Raspberry Pis with Sense HATs orbiting the Earth on the International Space Station.
HAT stands for Hardware Attached on Top.
The Sense HAT sits on top of the Raspberry Pi computer and allows you to write programmes that interact with the sensors and the LED matrix.
So here's your Sense HAT input and output.
So you've got an eight by eight RGB LED matrix grid and that is extremely colourful.
If you've got one yourself, you'll see how bright those lights are and it does make some very colourful pictures that you can have on there.
It's got a gyroscope, an accelerometer and a magnetometer as well.
It's got temperature and humidity sensor, a barometric pressure sensor and a mini joystick too.
So it's got quite a lot going on with it, it's quite a good bit of kit.
Now an emulator has been designed for the Sense HAT so that anyone can learn to programme with it, even if they don't have the physical device.
So I've already explained that to you.
You can use a physical Raspberry Pi and a physical Sense HAT with these lessons if you want to or you can just use the emulator like I'm going to show you.
So let's go and take a look at what the emulator looks like.
So what I've just done then is I've just typed in that short link that was on the presentation, it's also on your worksheets, so don't worry, you can find it there too and then what it's done is it's just given me those first two lines of code that I need to input the Sense HAT and then to use the Sense HAT as well.
So those two lines of code are quite important.
Now, you haven't seen Trinket before.
Trinket's quite different to Repl.
it, but it's similar in the fact that you can code online and you can execute your code online in the Cloud so you can log on wherever you want and use that code.
Now if you do want to set up an account, you can go to sign up here with your parent or carer's permission.
If you don't want to set up an account, then that's absolutely fine, but what you could do, is you could copy and paste your code at the end of the session into your Repl.
it account.
You won't be able to run it in your Repl.
it account because Repl.
it doesn't have the emulator at the moment there for you to use like Trinket does, so you won't be able to see the Sense HAT running there.
So the code won't actually work, but if you wanted to save all your code in one place, that's another option that you can do, if you don't want to set up another account.
That's just another option.
What you can do in this software, you've got expand, so if you want to make it a big bigger, you can choose the expand option there and then you can just see a little bit more.
Another thing you can do is just make the font size larger 'cause I think the font size is extremely small on this site, so you can go down to there, click those three lines then you can just make the font size larger so that you can see it there.
You can't save it to a darker screen on the background, you've just got a white screen there.
The only thing is now I've made it to bigger that side, it's also made it bigger that side, but that's okay for now.
When you're doing it, you might want it a little bit smaller.
So here is the Sense HAT and you'll notice that this Sense HAT that's on here looks a bit different to the one that I had and this is because this is the AstroPi.
So this is a graphical version of what is in the International Space Centre now.
So there's two of these in the International Space Centre right now and they're in these boxes here to protect it while it's in space as well.
So, that and then you've got the Raspberry Pi computer would be inside there.
So, you can have it in this view, the other view is the Raspberry Pi view, which looks a little bit more like what I showed you earlier with the physical device.
So I've got it here.
You can also drag this over so you've got a little bit more room too.
So I'm going to just have it like that for now.
I might have to keep switching views so that you can see the whole screen and everything properly, but we'll just have to see how we get on.
So, as you've noticed, if I just drag and hold I can move this around and as you start to programme it, because there are sensors on it that detect the movement, you can actually set up programmes so that based on where it is, certain things can happen, so that's why you're able to move it here on the screen.
So that allows you to move it around.
You've also got your different sensors up here.
Now obviously you can't make it warmer or colder on the computer, so you have to emulate that by just putting the sliders on, but if you were using the real Sense HAT, you'd have to know what the temperature is and try and make it warmer by maybe blowing hot air on it or something like that to test it out.
So you can use those sliders here too.
So that's just giving you an idea of how it works.
You do usually, sometimes have to press run in order to get the emulator to appear on the right hand side.
If you just went into Trinket yourself and just copied and pasted that code in there, you wouldn't be able to see the Sense HAT on the right hand side and so you'd actually run the code, but because I've given you the start code, it is there on the right hand side.
If it's not there for some reason, if you press run, it should appear on the right hand side.
So, you're going to have a little go at finding this yourself, just doing a little bit of start code to get you going.
So complete the first steps section of your worksheet to get started with the Sense HAT.
Pause the video while you have a go at that.
Awesome, hopefully you found that quite fun.
So we're going to look at controlling the matrix now.
So you might find your LED matrix becomes filled with pixels that you no longer want to be lit up.
So to clear the screen, you need to use sense.
clear with the two brackets and when you use this code snippet it will switch off all of the LED's on the matrix.
Now you can also add a colour as an argument to fill the whole display with a single colour.
And you'll notice there that red is there inside the brackets.
Now red is a variable so you would need to make sure that you declared that variable red and that assigned the correct values to it to make it red.
So here's a question for you then.
What do you think the output of this programme will be when it is executed? Pause the video while you have a little think about that.
Let's see what it'll do then.
So on the Sense HAT, it will put a yellow pixel, it'll just light one pixel in that top left hand corner.
So this code snippet sets a pixel at a specified location to a specific colour.
So if you look at this line of code we've got set the pixel at this x coordinate and this y coordinate to this colour.
So X goes across and Y goes down and you can see the values there.
So locations begin at zero and end at seven.
And setting a pixel is a useful tool.
However, it can take a lot of thought to create a full graphic.
So if you look there, you've got, it's not quite a smiley face, it's quite a serious face there.
It takes all of those lines of code there to draw that one face and also, it's quite difficult to know exactly where those pixels are going to appear 'cause you really have to visualise that in your mind.
This is where a list can become really useful.
So a list can be used to set up all of the pixels on the matrix in one structure.
So this is what it looks like here.
So you've got a bit of code and you've got a list there called smile and then if you take a look there, all of those elements in that list pretty much match up with what is actually on the Sense HAT there on the screen.
So the list can be presented in the code to match the layout of the matrix and this just makes it much, much easier to realise, the visualise in your mind what it's actually going to look like and then the list is then passed as an argument to the set pixels function.
So notice it's got a little s on the end now, not instead of just pixel.
And the output is displayed on the matrix like that.
Now you're going to have a go at designing your own animated character which you can use on that grid.
So for the next task, you'll be designing an animated character that will appear on your LED matrix.
You will need to either print the worksheet and colour in the squares or create your own eight by eight grid to colour in.
Now if you take a look at the worksheet, it does give you all the instructions you need for that.
Yeah, and if you need to print and colour or just copy the grid in colour, then that's fine.
The important thing is that you've got that eight by eight grid and you know exactly what is going to go into each grid so that when you start copying it across into your Python code, you can match it up quite easily.
And it's also really important that you put letters in each box as well.
Don't just colour those boxes in.
You need a letter in each box too because you're going to have to assign a colour to each of those letters as well.
So take a look at your worksheet, use the create your character section of your worksheet to create an animated character with your Sense HAT.
Have fun, enjoy this one.
Excellent.
So, what I'd like you to do now after you've had a go at doing all those challenges with your Sense HAT, I want you to use Google Earth to take a 360 degree tour of the International Space Station and whilst you are there, your mission is to find those two Astro Pis.
So I'm going to give you a quick demonstration of how to get there and how to use it, but I'm not going to show you where it is, okay? That's your job, so let's go take a look.
So you're going to go to that short link that will be on the screen in a few moments for you to have a look at, and this is just what it looks like at the beginning.
You'll notice on the right hand side there, you get the list of all the places that you can look at in the International Space Station.
So if I go to, let's for example, node three, what it does is it takes me to inside node three, gives me a little bit of information about what that actually is there and then I can just drag it around, and if you've ever used Google Earth before, you'll be quite used to this, and you can drag it around and you can start looking at all the different things that are around.
So doesn't look like there's an Astro Pi there anywhere.
Let's just have a look.
So it's a little bit of a treasure hunt for you to try and see if you can spot, I want to say it's obvious, they're fairly obvious.
You don't have to really, really strain at the screen in order to find it.
It should pop out quite easily, but you will need to hunt them, okay? You don't need to zoom in though, they're not going to be miles away in the background and you have to zoom in.
If you haven't seen it by the time you've looked around, up and down, then it's probably not in that room and you can try a different room, okay? So you have a go now.
Use the short link there to find that Google Earth link and then see if you can find those two Raspberry Pi Astro Pis in the Space Station.
Off you go.
Well I'm going to reveal the answer now.
So here it was, it was in the Columbus Research Laboratory.
If you gave up or you didn't quite get there, you can go back now and have a look at it and see if you can find them.
So there they were on Google Earth, up there in space.
It's quite exciting, isn't it, to know that those two things are up in space.
I find it quite fascinating.
So hopefully you really enjoying using a Sense HAT in this lesson and you've got a bit of an idea of how it works now and we're going to take this a little bit further in our next lesson to do with Sense HATs.
And if you'd like to, please ask your parent or carer to share your work on Instagram, Facebook or Twitter, tagging @OakNational and hashtag LearnwithOak 'cause it'd be nice to see those animations that you've done in this lesson on your Sense HAT.
And I'll see you again soon for our next lesson.