Your first question may be.... what is Python?
Python is a programming language that involves typed code rather than dragging and dropping blocks together.
Python is often used at GCSE level but is also a really popular programming language across the world in a variety of jobs. Python is constantly being developed by the Open Source community making it great for programming Raspberry Pis, Tello Edu drones, Lego robots and BBC micro:bits.
Pupils across primary and comprehensive schools often get a great experience using block code editors such as Scratch. At Penyrheol, we noticed that pupils didn't always have experience of the same block code editors but found that BBC micro:bits were a great resource to use help pupils make further progress.
Micro:bits have the flexibility to work with a block code editor and high level programming languages such as Javascript and Python. GCSE pupils use Python as their main high level programming language when studying GCSE Computer Science at Penyrheol Comprehensive. Projecti Codio has helped us plan how to bridge the gap between pupils using micro:bits in Year 8 and pupils using Python at GCSE level in Year 10.
Although the block code editor on the micro:bit website has an option to create code using Python, we felt we needed more help with creating working Python code. A bit of research led us to https://codewith.mu/.
Below are some quick links from their website. The download was quick but you need to be quite patient with installation and the first time you start the software. The tutorials section of the site really helped us to make quick progress at the start.
About MU - https://codewith.mu/en/about
Download - https://codewith.mu/en/download
Tutorials - https://codewith.mu/en/tutorials/1.1/
Tutorials - https://codewith.mu/en/tutorials/1.1/microbit
Tutorials - https://microbit-micropython.readthedocs.io/en/latest/tutorials/introduction.html
This piece of software included in the download link above, works in a quite similar fashion to other Python editors we have used with pupils. It will therefore help to introduce the same Python coding techniques we use at GCSE level but with visual results on a piece of hardware that pupils can hold.
The software can be installed on a Windows/Apple laptop or desktop PC and has some great error checking and code prompting facilities.
The document to the right is a guide we have created to help pupils use the accelerometer on the micro:bit. The sheet describes how to use Python commands to read the accelerometer data and then change the display depending on the readings.
The first guide describes how to make a basic balance sensor that only displays if the micro:bit is tilted to LEFT, RIGHT or balanced in the middle.
The second guide (in the same document) shows how to make a single LED light appear to move on the x and y axis according two axis that the micro:bit can be tilting on.
Word document version - Balance tutorial.docx
Python file - basic_balance_sensor.py
The tutorial on the website below assisted in the creation of this resource.
The PDF document to the left takes the balance sensor guide to a higher level. It uses both the X and Y accelerometer data to create an electronic bubble on the display of the LED display. This code has been available as an example for micro:bit users for several years. However, we felt we needed our own tutorial to help pupils create it in Python.
Using standard Python techniques such as WHILE loops, IF functions and a few functions from the import micro:bit library, the accelerometer data brings the micro:bit to a whole new functional level.
If the micro:bit is placed in one of the cases available from a website such as kitronik, it can then be used as a quite accurate spirit level.
Word document version - Electronic spirit level.docx
Python file - electronic_spirit_level.py
This resources was inspired by an example we had seen many years ago on the microbit.org website.
This guide sheet uses the accelerometer to merely detect if it has been shaken. If the device has been shaken it then reads data from a list created using [ ]. This is has been a key feature of pupils Python programming projects created in GCSE Computer Science.
Lists created using square brackets can act as data holders when users or sensors enter data into a program. The data within square brackets can be edited, amended, appended to and even searched.
Another feature of this code, is using the random library. This gets imported at the start of the program along with the micro:bit library. Importing and linking to code libraries is a key concept pupils need to learn particularly if they want to work on a coding team. Libraries help to create consistent solutions amongst teams.
This can then lead to using the micro:bit to detect if it is accelerating or decelerating. The sheet gives more information on the code to use to detect the force of acceleration, deceleration or even freefall.
Word document version - Dice tutorial.docx
Python file - dice.py
If pupils have managed to create the dice then they can move on to creating a Magic 8 Ball. The Dice and the 8 Ball use very similar code but the Magic 8 Ball guide sheet has a few adaptions added to it.
When using the MU code editor, there is a limit to how long one line of code can be. Interestingly the solution to this problem gives pupils a taster of how advanced coders may organise long lists of data.
Pupils can also start to think about improving the user experience by creating some custom graphics that let the user when the Magic 8 Ball is ready to use. This is a little like a start or splash screen on a software application.
Word document version - 8 Ball tutorial.docx
Python file - 8_ball.py
The micro:bit is also capable of reading magnetic north. This means it can give the user data on which direction it is pointing in relation to north. Readings come back in degrees from 0-359.
Performing calculations using Python and other programming languages can be a challenge for pupils as the mathematical symbols aren't always the same as in their traditional Maths lessons. Symbols such as forward slash and asterisk need to be used for divide and multiply (respectively). There are also times when a double forward slash needs to be used so that integers are returned as answers.
The compass tutorial also shows pupils how important it is to connect if statements using elif and else for more efficient code.
Word document version - Compass tutorial.docx
Python file - compass.py
To the left is a task idea that one of our staff created to share with our Primary Cluster colleagues.
The task requires pupils to learn about decomposition i.e. breaking something down into smaller parts to help solve a problem. Not only are pupils asked to break a story or poem down into individual parts but they also need to break their code down into smaller individual solutions.
The third page of the resource has a really useful list of all the ready-made images that a micro:bit can create using its LEDs
Word document version - Create a micro_bit story_poem project.docx