MicroPython 101

A project-based introduction to micro:bit programming using MicroPython with instructions to build 16 hands-on micro:bit projects. Request Quote

  • Grades 6 - 8
  • 14 lessons
    • Web
  • Python
  • Advanced Course
Course includes
  • 14 lessons
  • 86 activities
  • Enhanced Creativity Tools
  • Automatic Assessment
  • Tutorials and Reviews
  • Coding Puzzles
  • DIY Projects
  • Quizzes
  • Teacher Guides
  • Answer Keys
Prerequisites
No previous coding experience required.

MicroPython 101 Lesson Plan

Lesson: Introduction
Time: 45+ mins

Introduction

Welcome to Tynker's MicroPython 101 course! This course contains 14 exciting lessons that will teach your students how to program a micro:bit, which is a small (yet powerful) computer called a microcontroller. Did you know microcontrollers are all around us? They can be found in automobiles, mobile phones, laptops, and more! As students progress through the course, they'll learn about microcontrollers as they create a variety of projects while reinforcing coding concepts in the challenge activities.

Students will likely encounter a situation where their micro:bit does not work as expected, so they'll need to troubleshoot. The problem could be caused by human error (e.g., incorrect syntax, forgetting to attach the USB) or the device (e.g., the firmware isn't updated).

By the end of this lesson, students will become familiar with using their micro:bit as they complete a text scrolling and counter project. Note: Answers to all challenge solutions and quiz questions are located below the "Standards" section of this teacher guide.

New Code

  • display.scroll() : This is a display function that allows the user to scroll text on the micro:bit.
  • button_a.was_pressed() : This is a button function that returns True when button A is pressed on the micro:bit.
  • button_b.was_pressed() : This is a button function that returns True when button B is pressed on the micro:bit.

Vocabulary

  • micro:bit : A small computer that can run MicroPython commands
  • MicroPython: A version of Python that's designed to run on tiny computers, such as the micro:bit.
  • Booleans: Values that can only be True or False.
  • Loop: A loop is used to repeat one or more commands over and over

Objectives

Students will...

  • Demonstrate how to program and download code onto the micro:bit
  • Apply coding concepts to complete the challenge activities
  • Create a text scrolling and counter project using the micro:bit

Materials

  • micro:bit device (recommended 1 per student)
  • USB cord
  • Computers, laptops, or Chromebooks (1 per student) with student account access to Tynker.com

Warm-Up (5 minutes)

Tell students that they're going to learn how to program their micro:bit today using Tynker! Prepare students for today's lesson by helping them understand how to program their micro:bit. For example:

  • Step 1: Use Tynker's Text Code Editor to write your code
  • Step 2: Attach your USB to the computer and the micro:bit
  • Step 3: Click Deploy, then select the device you're using
  • Step 4: Test your micro:bit to make sure your code transferred correctly

Activities (45 minutes)

Facilitate as students complete all Introduction modules on their own:
1. What Is a micro:bit? (Document)

  • Students will read a short document that introduces micro:bit and the MicroPython 101 course. Here's what the micro:bit looks like:

  • Emphasize to students that they’ll need to read each module carefully so they can apply concepts from the lesson to program their micro:bit correctly and answer a multiple-choice quiz.
  • Point out the different features of the micro:bit: accelerometer, thermometer, compass, light sensor, and radio. Explain to students that they'll explore these features and more in the upcoming modules.
  • Tell students to click the Next button (located at the bottom of the document) to move on to the next module.

2. What is MicroPython? (Example)

  • In this module, students will learn about MicroPython, a version of Python that can be used to run on micro:bits. Additionally, they'll learn how to deploy code to the micro:bit.
  • Explain to students that the purple image of a micro:bit indicates an activity that requires using the Tynker Code Editor and deploying code. Here's what the purple circuit icon looks like:

  • Are students struggling to deploy their code?
    • Read the "Deploy Code" instructions carefully
    • Make sure the USB cable is properly attaching the micro:bit to the computer
    • Ask them to click the Deploy button in the code editor
    • Check that they're connecting the micro:bit to the correct device (e.g., BBC micro:bit CMSIS-DAP, TDAP-Link, LPC1768)
    • Update the micro:bit's firmware. Here's a link with helpful instructions:
      https://microbit.org/guide/firmware/

