Getting Started with MicroPython and the SparkFun Inventor's Kit for micro:bit
Introduction to MicroPython
MicroPython is an open source interpreter for the Python programming language developed specifically for microcontrollers. In this experiment guide, we will show you how to get started using MicroPython with the popular micro:bit board and our SparkFun Inventor’s Kit for micro:bit.
When you’re done with this guide, you’ll have the know-how to start creating your own projects and experiments with MicroPython for micro:bit!
MicroPython is just an interpreter, so it does not include a space to write and edit code. Luckily, there is an editor we can use to write our Python code. Before you get started, you’ll need to download Mu. Mu is a simple code editor for beginners that runs on Windows, OSX, Linux and Raspberry Pi.
A major benefit of using MicroPython is the interactive REPL. REPL stands for Read-Evaluate-Print Loop, which is a very long way to say you can execute code live without compiling it first and then uploading it after.
The applications for Python are extensive, and the advantage to using Python over other programming languages include interacting with other languages and platforms, third-party modules, extensive support libraries, user-friendly data structures and, of course, it’s open source.
Some known issues with using Mu and micro:bit currently are not being able to import third-party modules, not being able to use interrupts, and not having a decent way to map numbers of one range to another. Since importing third-party modules is not supported, we will be copying and pasting the source code in the current Mu MicroPython file. As with learning any new language, Python requires time, patience, self-study and a lot of examples! Keep at it, and we will be here to help you along the way.
To download all of the files needed to follow along with all of the experiments, click the button below.
To use MicroPython with the micro:bit, there are a few different options.
- Code with Mu. Mu is used in this guide.
- Use the Online Python Editor
- uFlash for those users already running and familiar with Python 2.7 or 3.3+.
If you have never worked with electronics before, we recommend you be somewhat familiar with the concepts in the following tutorials:
- Voltage, Current, Resistance, and Ohm’s Law — The most basic concepts in electronics and electrical engineering. Get very familiar with these concepts, as they will be used throughout your electronics adventure.
- What is a Circuit? — In this guide, we will be building a variety of circuits. Understanding what that means is vital to understanding the Inventor’s Kit.
- How to Use a Breadboard — First time working with a breadboard? Please check out this tutorial! It will help you understand why the breadboard is great for prototyping and how to use one.