Understand what microcontrollers are, and why they’re used.
Remember how to set up and use a microbit
Re-familiarise ourselves with the micro:python interface
Words to learn for this lesson are: Micro-controller, Arduino, ARM, Maker’s revolution
Look at some of this video:
All the tech in this video uses a tiny open-source programmable computer called an Arduino. These are all simple, home-made projects using affordable, easily sourced components. Many of these projects (the Rubik’s cube solver, the robot arm, the 3D printer) have been made in after-school clubs here. The point is, we are living in a time when we have the tools and means to make pretty much anything we can imagine…
3D printing and laser-cutting give us the opportunity to create any component we can think of, whilst programmable micro controllers mean we can add sophisticated sensors and input/output to our creations. This has given rise to the Maker Movement – we no longer need factories to create products. We make our own!!
So, the Arduino you saw in the video contains an Atmega 328 ARM chip. This is essentially an entire computer (RAM, Microprocessor and ROM) squeezed onto one chip. The rest of the circuit board basically gives us access to input/output on this computer.
The BBC micro:bit you used in year 7 essentially uses similar technology, but has some simple sensors for input, and basic output built in.
Task: Research and explain the input/output features of the BBC micro:bit, labelling a diagram in your books. This page should help.
Now a refresher of how to use your micro:bit:
OK, let’s get started. You will be given the BBC Microbit device, a short USB cable and an (empty) battery pack. The Microbit is reasonably tough, but please be careful when you are handling it – try not to drop it and be careful when plugging or unplugging cables.
Plug the small end of the USB cable into the USB socket on the top of the Microbit – it will only go in one way so don’t force it, check you’ve got it the right way round!
Plug the large end of the USB cable into a USB socket on your computer – your teacher will show you where this is.
When you plug it in the yellow light next to the USB power will light up to tell you the Microbit has power. You may also see the red LEDs on the back light up as it runs a demo program.
Open the MicroPython editor by clicking the link above. This will load a demo program which looks like this:
Your teacher will show you how to flash this program to your micro:bit
You started to look at this in year 7, but a quick refresher:
So what does all of the code written in Python mean mean? Let’s go through it line by line:
from microbit import *
This line tells Python that it has to use the microbit library. A library is a set of add-in instructions that allows Python to communicate properly with the microbit. The programmer doesn’t need to do anything complicated. You must always have this line at the top of any Python code you want to run on the Microbit.
This is the Python equivalent of the forever block in Blockly. This means that whatever comes after it (and is indented) will repeat forever.
This tells the Microbit to scroll the message enclosed in apostrophes. In this case it will scroll the message Hello, World! across your screen.
This tells the Microbit to display a built-in image. Python has lots of built-in images – the list is below:
This tells the Microbit to wait for 2000 milliseconds. 2000 milliseconds are 2 seconds. What would happen if this line wasn’t in the program?
In the MicroPython editor, click the Download button and transfer the .hex file to your Microbit to run the program. See if it works. Try changing the code – for example try changing the image it displays or the text that is displayed.
Write some code that will display 4 different animals, one after the other.
How about the name of the animal, followed by a picture?
Screenshot your code and add it to your book.