Programming the BBC micro:bit: Getting Started with MicroPython

Programming the BBC micro:bit: Getting Started with MicroPython

by Simon Monk

Paperback(Student)

$13.91 $15.00 Save 7% Current price is $13.91, Original price is $15. You Save 7%.
View All Available Formats & Editions
Choose Expedited Shipping at checkout for guaranteed delivery by Friday, November 15

Overview

Publisher's Note: Products purchased from Third Party sellers are not guaranteed by the publisher for quality, authenticity, or access to any online entitlements included with the product.




Quickly write innovative programs for your micro:bit—no experience necessary!


This easy-to-follow guide shows, step-by-step, how to quickly get started with programming and creating fun applications on your micro:bit.. Written in the straightforward style that Dr. Simon Monk is famous for, Programming the BBC micro:bit: Getting Started with MicroPython begins with basic concepts and gradually progresses to more advanced techniques. You will discover how to use the micro:bit's built-in hardware, use the LED display, accept input from sensors, attach external electronics, and handle wireless communication.
•Connect your micro:bit to a computer and start programming!
•Learn how to use the two most popular MicroPython editors
•Work with built-in functions and methods—and see how to write your own
•Display text, images, and animations on the micro:bit’s LED matrix
•Process data from the accelerometer, compass, and touch sensor
•Control external hardware by attaching it to the edge connector
•Send and receive messages via the built-in radio module
•Graphically build programs with the JavaScript Blocks Editor

Product Details

ISBN-13: 9781260117585
Publisher: McGraw-Hill Professional Publishing
Publication date: 11/20/2017
Edition description: Student
Pages: 176
Sales rank: 880,792
Product dimensions: 7.00(w) x 9.00(h) x 0.38(d)

About the Author

Simon Monk (Preston, UK) has a bachelor’s degree in cybernetics and computer science and a Ph.D. in software engineering. He has authored more than 25 books, including Programming Arduino, 30 Arduino Projects for the Evil Genius, Hacking Electronics, and Fritzing for Inventors. Dr. Monk also runs the website monkmakes.com, which features his own products.

Table of Contents

Acknowledgments x

1 Introduction 1

Plug Me In! 1

History 3

What Can It Do? 4

Micro: bit versus Raspberry Pi and Arduino 5

So What Is Programming? 7

Why MicroPython? 8

Summary 8

2 Getting Started 9

MicroPython Editors 9

Online Editor 10

Installing micro: bit Programs Using Windows 11

Installing micro: bit Programs Using a Mac 13

Installing micro: bit Programs Using Linux 14

Saving and Loading Programs 17

The Mu Editor 17

Installing Mu on Windows 18

Installing Mu on a Mac 19

Installing Mu on Linux 19

Using Mu 19

The REPL 21

Downloading This Book's Programs 23

Summary 24

3 Micro Python Basics 25

Numbers 25

Variables 27

Strings 28

Converting Numbers to Strings 29

Programs 30

Looping Forever 31

For Loops 33

Ifs and elses 34

More on while 35

Timer Example 36

Summary 37

4 Functions 39

What Are Functions? 39

Parameters 40

Global Variables 42

Return Values 43

Advanced Parameters 44

Summary 44

5 Lists and Dictionaries 45

Lists 45

Message Board Examplep 45

The Lowdown on Lists 48

Accessing Elements of a List 48

Adding to a List 49

Deleting from a List 49

Joining Lists Together 50

Strings as a List of Characters 50

Dictionaries 51

An Example 51

Dictionaries in Detail 53

Accessing Elements of a Dictionary 53

Adding Items to a Dictionary 54

Summary 54

6 Writing Your Own Programs 55

Writing Software 55

Keep It Simple 55

Spikes and the REPL 56

Versioning 56

Comments 57

Refactoring 57

State Machine Design 59

Revisiting the Timer Example 61

A State Machine Framework 61

Switching Between States 62

Adding Code to the set State 63

Adding Code for the run State 63

Adding Code for the ALARM State 65

Debugging 66

More Python 67

Formatting 67

Exception Handling 68

File System 69

Summary 71

7 Modules and Classes 73

Built-in Modules 73

Importing Modules 74

Classes and Instances 75

Inheritance 76

Making Simple Modules 78

Making a Module That Uses a Class 80

Module and Class Definition 81

Methods 81

Using the Module 83

Modules from the Community 83

Summary 83

8 The LED Display 85

Controlling Individual LEDs 85

Scrolling Text 87

Showing Text 88

Showing an Image 88

Animation 89

Racing Game 91

Summary 93

9 Micro: bit Sensors 95

Buttons Revisited 95

Gestures? 96

Raw Accelerometer Data 96

Magnetometer 99

Processor Temperature1 102

Touch 102

Summary 104

10 Connecting Electronics 105

Battery Power 105

USB Power Pack 105

3 V Battery Pack 107

Battery Life 107

Micro: bit Operating Voltage 108

GPIO Pins 0, and 2 108

Alligator Clip Leads 109

Digital Outputs 110

Analog Outputs 113

Digital Inputs 115

Analog Inputs 115

Power Out 119

Sound Output 120

Alligator Clip to Audio Socket 120

Amplifier Modules 121

Updating the Alarm Project 121

Music 123

Speech 124

Neopixels 124

The Edge Connector 126

Pinout 127

Breakout Boards and Kits 128

Disabling Hardware 129

Summary 129

11 Radio and Communications! 131

Basic micro; bit-to-micro: bit Communication 131

Messaging Different Users 132

Advanced Radio Settings 134

Computer-to micro: bit Communication 135

Remote Control of Your micro: bit Using Python 136

Python on Your Computer 137

Getting Bitio 137

Installing the Resident Program 137

Using Bitio from the Console 137

Summary 139

12 JavaScript Blocks Editor 141

The Editor 141

Getting Started 142

Events 144

Variables and Loops 144

Magnetometer Example 147

Summary 147

A Micro Python Reference 149

Language Contructs 149

Comparisons 150

Numbers 151

Strings 151

Lists 153

Dictionaries 154

Type Conversions 155

B Hardware 157

Micro: bit Edge Connector Pinout 157

Suppliers and Manufacturers 158

Components 158

Hardware 158

Kits! 159

Basic Components 159

Modules and Expansion Boards 160

Index 161

Customer Reviews

Most Helpful Customer Reviews

See All Customer Reviews