Programming a micro:bit




100 Points
Learning Objectives

micro:bit

micro:bitmicro:bit Features

These instructions will show you how to create and upload programs into a micro:bit microcontroller.
Microcontrollers are becoming common-they control automobile engines and subsystems. Examples.
And they will provide substantial cost savings in automobiles, like Teslas.
In later assignments you will continue working with and experiencing the capabilities of the micro:bit.

After completing this assignment you will be able to:

  1. Obtain, modify or create a program
  2. Connect a computer to the micro:bit
  3. Upload the program to the micro:bit
  4. Test and debug the program
  5. Upload a screen shot to D2L

Assignment Overview
This assignment reviews basic computer concepts that you will need in this course and throughout your career.
For this assignment, you will install the Mu  code editor onto your laptop.
Note there is also a Mu editor available for Windows and Macs.
You will learn to work with Mu and upload programs to the micro:bit.
And you will modify and debug these programs.

You are expected to have a working knowledge of microcontroller hardware and software.
If you do not understand how to use an item, perform a Google Search, refer to the WSU Technology Knowledge Base,  ask a teaching assistant, or ask the instructor.


Note: if the micro:bit is acting up, it may need to have the firmware updated.
Instructions to update the micro:bit firmware can be found here: Update Firmware
Current firmware Interface Version: 0253


Exercise 1-Mu Editor

The programs that run on an micro:bit can be created on many devices-a laptop or Raspberry Pi.
In this exercise you will install the Mu code editor onto a computer.
Mu is an editor used to program in microPython.

  1. The micro:bit is connected to the USB-C dock, your laptop connects to the micro:bit once you connect to the USB-C dock.
  2. You may notice that with your laptop connected to the USB-C dock a message appears on the micro:bit screen.
    This is not a problem, the micro:bit is running a program that was uploaded previously.
  3. Visit this url to download and install Mu to your laptop.
  4. On your laptop, start mu.
    If a 'Select Mode' window appears, choose 'BBC micro:bit', then press OK.

    Mu Mode Mu Mode

  5. This is what the mu editor looks like in micro:bit Mode, with a simple program.

    Mu EditorMu Code Editor


Before proceeding, make sure that you have already uploaded / published this assignment to your course website.
Then you will be able to view the remaining instructions and copy code from the assignment while viewing it in a web browser.


Exercise 2-Create Program

Create a simple program to scroll a message across the micro:bit.

  1. On your computer, browse to the following url:
    Scroll Message: https://microbit-micropython.readthedocs.io/en/latest/tutorials/hello.html
    This page explains how to create a program that scrolls a message across the micro:bit.
  2. After reading the page, you can easily modify the code in order to make it display other text.
  3. Below is code that will display another message.
    Copy it, and paste it into the Mu editor.
    Then make use of the toolbar buttons, such as 'Check', to verify your code before you flash (upload) the code to the micro:bit.
     # <-- this is a comment
    
    # Write your code below :-)
    
    from microbit import *   # import entire micro:bit library
    
    display.scroll("WELCOME TO MIS!")
    
  4. Save the program as IOTB01.py in the default location, 'C:\Users\<StarID>\mu_code'
  5. On the micro:bit press the 'Reset' button to make a program run again.

Exercise 3-Test and Debug

Next you are given a program that does not work, which means something is wrong with the code.
Note that there can be multiple problems!
Use your trouble-shooting skills to diagnose and repair the code.
Hint: remember to 'Check' your code.

Another hint: make use of the function syntax.
Syntax CheckerSyntax Checker

And another hint: if you try to flash a program that does not work, an error message will scroll on the micro:bit.
This message may be lengthy, and possibly hard to read.


  1. Copy the code below, and paste it into the mu editor:
    # Your Name Here
    # Your Class Here
    # Today's Date Here
    # IOTB01
    
    from microbit import *
    
    display.scroll("WELCOME TO MIS!")
    
    while True:
        if button_a.is_prssed():
            display.show(Image.HAPPY)
        elif button_b.is_pressed():
            display.scroll("I love coding!",delay=100,wait=True,loop=False, monospace=False)
        else:
            display.show(Image.SAD)
    
    display.clear()
    

  2. Save the program as IOTB01X.py in the default folder.
  3. Use your trouble-shooting skills to make the program function properly:
    When button A is pressed, a Happy Face appears on the micro:bit
    When button B is pressed, the message 'I love coding!' scrolls on the micro:bit
    When no button is pressed, a Sad Face appears on the micro:bit
  4. Modify the program as required so that is works.
    There are errors in the code!
  5. When you think the program is ready, flash the micro:bit and try it out.

Exercise 4-Document Work
  1. Use the Snipping Tool to make a screen shot of the micro:bit IDE.
    Make sure your name, class, assignment and date is visible in your program comments.
  2. Save the screen shot as "IOTB01" in your ' ' folder.
  3. Your screen shot will look something like this:
    screen shot formatScreen Shot Format


Upload Screenshot

Upload a screen shot of your work to the appropriate D2L Assignment folder.

(70) 1. Use a web browser to login to D2L.
Upload your screenshot to the 'IOTB01' D2L Assignment Folder. Save the screen shot as "IOTB01" in your ' ' folder.

Screen Shot IOTB01


Exercise 5-Reflection

Browse to the micro:bit Tutorials page.
Examine the available tutorials.
Choose a tutorial of interest to you and read it.

Based on your experience in this exercise and the tutorial you reviewed, develop a brief statement about the value of microcontrollers as an automation tool for simple tasks in organizations.
Think about what type of problems these devices could solve, and would it be effective?
Consider the learning curve to program these devices.

(20) 2. Reflections



Submit Assignment

When all tasks are completed press the Submit button.


(10) 3. Assignment submission