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: Track and Field
Time: 45+ mins

Introduction

Get ready to exercise your body and mind! In this lesson, students will learn how to program their micro:bit into a helpful exercise tool that can track footsteps and time. Additionally, they'll learn how to display a clock timer animation. Note: The Pedometer (step counter) and Stopwatch projects from this lesson are intended to be used with a battery pack for the micro:bit.

New Code

  • accelerometer.get_x():This is an accelerometer function that returns the acceleration of an object moving horizontally (left and right).
  • accelerometer.get_y(): This is an accelerometer function that returns the acceleration of an object moving vertically (up and down).
  • accelerometer.get_z(): This is an accelerometer function that returns the acceleration of an object that's moving with depth (in the z-direction).
  • display.clear(): This is a function that clears all images and doesn't show anything on the micro:bit.

Vocabulary

  • Pedometer : A device that detects the number of footsteps taken
  • Stopwatch : A device that keeps track of time passed and has as a start/stop timer

Objectives

Students will...

  • Use the micro:bit to run coding examples
  • Apply coding concepts to create Pedometer and Stopwatch projects

Materials

  • micro:bit device (recommended 1 per student)
  • USB cable
  • Computers, laptops, or Chromebooks (1 per student) with student account access to Tynker.com
  • Optional: Battery pack
  • Optional: Tape, string, or safety pin to wear the micro:bit on clothing or shoes

Warm-Up (5 minutes)

  • Tell students that the micro:bit has a built-in accelerometer that detects motions such as shaking and tilting. Can anyone think of a situation when someone would want to use the device?
  • Explain that an accelerometer is often used in exercise to keep track of how many steps someone has walked. Can anyone think of other devices that use an accelerometer?

Activities (45 minutes)

Facilitate as students complete all Track and Field modules on their own:
1. Track and Field (Document)

  • Students will read a short document that introduces the lesson. They'll learn that today's activities include using the micro:bit's built-in accelerometer and time functions to create Pedometer (step counter) and Stopwatch projects.
  • Optional: Ask if anyone has used a pedometer before.
  • Students will learn that in this lesson, they'll build their own pedometer and stopwatch!
  • Explain that a pedometer detects steps, whereas a stopwatch keeps track of time.

2. Project 1: Pedometer (DIY)

  • In this module, students will learn how the micro:bit can detect and show acceleration measurements in three different directions.
  • Make sure students know the difference between the X,Y, and Z-axes relative to their movement:
    • X-axis: Horizontal (left-right) movement
    • Y-axis: Vertical (up-down) movement
    • Z-axis: Represents depth
  • Try It Out! Display Accelerometer Values
    • In this activity, students are encouraged to experiment with their code to get either Y or Z axis values.
    • Here's a list of the different functions students can use:

  • Coding Challenge, Step 1: Detecting Footsteps
    • To solve this challenge, students need to program their micro:bit to detect footsteps.
    • Make sure they read the requirements carefully:

    • If students are struggling, ask them to read the comments and determine what function they should use. For example, the "#sleep for a bit" comment indicates that the student should use a sleep() function.
    • Tell students that they'll expand on this project in the next module.

3. Counting Steps (DIY)

  • Coding Challenge, Step 2: Counting the Steps
    • Students will expand on their previous project by programming the micro:bit to track and display the user's total number of footsteps taken.
    • Remind students that in Python, the += operator adds to the variable.
    • Give a hint: Tell students to create a variable called steps and assign it a value of 0. They'll also need to display the steps variable using the display.scroll() function.

4. Gearing Up (DIY)

  • This module instructs students to experiment with their code as they test and debug their pedometer program.
    • Is the micro:bit falling off the student's clothing or shoes? Ask them to put the micro:bit inside their pocket or hold it in their hand.
    • Is the micro:bit adding too many steps? Try increasing the value that compares the Y-axis. For example, if the value is set to "1500", try setting it to "1600":

    • Is the micro:bit not counting enough steps? Try decreasing the value that compares the Y-axis. For example, if the value was set to "1500," try setting it to "1400":

5. Project 2: Stopwatch

  • In this module, students will learn how to display and record time using their micro:bit.
  • Explain to students that the running_time() function will return how much time has passed using milliseconds--not seconds.
  • Step 1: Starting the Timer
    • This section is mostly blank. Make sure students read the comments, coding tips, and criteria carefully.
    • Give a hint: Tell students to use a while not loop. Also make sure they're using the correct syntax for button A:

    • Tell students that they'll expand on this project in the next module

6. Finishing Touches (DIY)

  • Coding Challenge, Step 2: Final Touches
    • Students will expand on their previous project by programming the micro:bit to show the final time.
    • Give a hint: Tell students to use a display.show() function and include four parameters (i.e., image, wait, loop, delay).

7. Timing It (DIY)

  • This module instructs students to experiment with their code as they test and debug their stopwatch program.
  • Encourage students to compare the accuracy of their stopwatch to a timer on a phone or stopwatch. Which is more accurate?
  • Are students struggling to convert milliseconds to seconds? Ask them how many milliseconds are in one second. (Answer: 1000). Next, tell them to divide their final_time by 1000. Part of their solution might look like this:

8. Review

  • This module reviews the following:
    • The accelerometer.get_x() function returns the acceleration of an object moving horizontally (left and right).
    • The accelerometer.get_y() function returns the acceleration of an object moving vertically (up and down).
    • The accelerometer.get_z() function returns the acceleration of an object moving with depth.

9. Quiz (Multiple-choice)

  • Students will be asked 5 quiz questions to review concepts from this lesson.

Extended Activities (10 minutes)

Lead a discussion with your students:

  • What's the difference between a pedometer and stopwatch? (Answer: A pedometer detects steps, whereas a stopwatch keeps track of time.)
  • If your pedometer is adding too many steps, should you increase or decrease the value that compares the Y-axis? (Answer: Increase.)
  • How can using a pedometer help a person live a healthier lifestyle? (Answer: It can make them more aware of how inactive or active they are. They can also establish goals that challenge them to take a certain number of steps a day.)

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.