Skip to content

Latest commit

 

History

History
345 lines (253 loc) · 7.58 KB

File metadata and controls

345 lines (253 loc) · 7.58 KB

micro:bit Setup Guide (MicroPython)

Complete guide for physical computing with micro:bit boards (weeks 19-24).

What is micro:bit?

  • Small programmable computer (5cm × 4cm)
  • Has LEDs, buttons, sensors (accelerometer, compass)
  • Runs MicroPython (special Python for microcontrollers)
  • Perfect for physical computing projects

Hardware Needed

Essential (per student):

  • 1× BBC micro:bit v1 or v2 (v2 recommended)
  • 1× USB cable (micro-USB for v1, USB-C for v2)
  • Computer with USB port

Optional (for advanced weeks):

  • Battery pack (2× AAA)
  • Crocodile clips (for Week 22 pins)
  • Buzzer, LED, servo (Week 22)
  • 2nd micro:bit (Week 23 radio)

Where to Buy:

  • Official: microbit.org/buy
  • Amazon, Adafruit, SparkFun
  • Cost: $15-25 per board

Option A: Mu Editor (RECOMMENDED)

Mu is designed specifically for micro:bit programming.

Installation:

macOS:

# Download from codewith.mu
# Or use Homebrew:
brew install --cask mu-editor

Windows:

  1. Visit: https://codewith.mu/
  2. Download installer
  3. Run installer
  4. Allow in Windows Security if prompted

Linux:

pip3 install mu-editor

First Steps with Mu:

  1. Connect micro:bit

    • Plug micro:bit into USB port
    • Should show up as "MICROBIT" drive
  2. Open Mu

    • Click "Mode" button
    • Select "BBC micro:bit"
  3. Write code:

    from microbit import *
    display.scroll("Hello!")
  4. Flash to micro:bit

    • Click "Flash" button
    • Wait for yellow LED on micro:bit to stop flashing
    • Message appears on LED display!
  5. Success! ✅ You're ready for Week 19!


Option B: Online Editor (No Installation)

If installation is difficult, use browser-based editor.

Method 1: Official micro:bit Python Editor

  1. Visit: https://python.microbit.org/v/3
  2. Write code in browser
  3. Click "Download" button
  4. Drag downloaded .hex file to MICROBIT drive
  5. Code runs on micro:bit!

Method 2: MakeCode (Block/JavaScript)


Option C: Simulator Only (No Hardware)

If micro:bit devices unavailable:

Online Simulator:

  • python.microbit.org has built-in simulator
  • Test code without hardware
  • Shows LED display, button presses
  • Limitation: No real sensor data, can't feel physical interaction

Classroom Strategy:

  • Students write code, teacher demos on ONE physical micro:bit
  • Rotate hardware between students
  • Works but less engaging than 1:1

Flashing Code to micro:bit

Understanding .hex Files:

  • MicroPython code compiles to .hex file
  • This is the "compiled" version for micro:bit
  • Drag .hex to MICROBIT drive to upload

Step-by-Step:

  1. Write code in Mu or online editor
  2. Click "Flash" (Mu) or "Download" (online)
  3. File saves as microbit-xxx.hex
  4. Drag file to MICROBIT drive
  5. Yellow LED flashes (uploading)
  6. micro:bit resets and runs code

Troubleshooting Flashing:

  • micro:bit not showing as drive: Try different USB cable (some are charge-only)
  • Error on flash: Reset micro:bit (button on back)
  • Code doesn't run: Check for syntax errors
  • Partial upload: Wait for yellow LED to stop completely

Testing Your Setup

Test 1: Hello World

from microbit import *
display.scroll("Hello World!")

Expected: Text scrolls across LED display

Test 2: Buttons

from microbit import *

while True:
    if button_a.was_pressed():
        display.show(Image.HAPPY)
    if button_b.was_pressed():
        display.show(Image.SAD)
    sleep(100)

Expected: Press A = smiley, Press B = sad face

Test 3: Shake Sensor

from microbit import *

while True:
    if accelerometer.was_gesture('shake'):
        display.show(Image.SURPRISED)
        sleep(1000)
        display.clear()

Expected: Shake micro:bit = surprised face

If all 3 work: ✅ Setup complete!


MicroPython vs Regular Python

Same Concepts:

  • Variables, loops, if/else, functions
  • Lists, strings, numbers
  • All Python basics from weeks 1-6 work!

Different:

  • from microbit import * (special import)
  • display.show() instead of print()
  • Hardware-specific: buttons, LEDs, sensors
  • Some libraries unavailable (no Pygame, Turtle)

Week 19-24 Focus:

  • Input: Buttons, sensors, pins
  • Processing: Python logic (same as always!)
  • Output: LEDs, display, music, pins

Classroom Setup Tips

For 10-30 Students:

  1. Check all USB cables

    • Test each cable (some are broken)
    • Label working cables
  2. Pre-flash test program

    • Flash "Hello" program to all micro:bits
    • Confirms all working before lesson
  3. Charging strategy

    • Battery packs for portable projects
    • USB for development/testing
  4. Pairing if using radio (Week 23)

    • Set same radio group number
    • Test in pairs before full class
  5. Backup computers

    • Online editor as fallback
    • Guest accounts ready

Common Issues & Solutions

Issue: micro:bit not detected

macOS:

  • System Settings → Privacy & Security → Files and Folders
  • Allow Terminal/Mu to access removable volumes

Windows:

  • Device Manager → check for "MICROBIT" under Portable Devices
  • Update drivers if needed

Solution: Try different USB port, restart computer


Issue: Code has errors but hard to see

Mu Editor:

  • Click "Check" button (shows Python errors before flashing)
  • Read error messages carefully

Common errors:

# Wrong:
from Microbit import *  # Capital M
while true:             # lowercase true

# Correct:
from microbit import *  # lowercase m
while True:             # Capital T

Issue: Code runs once then stops

Cause: No loop!

# Runs once:
display.show(Image.HEART)

# Runs forever:
while True:
    if button_a.was_pressed():
        display.show(Image.HEART)

Issue: Buttons don't respond

Solution: Use was_pressed() not is_pressed()

# Better:
if button_a.was_pressed():  # Detects button press event
    do_something()

# Works but tricky:
if button_a.is_pressed():   # Checks if currently held
    do_something()

Week-by-Week Hardware Needs

Week Hardware Needed Can Use Simulator?
19 micro:bit only ✅ Yes
20 micro:bit only ✅ Yes (limited)
21 micro:bit only Partial (no real sound)
22 + LED, buzzer, clips ❌ No (needs hardware)
23 2× micro:bits ❌ No (needs radio)
24 Depends on project Varies

Resources

Official Documentation:

Mu Editor:

Online Editor:

Community:

  • micro:bit Discord
  • micro:bit subreddit (r/microbit)

Safety Notes

For Week 22 (Pins & External Components):

  • Never connect 3V to GND directly (short circuit!)
  • Use correct resistors for LEDs (150-330Ω)
  • External power for servos (don't power from micro:bit)
  • Adult supervision for soldering
  • Crocodile clips safer than breadboard for beginners

Battery Safety:

  • Use AAA batteries only (not 9V or lithium)
  • Remove batteries when not in use
  • Don't mix old and new batteries

Success Checklist

Before Week 19:

  • micro:bit hardware acquired
  • Mu editor installed OR online editor tested
  • Can flash code to micro:bit
  • Test programs work (Hello, buttons, shake)
  • USB cables tested and working
  • Backup plan ready (simulator/sharing devices)

If all checked: ✅ Ready for weeks 19-24 - physical computing!