3. Hello, World! (DIY)

  • Students will learn how to write their first program using MicroPython and the display.scroll() function.
  • Tell students that the display.scroll() function allows them to display text on their micro:bit.
  • Coding Challenge: Change the Display
    • To solve this challenge, students need to change the word "Tynker" to "Hello, World!". Note: Answers to all challenge solutions are located below the "Standards" section of this teacher guide.
    • Remind students to type their code inside Tynker's Code Editor. Then, they'll need to click the Deploy button:

    • Optional: Ask students, "What does the Deploy button do?" (Answer: The Deploy button downloads the code onto the micro:bit.)
    • If students finish early, ask them to change the text to a different word, such as their name or favorite color. Their code might look similar to this:

4. Scorekeeper (DIY)

  • Students will learn how to create a program that keeps track of a score using the A and B buttons on the micro:bit.
  • Point out to students that the A and B buttons on the micro:bit can be used to increase, decrease, or reset the count. Once students finish programming their micro:bit, they can see the count displayed on the micro:bit.
  • This page includes two challenges:
    • Coding Challenge: Creating a Variable- Tell students to create a variable called counter and make sure they assign it a value of 0. Next, they'll need to display the counter variable using the display.scroll() function.
    • Coding Challenge: Using the Buttons- To solve this challenge, students need to program the micro:bit's button A to increase the counter variable and button B to decrease the counter variable. Give a hint: Tell students that in Python, the += operator adds to the variable, whereas the -= operator subtracts from the variable.
  • Are students struggling with the "Taking It Further" activity?
    • Give a hint: Tell them to create an if statement using the button_a.was_pressed() and button_b.was_pressed() functions. Next, they'll need to reset the counter to 0. They'll also need to display the counter variable using the display.scroll() function.
    • The code for the bonus section might look similar to this:

5. Review (Document)

  • This page reviews the following:
    • How to import the micro:bit's module using from microbit import *
    • How to increase a variable's value by using the += operator
    • display.scroll(text, wait=False, loop=False): Check that students understand the different parameters. For example, the text parameter needs to be in quotations. Point out to students that display.scroll() can also include wait and loop parameters.
    • The button_a.was_pressed() function controls button A on the micro:bit.
    • The button_b.was_pressed() function controls button B on the micro:bit.
    • Applying two different loops: while True: and If...Else...

6. Quiz (Multiple-choice)

  • Inform students that they'll need to apply what they've learned and answer a multiple-choice quiz. Note: Quiz questions and answers are located below the "Standards" section of this teacher guide.

Extended Activities (10 minutes)

Lead a discussion with your students:

  • Who can name at least two different micro:bit parts you learned today? (Answer: input/output pins, button A, button B.)
  • What does the Deploy button do? (Answer: downloads your code onto the micro:bit.)
  • If you're micro:bit isn't working as expected, what should you do? (Answer: check your code's syntax, make sure the USB is attached properly, ask a neighbor or the teacher for help, make sure you're pairing your micro:bit correctly, update the firmware.)

U.S. Standards

  • CCSS-Math:MP.1
  • CCSS-ELA: 6-8.RST.3, 6-8.RST.4, 6-8.RST.7
  • CSTA: 2-AP-11, 2-AP-13, 2-AP-15, 2-AP-17
  • CS CA: 6-8.AP.11, 6-8.AP.13, 6-8.AP.15, 6-8.AP.16, 6-8.AP.17
  • ISTE: 1.c, 1.d, 4.d, 5.c, 5.d, 6.b

U.K. Standards

Key Stage 2 (Years 4-6)

  • Design, write and debug programs that accomplish specific goals, including controlling or simulating physical systems; solve problems by decomposing them into smaller parts.
  • Use logical reasoning to explain how some simple algorithms work and to detect and correct errors in algorithms and programs.
  • Understand computer networks, including the internet; how they can provide multiple services, such as the World Wide Web, and the opportunities they offer for communication and collaboration.
  • Use technology safely, respectfully and responsibly; recognise acceptable/unacceptable behaviour; identify a range of ways to report concerns about content and contact.

Key Stage 3 (Years 7-9)

  • Understand several key algorithms that reflect computational thinking [for example, ones for sorting and searching]; use logical reasoning to compare the utility of alternative algorithms for the same problem.
  • Create, re-use, revise and re-purpose digital artefacts for a given audience, with attention to trustworthiness, design and usability.
  • Understand a range of ways to use technology safely, respectfully, responsibly and securely, including protecting their online identity and privacy; recognise inappropriate content, contact and conduct and know how to report concerns.