The Official BBC micro:bit User Guide
4/5
()
About this ebook
The go-to guide to getting started with the BBC micro:bit and exploring all of its amazing capabilities.
The BBC micro:bit is a pocket-sized electronic development platform built with education in mind. It was developed by the BBC in partnership with major tech companies, communities, and educational organizations to provide kids with a fun, easy, inexpensive way to develop their digital skills. With it, kids (and grownups) can learn basic programming and coding while having fun making virtual pets, developing games, and a whole lot more.
Written by internationally bestselling tech author Gareth Halfacree and endorsed by the Micro:bit Foundation, The Official BBC micro:bit User Guide contains what you need to know to get up and running fast with the BBC micro:bit. Learn everything from taking your first steps with the BBC micro:bit to writing your own programs. You'll also learn how to expand its capabilities with add-ons through easy-to-follow, step-by-step instructions.
- Set up your BBC micro:bit and develop your digital skills
- Write code in JavaScript Blocks, JavaScript, and Python
- Discover the BBC micro:bit’s built-in sensors
- Connect the BBC micro:bit to a Raspberry Pi to extend its capabilities
- Build your own circuits and create hardware
The Official BBC micro:bit User Guide is your go-to source for learning all the secrets of the BBC micro:bit. Whether you're just beginning or have some experience, this book allows you to dive right in and experience everything the BBC micro:bit has to offer.
Gareth Halfacree
Gareth Halfacree is a freelance technology journalist, writer, and former system administrator in the education sector. With a passion for open-source software and hardware, he was an early adopter of the Raspberry Pi platform and has written several publications on its capabilities and flexibility. He can be found on Mastodon as @ghalfacree@mastodon.social or via his website at freelance.halfacree.co.uk.
Read more from Gareth Halfacree
Get started with MicroPython on Raspberry Pi Pico: The Official Raspberry Pi Pico Guide Rating: 0 out of 5 stars0 ratingsThe Official Raspberry Pi Beginner's Guide: How to use your new computer Rating: 4 out of 5 stars4/5Raspberry Pi User Guide Rating: 4 out of 5 stars4/5
Related to The Official BBC micro:bit User Guide
Related ebooks
Raspberry Pi Projects For Dummies Rating: 5 out of 5 stars5/5Arduino Android Blueprints Rating: 0 out of 5 stars0 ratingsRaspberry Pi Robotics Essentials Rating: 0 out of 5 stars0 ratingsRaspberry Pi LED Blueprints Rating: 0 out of 5 stars0 ratingsElectronics For Dummies Rating: 0 out of 5 stars0 ratingsArduino Sketches: Tools and Techniques for Programming Wizardry Rating: 4 out of 5 stars4/5Raspberry Pi Blueprints Rating: 0 out of 5 stars0 ratingsRaspberry Pi IoT Projects: Prototyping Experiments for Makers Rating: 0 out of 5 stars0 ratingsInternet of Things with Intel Galileo Rating: 0 out of 5 stars0 ratingsCoding For Kids For Dummies Rating: 0 out of 5 stars0 ratingsProgramming the BBC micro:bit: Getting Started with MicroPython Rating: 0 out of 5 stars0 ratingsRaspberry Pi Projects for Kids Rating: 0 out of 5 stars0 ratingsArduino App Bluetooth Robotics Rating: 4 out of 5 stars4/5Arduino: A Quick-Start Beginner's Guide Rating: 4 out of 5 stars4/5Fun Games with Scratch 3.0: Learn to Design High Performance, Interactive Games in Scratch (English Edition) Rating: 0 out of 5 stars0 ratingsRaspberry Pi Projects for Kids - Second Edition Rating: 4 out of 5 stars4/5Let's Get Coding Rating: 0 out of 5 stars0 ratingsRaspberry Pi Home Automation with Arduino - Second Edition Rating: 0 out of 5 stars0 ratingsGetting Started with Raspberry Pi: Program Your Raspberry Pi! Rating: 4 out of 5 stars4/5Teaching Primary Programming with Scratch Pupil Book Year 6 Rating: 0 out of 5 stars0 ratingsElectronics For Kids For Dummies Rating: 5 out of 5 stars5/5Programming Arduino: Getting Started with Sketches, Third Edition Rating: 0 out of 5 stars0 ratingsArduino for Kids Rating: 0 out of 5 stars0 ratingsRaspberry Pi Computer Architecture Essentials Rating: 0 out of 5 stars0 ratingsLua Essentials: A Journey Through Code and Creativity Rating: 0 out of 5 stars0 ratingsGet Started With Arduino: Robots, Musical Instruments, Smart Displays and More Rating: 0 out of 5 stars0 ratingsArduino For Dummies Rating: 4 out of 5 stars4/5Tinkercad | Step by Step Rating: 0 out of 5 stars0 ratingsCode-It Workbook 4: Problem Solving Using Scratch Rating: 0 out of 5 stars0 ratings
Systems Architecture For You
CompTIA A+ CertMike: Prepare. Practice. Pass the Test! Get Certified!: Core 1 Exam 220-1101 Rating: 0 out of 5 stars0 ratingsSolution Architecture Foundations Rating: 3 out of 5 stars3/5AutoCAD 2023 : Beginners And Intermediate user Guide Rating: 0 out of 5 stars0 ratingsJavaScript Application Design: A Build First Approach Rating: 0 out of 5 stars0 ratingsDeveloping Solutions for Microsoft Azure AZ-204 Exam Guide: A comprehensive guide to passing the AZ-204 exam Rating: 0 out of 5 stars0 ratingsBlockchain Basics: A Non-Technical Introduction in 25 Steps Rating: 5 out of 5 stars5/5CompTIA ITF+ CertMike: Prepare. Practice. Pass the Test! Get Certified!: Exam FC0-U61 Rating: 0 out of 5 stars0 ratingsPlayStation 2 Architecture: Architecture of Consoles: A Practical Analysis, #12 Rating: 0 out of 5 stars0 ratingsCompTIA Network+ CertMike: Prepare. Practice. Pass the Test! Get Certified!: Exam N10-008 Rating: 0 out of 5 stars0 ratingsChatgpt | Generative AI - The Step-By-Step Guide For OpenAI & Azure OpenAI In 36 Hrs. Rating: 0 out of 5 stars0 ratingsLearn Git in a Month of Lunches Rating: 0 out of 5 stars0 ratingsLearning Ansible 2 - Second Edition Rating: 5 out of 5 stars5/5Software Architecture with Python Rating: 0 out of 5 stars0 ratingsDistributed Facts Device for Flow Controls Rating: 0 out of 5 stars0 ratingsAdvanced API Security: OAuth 2.0 and Beyond Rating: 0 out of 5 stars0 ratingsThe Ultimate Guide To Auto Cad 2022 3D Modeling For 3d Drawing And Modeling Rating: 0 out of 5 stars0 ratingsSOA Patterns Rating: 0 out of 5 stars0 ratingsArduino Projects For Dummies Rating: 3 out of 5 stars3/5Spring Batch in Action Rating: 0 out of 5 stars0 ratingsPSP Architecture: Architecture of Consoles: A Practical Analysis, #18 Rating: 0 out of 5 stars0 ratingsMastering Kubernetes Rating: 5 out of 5 stars5/5Learning Embedded Android N Programming Rating: 0 out of 5 stars0 ratingsWii Architecture: Architecture of Consoles: A Practical Analysis, #11 Rating: 0 out of 5 stars0 ratings.NET Core in Action Rating: 0 out of 5 stars0 ratingsVMware vSphere 6.x Datacenter Design Cookbook - Second Edition Rating: 0 out of 5 stars0 ratingsThe Construction Technology Handbook Rating: 0 out of 5 stars0 ratingsMicrosoft IIS 10.0 Cookbook Rating: 0 out of 5 stars0 ratings
Reviews for The Official BBC micro:bit User Guide
3 ratings1 review
- Rating: 5 out of 5 stars5/5The BBC micro:bit was created by the BBC in partnership with major tech companies, communities, and educational organizations to provide kids with a fun, practical, inexpensive way to learn programming.
Book preview
The Official BBC micro:bit User Guide - Gareth Halfacree
Introduction
EDUCATIONAL COMPUTING HAS a long and storied history, beginning with the adoption of mechanical calculators to aid with mathematics classes through to the early days of microcomputing with initiatives like the BBC Computer Literacy Project in the 1980s. As the cost of computers came down and their capabilities increased, schools around the world rapidly went from a single shared computer to entire rooms filled with computers, integrating them into lessons from languages and history to engineering and art.
Today many homes have a computer of their own, or in some cases more than one. While access to computers has increased, actually operating them brings with it a sense of being disconnected from their inner workings. The BBC Micro, the 1980s microcomputer designed by Acorn Computers and at the heart of the BBC Computer Literacy Project, loaded straight into a text-based programming language known as the Beginner’s All-Purpose Symbolic Instruction Code (BASIC) and invited experimentation; today, the majority of computers load into a graphical user interface (GUI) which emphasises the use of pre-written programs over creating your own.
The BBC micro:bit is designed to bring back the days of learning to write your own code on a low-cost, easily-understood platform. Designed to sit at the heart of an international computer literacy programme directly inspired by the BBC’s original Computer Literacy Project, the BBC micro:bit is an affordable microcontroller on which you can run your own programs to do everything from spell out your name or play a game to turn lights on and off or communicate via radio.
Schools around the world have begun to adopt the BBC micro:bit in their curricula, but it’s by no means exclusively for structured educational use. The device’s readily accessible nature means it can be used to teach programming and computing concepts to children of any age, its robustness and small size mean it’s extremely portable and well-suited to wearable projects, and its surprising power and flexibility mean that you’re unlikely to find yourself restricted by its capabilities even when using it at the heart of more complex projects.
Who This Book Is For
This book is written for anyone interested in working with the BBC micro:bit. You don’t need pre-existing knowledge of computers, electronics, or programming to be able to pick up a BBC micro:bit and get started.
All you need to get the most from this book is the ability to read and a willingness to learn. If you’ve used computers before, you’ll find that you are able to skim through some of the early chapters on general concepts. If you’ve used other microcontroller-based development boards, you can skip still more. If you’ve written your own computer programs, then you’ll find programming for the BBC micro:bit immediately familiar. And if you know your way around an electrical circuit, the later chapters should hold few surprises.
Whether you’re an existing user of the BBC micro:bit or a complete newcomer, this book aims to get you started on your journey with a minimum of fuss and maximum enjoyment.
What This Book Covers
The march of technology is constant, and the BBC micro:bit is no exception. This book has been written based on the most recent version of the BBC micro:bit hardware, revision 1.3b, but it is entirely applicable to all versions going back to the first prototype versions given to schools for testing purposes. Equally, it will remain applicable to all future revisions thanks to the sterling work of the Micro:bit Educational Foundation, which has been instrumental in the development of this book.
The software for the BBC micro:bit is, as with the hardware, under constant development. References to the software in this book are accurate at the time of writing, and all screenshots and related materials have been captured on the very latest software versions. Over time, small changes may be made to the way the software looks, but the way it works will remain the same.
This is especially important for the programs contained within the book. Although the languages available for the BBC micro:bit will expand over time and gain additional features, the existing features will always be available. A program taken from this book today will still be usable with the BBC micro:bit years down the line.
How This Book Is Structured
Part I, ‘An Introduction to the BBC micro:bit’, offers a guide to the hardware and how it works, step-by-step instructions on unpacking your first BBC micro:bit and exploring its sample program, and connecting the BBC micro:bit to your computer so you can load a program of your own. This section also contains a number of tips on working with the BBC micro:bit, including how to handle it to protect it against possible damage. Even if you’ve already worked with a BBC micro:bit, reading this section is well advised.
Part II, ‘Coding for the BBC micro:bit’, gets you started writing your own programs. You learn the languages available for the BBC micro:bit and how they differ, and you learn to write your own programs from a simple message scrolling across the BBC micro:bit’s display and reading from its various built-in sensors to writing a simple game.
There’s a chapter dedicated to each of the three main programming languages used with the BBC micro:bit: JavaScript Blocks, JavaScript, and Python. Each chapter is designed to be as close to identical to the others as possible, allowing you to quickly see how the process of writing each program differs between languages. You can use the comparison table at the start of the section to pick a favoured language and read only that language’s chapter, or you can work through all three chapters in turn to get a real feel for how each operates.
Part III, ‘Advanced BBC micro:bit Projects’, goes a step further, introducing the radio module with examples on communicating between individual BBC micro:bits and groups of BBC micro:bits without the need for wires. There’s also a chapter dedicated to using the BBC micro:bit with the popular Raspberry Pi educational single-board computer, extending the capabilities of both devices.
In addition, you learn how to add external components like switches and LEDs to the BBC micro:bit, building electronic circuits from basic components to further extend its functionality. There’s no soldering involved, and the circuits described are designed to be safe and accessible for even the youngest reader; they require only a small number of affordable electronic components.
You will now have a sound understanding of how the BBC micro:bit works, how to program it, and how to use it with other devices. You still won’t have reached the end of its capabilities, though, so the final chapter offers information on additional resources, including add-on hardware which can further increase the BBC micro:bit’s flexibility, and websites offering more project ideas and formal lesson plans for use in structured education.
Finally, the appendices have full program listings for every program mentioned in the book in all three languages, making it easy to type them in without getting distracted by comments and explanations of what each part of the program is doing. If you’d rather save your fingers, you can download the same program files from the book’s website at www.wiley.com/go/bbcmicrobituserguide. You’ll also find a pin-out diagram of the BBC micro:bit with a full list of its capabilities.
What You Need to Use This Book
Technically speaking, you can begin using this book even without a BBC micro:bit of your own; simulators allow you to write programs designed for the BBC micro:bit and see how they run even without loading them onto a physical BBC micro:bit. You’ll get the most from the book if you have at least one BBC micro:bit with which to experiment, however, along with a few extras detailed here.
To run the main program samples listed in this book, you need the following:
A BBC micro:bit
A fully-wired micro-USB cable
A computer running Microsoft Windows, Apple macOS, or Linux, with a free USB port
An up-to-date web browser and working Internet connection
For the radio programs included in Chapter 8, ‘The Wireless micro:bit’, you also need:
A total of three BBC micro:bits
To run the programs listed in Chapter 9, ‘The BBC micro:bit and the Raspberry Pi’, you need:
A Raspberry Pi Model B+, Raspberry Pi Model 2, Raspberry Pi Model 3, or Raspberry Pi Zero W
A micro-USB On-The-Go (OTG) adapter cable, if using the Raspberry Pi Zero W
To build the circuits detailed in Chapter 10, ‘Building Circuits’, you also need the following:
Wires with crocodile clip or 4mm banana plug connectors
A button or switch
An LED
A current-limiting resistor (see Chapter 10 for an explanation)
A potentiometer
These parts are readily available via the Internet or in high-street electronics component shops, and they can frequently be supplied by BBC micro:bit resellers alongside the BBC micro:bit itself.
Conventions
To help you get the most from the text and keep track of what's happening, we've used a number of conventions throughout the book.
Technical terms are presented in italic when they’re first used. The same applies to acronyms and initialisms, which are presented in full when first used and then in their abbreviated form.
Metric measurements are used throughout this book, with imperial measurements provided in brackets where appropriate.
When a line of code would extend past the border of the page, a ↩ symbol is printed. When you see this symbol, continue to type the code without pressing the Enter or Return keys. If you’re not sure how a line of code should be entered, visit the website at www.wiley.com/go/bbcmicrobituserguide to download plain-text versions of each program; these can then be used for reference or even simply copied and pasted directly into the editors.
Contact Me
Comments, corrections, and questions from readers are heartily welcomed via email at microbit@halfacree.co.uk, while other publications of mine can be found at freelance.halfacree.co.uk.
You can also get in touch with me via Twitter at twitter.com/ghalfacree and via encrypted message at keybase.io/ghalfacree.
Enjoy the book, and happy travels on your BBC micro:bit journey!
—Gareth Halfacree
Part I
An Introduction to the BBC micro:bit
Chapter 1 Meet the BBC micro:bit
Chapter 2 Getting Started the BBC micro:bit
Chapter 3 Programming the BBC micro:bit
Chapter 1
Meet the BBC micro:bit
In this chapter
check A look at what the BBC micro:bit is and how it came about
check A tour of the BBC micro:bit and an explanation of its major components
THE BBC MICRO:BIT is an incredible device, capable of educating and entertaining in equal measure. It can form the heart of a complex robotic or home automation system, or it can simply show a smiley face when you press a button. It can help you come to grips with programming, learn about how electronics work, and even communicate wirelessly with more BBC micro:bits or other devices such as a smartphone or tablet.
You can write programs for the BBC micro:bit in a variety of programming languages, or you can use programs others have written. You can use the BBC micro:bit in the classroom, the club, the playground, or at home. You can play games, solve problems, and invent new devices, all with your BBC micro:bit.
Before all this, though, you’ll need to meet the BBC micro:bit.
A Tour of the Board
The BBC micro:bit is what is technically known as a microcontroller development board. That is, it’s a printed circuit board (PCB) which contains a microcontroller on which you can run your own programs and connect your own hardware.
The first microcontroller development boards were expensive and complicated to use. In the decades since their first introduction, they have become steadily cheaper and more accessible, until the BBC micro:bit became possible: a minimal-cost, highly-functional board designed to help teach programming, or ‘coding’, to anyone regardless of experience.
Your programming journey begins simply: learning about the BBC micro:bit itself.
WARNING
The BBC micro:bit is designed to be robust, but it’s still a complex electronic device. It’s designed as a bare circuit board so that you can see what all its components are and what they do, but this does mean you need to take a little more care with handling it than if it were in an enclosure. Always make sure to handle it by its edges to avoid damage through electrostatic discharge. For more information on preventing electrostatic discharge damage, see Chapter 2, ‘Getting Started with the BBC micro:bit’.
The BBC micro:bit itself is a small printed circuit board with a range of components fitted. It has two sides: the front side of the BBC micro:bit includes the display and buttons, while the back side has components like the micro-USB connector and radio. Figure 1-1 shows the front side of the BBC micro:bit, and Figure 1-2 shows the back.
FIGURE 1-1: The front of the BBC micro:bit
FIGURE 1-2: The back of the BBC micro:bit
The BBC micro:bit includes a layer of print known as a silkscreen layer, which labels some of the more important components. The buttons on the front side are labelled A and B so you know which is which, while the back side picks out key components like the processor and the accelerometer. These components, and others, are described in more detail in the next section.
Breaking It Down
Like any complex device, the BBC micro:bit is made up of numerous relatively simple parts. From the more obvious, like the display which dominates the front of the board, to the more subtle, like the radio which allows two or more BBC micro:bits to communicate with each other or connect to a smartphone or tablet, each component works with the others to give the BBC micro:bit its impressive flexibility.
If you’re impatient to get started with your BBC micro:bit, you can skip ahead to Chapter 2. Reading the rest of this chapter, though, will give you a good understanding of just what the BBC micro:bit can do, putting you in good stead for not only learning how it works but coming up with practical projects of your own as your skills progress.
Display
The most obvious feature of the BBC micro:bit is its display, which sits in the centre of the board’s front side (see Figure 1-3). This is the BBC micro:bit’s primary output device, a means for a program running on the BBC micro:bit to communicate with the outside world—whether that’s reading off the position of one of the BBC micro:bit’s sensors or simply displaying a smiling face.
FIGURE 1-3: The BBC micro:bit’s display
The BBC micro:bit’s display serves the same purpose as the monitor on a desktop computer but is of a considerably lower resolution. Where a desktop monitor may be made up of 1,920 columns of 1,080 picture elements or pixels, the BBC micro:bit has just five columns of five picture elements for a total of 25 pixels.
Although 25 pixels may not sound like much, it’s more than enough to view useful information such as a bar graph or the elements of a simple game or to scroll messages of almost any length. You’ll learn more about using the display for these tasks and more later in the book.
From a technical perspective, the BBC micro:bit’s display is made up of a 5 × 5 light emitting diode (LED) matrix. Each LED in the matrix makes up one pixel and can display a single colour in varying brightnesses. By altering the brightness and rapidly changing the image being shown, the BBC micro:bit’s display can show animation as well as still images.
Buttons
Next to the display, the buttons are the BBC micro:bit’s second most obvious feature. The two main buttons, Button A and Button B, are positioned either side of the display at the front of the board and are labelled with their letter to avoid any confusion (see Figure 1-4). These two buttons form the BBC micro:bit’s primary input devices. Where the display allows information to be output from a program running on the BBC micro:bit, the buttons allow you to send simple inputs into the program to change the image being displayed, for example, or control a character in a game.
FIGURE 1-4: The BBC micro:bit’s Button A and Button B
These buttons are technically known as a momentary switch. These are different to the switches you might use to turn on a light, which are known as latching switches or toggle switches. A momentary switch stays ‘on’ only as long as you continue to push it down, while a latching switch goes from ‘off’ to ‘on’ and stays there until you push it again.
Although the buttons are permanently connected to the BBC micro:bit, they won’t do anything unless the program running on the BBC micro:bit is listening for a button input. Depending on what you’re using the BBC micro:bit for, you may want to use only one or even neither of the two buttons; alternatively, you may find you need more buttons, in which case the input-output pins will help you expand the BBC micro:bit.
In addition to Button A and Button B, there’s a third button on the back of the BBC micro:bit: the Reset button. Like the Reset button of a desktop computer, the BBC micro:bit’s Reset button acts like cutting the power. Whatever the BBC micro:bit is doing at the time will be interrupted, and the BBC micro:bit will restart and begin its stored program again from the start. The Reset button is useful when experimenting with programs that may cause the BBC micro:bit to stop responding, but be careful not to press it accidentally when you’re in the middle of something. There are other uses for the Reset button, too, which will be explained in later chapters.
Processor
The processor is often called the ‘brain’ of a computer, and the BBC micro:bit’s processor—technically known as a microcontroller—is no exception. Found on the upper-left of the rear of the BBC micro:bit and labelled on the board’s silkscreen layer, the processor is a tiny black square no bigger than your little fingernail called an integrated circuit (see Figure 1-5).
FIGURE 1-5: The BBC micro:bit’s processor
Despite its small size, this integrated circuit is surprisingly complex. It’s here that any program the BBC micro:bit is using is both stored and run. While in a desktop computer, memory, storage, and the central processing unit are all separate, the BBC micro:bit’s processor is all-in-one; this is known as a system-on-chip (SoC).
The BBC micro:bit’s processor uses a special set of instructions, known as an instruction set architecture, called the ARM Architecture. Named for the company which invented it, ARM processors are designed to offer high performance at the lowest possible power usage. The BBC micro:bit uses this to great effect: It’s possible to run the BBC micro:bit for months when using the recommended batteries.
For those interested in the technical side, the BBC micro:bit’s processor is a Nordic nRF51822, which contains a single-core ARM Cortex-M0 running at 16Mhz, with 16 KB of random access memory (RAM) and 256 KB of non-volatile memory (NVM) for program storage.
The BBC micro:bit also has a second processor, not labelled on the silkscreen and found at the upper-right of the board. When you connect the BBC micro:bit to your computer using a micro-USB cable, as described in Chapter 3, ‘Programming the BBC micro:bit’, this second processor takes over and handles communication with your computer, accepting new programs and transferring them to the main processor to run.
Radio
A major feature of the BBC micro:bit is its radio, which allows it to communicate with other BBC micro:bits or with other devices, such as a smartphone or tablet. The radio itself is a part of the BBC micro:bit’s main processor, forming a segment of the system that makes up the system-on-chip design. As a result you won’t find it labelled on the silkscreen as with other components, but instead covered under the ‘PROCESSOR’ label.
The BBC micro:bit’s radio has two main functions. The first function is to communicate with other BBC micro:bits wirelessly, allowing you to group multiple BBC micro:bits without having to string cables between them. The second function is to communicate with other devices, which it does using Bluetooth Low Energy (BLE), a low-power version of the popular Bluetooth wireless standard built into most modern smartphones and tablets.
Unlike the type of radio you might use to listen to music, there’s no external antenna for the BBC micro:bit’s radio chip. Instead, it uses a cleverly-shaped copper track built into the circuit board itself. You can find this at the upper-left on the rear of the BBC micro:bit, labelled ‘BLE ANTENNA’ (see Figure 1-6). It doesn’t look like much, but if you hold it to the light, you should be able to see a raised line tracing a series of rectangular shapes—providing, that is, the antenna isn’t covered by regulatory compliance stickers required of all radio transmitters in selected countries.
FIGURE 1-6: The BBC micro:bit’s radio antenna
Accelerometer
One of two built-in sensors, the BBC micro:bit’s accelerometer is an integrated circuit even smaller than the processor chips (see Figure 1-7). It’s so small that if it weren’t labelled on the board’s rear silkscreen, it’d be easy to overlook it. Despite its small size, this chip is extremely clever: it knows exactly how the BBC micro:bit is positioned in space at any given time.
FIGURE 1-7: The BBC micro:bit’s accelerometer
When you rotate your smartphone from portrait to landscape and vice versa, it’s an accelerometer that tells the device what you’ve done and allows it to automatically rotate the screen. The BBC micro:bit’s accelerometer works in the same way: it can track the angle of the device in all three axes—sideways, backward and forward, and up and down, or X, Y, and Z—by tracking what is known as proper acceleration.
The accelerometer can be seen in action during the BBC micro:bit’s demonstration program, which is explored in Chapter 2.
Compass
The second of the BBC micro:bit’s two built-in sensors, the compass, works roughly like the navigational tool of the same name: the compass will detect magnetic north and point you in that direction. If you’re building a robot, for example, the compass is a reliable method of navigating between points. As with the accelerometer, the compass is a tiny and easily-overlooked integrated circuit on the rear of the device and is labelled on the silkscreen (see Figure 1-8).
FIGURE 1-8: The BBC micro:bit’s compass
Like a traditional needle-based compass, the BBC micro:bit’s compass works by sensing magnetic fields. As a result, it has a second trick up its sleeve: the ability to detect magnetic fields other than the Earth’s natural ones. Using this chip, the BBC micro:bit can not only point the way north but can also indicate the strength of a local field’s magnetic force—and even detect metal. As it works by detecting these magnetic fields, however, this means that nearby magnets—such as those found in speakers—can affect the sensor’s accuracy when used as a compass.
Input-Output Pins
The BBC micro:bit has room for expansion in the form of input-output pins located on the bottom edge (see Figure 1-9). These aren’t literally pins but strips of copper on both sides of the BBC micro:bit’s printed circuit board; the term ‘pin’ is a technical term referring not to the connections themselves but to the ‘pin’ of the processor to which the connections are linked.
FIGURE 1-9: The BBC micro:bit’s input-output pins
The five largest pins, sometimes referred to as pads or rings in reference to their shape, are labelled on the front of the board: 0, 1, 2, 3V, and GND. The first three are the BBC micro:bit’s major input output pins themselves, while the latter two provide power and a ground connection to