BBC Micro:bit

1. What is Micro:bit?

Micro:bit is an open source hardware platform based on the ARM architecture launched by British Broadcasting Corporation (BBC) together with ARM, Barclays, element14, Microsoft and other institutions. The core device is a 32-bit Arm Cortex-M4 with FPU micro-processing.

Though it is just the size of a credit card, the Micro:bit main board is equipped with loads of components,including a 5*5 LED dot matrix, 2 programmable buttons, an accelerometer, a compass, a thermometer, a touch-sensitive logo and a MEMS microphone, a Bluetooth module of low energy, and a buzzer and others. Thus, it also boasts multiple functions.

The buzzer built in the other side of the board plays all kinds of sounds without any external equipment. The golden fingers and gears provide a better fixing of crocodile clips. Moreover, this board has a sleeping mode to lower power consumption of batteries when users long-press the Reset & Power button on the back. It is capable of reading the data of sensors, controlling servos and RGB lights, and it is attaching with a shield so as to connect with various sensors. It also supports a variety of programming platforms and is compatible with almost all PCs and mobile devices. Also, driver is required. It is of high integration of electronic modules, and has a serial monitoring function for easy debugging.

The board has found wild applications. It can be applied in programming video games, making interactions between light and sound, controlling a robot, conducting scientific experiments, developing wearable devices. Basically, it always be utilized to make some cool inventions like robots and musical instruments.


1.1 Micro:bit V2 Mainboard Layout

img


1.2 Micro:bit V2 Pin-out

img

Micro:bit pin functions:

Function

Pin

GPIO

P0, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10,
P11, P12, P13, P14, P15, P16, P19, P20

ADC/DAC

P0, P1, P2, P3, P4, P10

IIC

P19(SCL), P20(SDA)

SPI

P13(SCK), P14(MISO), P15(MOSI)

PWM(commonly used)

P0, P1, P2, P3, P4, P10

PWM(uncommonly used)

P5, P6, P7, P8, P9, P11, P12, P13,
P14, P15, P16, P19, P20

occupied

P3(LED Col3), P4(LED Col1), P5(Button A), P6(LED Col4),
P7(LED Col2), P10(LED Col5), P11(Button B)

Visit the official website for more details:

Microbit hardware

https://microbit.org/guide/hardware/pins/


1.3 Notes for the Application of Micro:bit

  • It is recommended to cover it with a silicone protector to prevent short circuit for it has a lot of sophisticated electronic components.

  • Its IO port is very weak in driving since it can merely handle current less than 300mA. Therefore, do not connect it with devices operating in large current, such as servo MG995 and DC motor or it will get burnt. Furthermore, you must figure out the current requirements of the devices before you use them and it is generally recommended to use the board together with a Micro:bit shield.

  • It is recommended to power the main board via the USB interface or via the battery of 3V. The IO port of this board is 3V, so it does not support sensors of 5V. If you need to connect sensors of 5 V, a Micro: Bit expansion board is required.

  • When using pins(P3, P4, P6, P7 and P10)shared with the LED dot matrix, blocking them from the matrix or the LEDs may display randomly and the data about sensors connected maybe wrong.

  • Pin 19 and 20 can not be used as IO ports though the Makecode shows they can. They can only be used as I2C communication.

  • The battery port of 3V cannot be connected with battery more than 3.3V or the main board will be damaged.

  • Forbid to operate it on metal products to avoid short circuit.

To put it simple, Micro:bit V2 main board is like a microcomputer which has made programming at our fingertips and enhanced digital innovation. And as for programming environment, BBC provides a website: https://microbit.org/code/, which has a graphical MakeCode program easy for use.


2. Micro:bit Installation

Micro:bit is free of driver installation. However, in case your computer fail to recognize the main board, you can install the diver too.

Driver installation: Please download tutorials in network disk.

Connect micro:bit mainboard to computer via USB cable.

img

Click the dirver file img and “Install”.


img


Click Install.

img


Click “Install” and “Finish”.

img


img


Click “Computer” —> “Properties” —> “Device manager”:

img


3. Programming

The following instructions are applied for Windows system but can also serve as a reference if you are using a different system.

3.1 Procedures

This chapter describes how to write program and load the program to the Micro: Bit mainboard. Visit official website for more details: https://microbit.org/guide/quick/

3.1.1 Step 1: Connect to Micro:bit

Connect the board to computer via USB cable.

For how to program via mobile deveices: https://microbit.org/get-started/user-guide/mobile/

Multiple operation systems are compatible with this board, including Macs, PCs, Chromebooks and Linux (Raspberry Pi).

img


If the red LED on the back of the board is on, that means the board is powered. When your computer communicates with the main board via the USB cable, the yellow LED on it will flashes. For example, it will flash when you burn a “hex”file.

Then Micro: bit main board will appear on your computer as a driver named “MICROBIT(E:)”. Please note that it is not an ordinary USB disk as shown below.

img


3.1.2 Step 2: Write programs

Online version of Makecode: https://makecode.microbit.org/

Click New Project;

The dialog box Create a Project appears, fill it with heartbeat and click Create √ to edit.

If you are Windows 10 system, it is also viable to edit on the APP MakeCode for micro:bit , which is exactly like editing in the website.

Windows 10 App download: https://www.microsoft.com/

Here we demonstrate on Google Chrome.

img

img


Write a micro:bit code.

You can drag some Blocks to the editing area and then run your program in Simulator as shown below: we demonstrate how to edit heartbeat program .

img


Click “ JS JavaScript” to check JavaScript language.

img


Click the arrow to switch to “Python” language.

img


3.1.3 Step 3: Download code

If your computer is Windows 10 and you have downloaded the APP MakeCode, what you will only have to do is to download the program to your Micro: Bit board.

If you are writing program through the website, following these steps:

  1. Click the ‘Download’ in the editor to download a “hex” file, which is a compact program format for Micro: Bit to read;

  2. Copy the “hex” file to your board. For Windows, you can also click and select ‘Send to → MICROBIT(E:) ‘to copy the hex file to the Micro: Bit board.

img

img


Or, you may directly drag the “hex” file in MICROBIT.

img

img

During the process of copying the hex file to the Micro: bit, the yellow LED on the back of the board flashes. When the duplication is completed, the LED will stop flashing and remain on.


3.1.4 Step 4: Run program

After the program is uploaded to the Micro: bit, you can power it via USB cable or an external power. Then the 5 x 5 LED dot matrix displays a heartbeat pattern.

Power via USB

Power via external 3V

img

img

Caution:

  • When you programs each time, the driver of Micro: bit will automatically eject and return so the hex files will disappear.

  • The board only has access to hex files rather than save them.


3.1.5 Other programming languages

This chapter has described how to use the Micro:bit main board.

Except for the Makecode graphical programming, if you want to write Micro:bit programs in other languages, visit https://microbit.org/code/ to learn more, or visit https://microbit.org/projects/ to find something you want to have a go.


3.2 Makecode

Google Chrome online version: https://makecode.microbit.org/

Or open the Windows 10 App makecode.

img


Click “New Project” and enter “heartbeat” to edit the code. Here is the main interface of Makecode.

img

There are blocks“on start”and“forever”in the code editing area.

When the power is plugged or reset, “on start” means that the code in the block only executes once, while “forever” implies that the code runs cyclically.


3.3 Quick Download

As mentioned before, if your computer is Windows 10 and you have downloaded the APP MakeCode. you can quickly download codes to the Micro: Bit main board by selecting ‘Download’.

While it is a little more trickier if you are using a browser to enter Makecode. However, if you adopt Google Chrome that is suitable for Android, ChromeOS, Linux, macOS and Windows 10, the process can be easier, too.

We use the webUSB of Chrome to access the hardware device connected by USB.

You could refer to the following steps to connect and pair devices.

Devices Pairng

Connect the board to computer via USB cable.

img


Click “…” and “Connect device”.

img


“Next”.

img


“Next”.

img


Then select the corresponding device and click “Connect”. If no device shows up for selection, please refer to: https://makecode.microbit.org/device/usb/webusb/troubleshoot

If the links are too troublesome, we also provide Troubleshooting(6. Troubleshooting) in tutorial.

For how to update micro:bit firmware: https://microbit.org/guide/firmware/

img


Click “Done”.

img

img


Download program

After connection, click img and it will change into img.

img


3.4 Makecode Extension Library

3.4.1 Add library

Please follow the steps to add extension files:

Open makecode to enter a certain project, click the gear-shaped icon(settings) in the upper right corner to choose “Extensions”.

img


Or click Advanced to add Extensions.

img


Search the library you want.

img


For instance, a servo library is required, so you can search “servo” to add one.

img


Back to the interface and you can see a Servos library.

img


3.4.2 Update/Delete library

Click Js JavaScript to switch to text code.

img


Click Explorer.

img


Find the lirary you want to remove and click to delete it.

img


Click Remove it.

img


Click Blocks to return to graphical programming.

img

img


3.5 Resources and Test Code

Download: https://fs.keyestudio.com/KS0801

3.5.1 Import code

We provide hexadecimal code files (project files) for each project. The file contains all the contents of the project and can be imported directly, or you can manually build the code blocks.

For simple projects, dragging a block of code to complete the program is recommended.

For complex ones, it is recommended to conduct the program by loading the hex code files.

Let’s take the “Heatbeat” project as an example to show how to load the code. Open the Web version of Makecode or the Windows 10 App Makecode, and click “Import”.

img


Click “Import File…”.

img

img

Choose “Heart beat.hex”.

img

img


In addition to the above method, you can also drag the the test code into the code editing area, as shown below:

img


Wait for loading.

img


3.5.2 Install CoolTerm

If your computer is Win7/8, the pairing cannot be done via Google Chrome. Therefore, digital signal or analog signal of sensors and modules cannot be shown on the serial simulator. So what can we do? CoolTerm software is a nice choice to read the serial data.

CoolTerm download: https://freeware.the-meiers.org/

  1. We take PC Windows as an example to download and unzip CoolTerm Win, and Mac/Linux can take it as a referance.

img


  1. Make sure the driver is connect to computer, and click to execute the software.

img


  1. The functions of each button on the Toolbar are listed below:

img

Icon

Function

img

Opens up a new Terminal

img

Opens a saved Connection

img

Saves the current Connection to disk

img

Opens the Serial Connection

img

Closes the Serial Connection

img

Clears the Received Data

img

Opens the Connection Options Dialog

img

Displays the Terminal Data in Hexadecimal Format

img

Displays the Help Window


4. Micro:bit Basic Projects

Project 1: Heartbeat

img

1. Introduction

This project is easy to conduct with a micro:bit main board, a Micro USB cable and a computer. The micro:bit LED dot matrix will display a beating heart. It serves as a start for your entry to the programming world!

2. Components

Micro:bit mainboard *1

img

Micro USB cable*1

img

3. Connection

Connect the board to your computer via micro USB cable.

img

4. Test Code

Please check code in Project 1 file.

imgimg

Visit https://makecode.micro:bit.org/reference to find more information about micro: bit blocks.

Visit https://makecode.micro:bit.org/ for programming helps.

Find code blocks:

img

Build blocks:

img

Click “JSJavaScript” to see Java code:

img

Pull down to click “Python” to see Python code:

img

5. Test Result

After uploading test code to micro:bit main board and keeping the connection with the computer to power the main board, the LED dot matrix shows pattern img and img, alternately.

upload the code to the development board

If the downloading is not smooth, please remove the USB cable from the main board and then reconnect them and reopen Makecode to try again.


Project 2: Single LED Blinking

img

1. Introduction

In this project, we intend to control a certain LED of the micro:bit main board to light up.

2. Components

Micro:bit mainboard *1

img

Micro USB cable *1

img

3. Connection

Connect the board to your computer via micro USB cable.

img

4. Knowledge

The LED dot matrix consists of 25 LEDs arranged in a 5 by 5 square.

In order to locate these LEDs quickly, as the figure shown below, we can regarded this matrix as a coordinate system by marking 0~4 from top to bottom and from left to right. Therefore, the LED sat in the second of the first line is (1,0) and the LED positioned in the fifth of the fourth column is (3,4), and others likewise.

img

5. Test Code

Find code blocks:

img

imgimg

Build blocks:

img

6. Test Result

After uploading test code to micro:bit main board and powering the main board via the USB cable, the LED in (1,0) lights up for 1s and the one in (3,4) shines for 1s and this sequence will repeat.

upload the code to the development board


Project 3: LED Dot Matrix

img

1. Introduction

Dot matrices are very commonplace in daily life. They have found wide applications in LED advertisement screens, elevator floor display, bus stop announcement and so on.

The LED dot matrix of Micro: Bit main board contains 25 LEDs in a grid. Previously, we have succeeded in controlling a certain LED to light by integrating its position value into the test code. Theoretically, we can turn on many LEDs at the same time to show patterns, digits and characters.

What’s more, we can also click ”show icon“ to choose the pattern we like to display. Last but not the least, we can design patterns by ourselves as well.

2. Components

Micro:bit mainboard *1

img

Micro USB cable *1

img

3. Connection

Connect the board to your computer via micro USB cable.

img

4. Test Code

Find code blocks:

img

Build blocks:

img

5. Test Result

After uploading test code to micro:bit main board and powering the main board via the USB cable, we find that the 5*5 dot matrix start to show numbers 1, 2, 3, 4 and 5, and then it alternatively showsimg, “Hello!”, img, img, img, img and img.

upload the code to the development board


Project 4: Programmable Buttons

![img](img/k1 - 1.png)

1. Introduction

Buttons can be used to control circuits. In an integrated circuit with a button, the circuit is connected when the button is pressed and if you release the button, the circuit is open.

Micro: Bit main board boasts three buttons: two programmable buttons (marked with A and B), and a reset button at back. By pressing the two programmable buttons, three different signals can be input. We can press button A or B or both so that the LED dot matrix shows A, B and AB respectively.

Let’s get started!

2. Components

Micro:bit mainboard *1

img

Micro USB cable *1

img

3. Connection

Connect the board to your computer via micro USB cable.

img

4. Test Code 1

Find code blocks:

img

img

Build blocks:

img

5. Test Result 1

After uploading test code and powering on, the 5*5 LED dot matrix shows A if button A is pressed and then released, B if button B pressed and released, and AB if button A and B pressed together and then released.

upload the code to the development board

6. Test Code 2

Find code blocks:

img


img


img


img


img


Build blocks:

img

7. Test Result 2

After uploading test code and powering on, when the button A is pressed, the LEDs in red increase; when the button B is pressed, the LEDs in red reduce.

upload the code to the development board


Project 5: Temperature Detection

img

1. Introduction

The Micro:bit main board is actually not equipped with a temperature sensor, but uses nNFR52833 chip for temperature detection. Therefore, the detected value is much closer to the temperature of the processor, so there maybe deviation from the ambient value.

Its detection range is -40 ~ 105℃.

2. Components

Micro:bit mainboard *1

img

Micro USB cable *1

img

3. Connection

Connect the board to your computer via micro USB cable.

img

4. Test Code 1

Find code blocks:

img


img


img


Build blocks:

img

5. Test Result 1

After uploading test code 1 to micro:bit main board, powering the main board via the USB cable, and click “Show console Device”, the temperature value shows in the serial monitor as shown below.

upload the code to the development board

img

When you touch the processor nNRF52833 on the board for a while, its temperature will rise gradually and the CoolTerm serial monitor will show this change:

img

If you’re running Windows 7 or 8 instead of Windows 10, Google Chrome won’t be able to match devices. so you’ll need CoolTerm.

Open CoolTerm and click Options to select SerialPort, set COM port and put baud rate to 115200 (after testing, the baud rate of USB SerialPort communication on Micro: Bit main board is 115200), and then click OK and Connect.

img


img


The CoolTerm serial monitor shows the change of temperature in the current environment, as shown below:

img


6. Test Code 2

Find code blocks:

img


img


img


img


Build blocks: 35 in the code can be modified according to actual conditions.

img


7. Test Result 2

After uploading the code 2 to the board, when the ambient temperature is less than 35℃, the 5*5 LED dot matrix shows img.

You may cover the sensor on the board to make the temperature equal to or become greater than 35℃, and then img will appear.

upload the code to the development board


Project 6: Geomagnetic Sensor

img

1. Introduction

This project aims to explain the use of the Micro: bit geomagnetic sensor, which can not only detect the strength of the geomagnetic field, but also be used as a compass to find bearings. It is also an important part of the Attitude and Heading Reference System (AHRS).

Micro: Bit main board uses LSM303AGR geomagnetic sensor, which supports four modes namely 100 kHz, 400 kHz, 1 MHz and 3.4 MHz and the dynamic range of magnetic field is ±50 gauss. In the board, the magnetometer module is used in both magnetic detection and compass.

In this experiment, the compass will be introduced first, and then the original data of the magnetometer will be checked. The main component of a common compass is a magnetic needle, which can be rotated by the geomagnetic field and point toward the geomagnetic North Pole (which is near the geographic South Pole) to determine direction.

Attention: this geomagnetic sensor built in the board can help us determine bearings by showing readings in the value from 0 to 360. And we need to calibrate it for the first by rotating. Please note that metal materials around may attenuate the accuracy of the reading and calibration.

2. Components

Micro:bit mainboard *1

img

Micro USB cable *1

img

3. Connection

Connect the board to your computer via micro USB cable.

img

4. Test Code 1

Find code blocks:

img


img


img


Build blocks:

img

Note: it is imperative to calibrate the Micro:bit board because different geomagnetic fields exist in different places. And the board requires a calibration for the first using time.

5. Test Result 1

After uploading code and powering on, press the button A and the board need to be calibrate when you see LED dot matrix shows “TILT TO FILL SCREEN”. Rotate the board until all 25 red LEDs are on as shown below.

img

After completing calibration, a smile img will appear. Press button A, and the detected magnetometer value will show. And the direction north, east, south and west correspond to 0°, 90°, 180° and 270° respectively.

upload the code to the development board

6. Test Code 2

img

We read the value to determine direction: the arrow points to the current magnetic North Pole.

img

For the above picture, the arrow pointing to the upper right when the value ranges from 292.5 to 337.5.

0.5 can’t be input in the code, so the values we get are 293 and 338.

We add other statements to make a set of complete code.

Find code blocks:

img


img


img


img


img


Build blocks:

img

img

img

7. Test Result 2

After uploading code and calibrating, tilt micro:bit board and the LED dot matrix displays the direction signs.

upload the code to the development board


Project 7: Accelerometer

img

1. Introduction

The Micro: Bit main board V2 has a built-in LSM303AGR gravity acceleration sensor with a resolution of 8/10/12 bits and range of ±2g, ±4g or ±8g.

The micro:bit board boasts a built-in LSM303AGR acceleration sensor (accelerometer) which includes standard, fast, plus and high-speed mode (100 kHz, 400 kHz, 1 MHz and 3.4 MHz) of I2C serial bus interface and SPI serial standard interface for external communication, with resolution of 8/10/12 bits and range of ±2g, ±4g, or ±8g.

When the micro:bit board is at rest or in uniform motion, the accelerometer only detects the acceleration of gravity. If the board is slightly swung, the detected acceleration is much less than the that of gravity, but the difference can be ignored. Therefore, we mainly detect the change of gravitational acceleration on the x, y, and z axes.

In this project, we will introduce how to measure the position of the board with the accelerometer. And then we may have a look at the original three-axis value output by the accelerometer.

2. Components

Micro:bit mainboard *1

img

Micro USB cable *1

img

3. Connection

Connect the board to your computer via micro USB cable.

img

4. Test Code 1

Find code blocks:

img


img


img


Build blocks:

img


5. Test Result 1

After uploading code and powering on, if we shake the Micro:Bit board(any direction), the LED dot matrix displays the digit “1”.

upload the code to the development board

When the logo is kept above, number 2 displays.

img

When it is kept upside down(logo below the LED dot matrix), it shows as below.

img

When it is placed on the desk, the number 4 appears.

img

When it is covered on the desk, the number 5 exhibits.

When the board is tilted to the left , the LED dot matrix shows the number 6 as shown below.

img

When the board is tilted to the right , the LED dot matrix displays the number 7 as shown below:

img

When the board falls down to the floor(a free fall), the LED dot matrix shows the number 8. (Please note that this test is not recommended for it may damage the main board.)

If you’d like to try this function, you can also set the acceleration to 3g, 6g or 8g. But still ,we do not recommend.

6. Test Code 2

Find code blocks:

img


img


img


Build blocks:

img


7. Test Result 2

Upload test code to micro:bit main board, power the main board via the USB cable, and click “Show console Device”.

upload the code to the development board

img

After referring to the MMA8653FC data manual and the hardware schematic diagram, the accelerometer coordinate of the Micro: Bit are shown in the figure below:

img

The following interface shows the decomposition value of acceleration in X axis, Y axis and Z axis respectively, as well as acceleration synthesis (acceleration synthesis of gravity and other external forces).

img

If you’re running Windows 7 or 8 instead of Windows 10, via Google Chrome won’t be able to match devices. You’ll need to use the CoolTerm serial monitor to read value.

Open CoolTerm and click Options to select SerialPort, and set COM port and baud rate to 115200. Click OK and Connect. The CoolTerm serial monitor shows the data of X axis, Y axis and Z axis , as shown in the figures below :

img


Project 8: Light Brightness Detection

img

1. Introduction

In this experiment, we will use the micro:bit board to detect light intensity. Since the micro:bit board does not contains its own photoresistor, the LED dot matrix will shoulder this job. The light signal will convert into input, and the voltage decay time is sampled so that the detected light intensity is a relative value.

2. Components

Micro:bit mainboard *1

img

Micro USB cable *1

img

3. Connection

Connect the board to your computer via micro USB cable.

img

4. Test Code

Find code blocks:

img


img


img


img


Build blocks:

img


5. Test Result

Upload the test code to micro:bit main board, power the board via the USB cable and click “Show console Device”.

upload the code to the development board

img

When the LED dot matrix is covered by hand, the light intensity is approximately 0; when the LED dot matrix is exposed to light, the light intensity gets stronger with the light as shown below:

img

20 in the code is an arbitrary value of light intensity. If the current light value is less than or equal to 20, the icon moon will appear on the LED dot matrix. If it’s bigger than 20, the sun will appear.

If you’re running Windows 7 or 8 instead of Windows 10, Google Chrome won’t be able to match devices. CoolTerm will be required.

Open CoolTerm and click Options to select SerialPort, and set COM port and baud rate to 115200, click OK and Connect. The CoolTerm serial monitor shows the value of light intensity, as shown below:

img


Project 9: Speaker

img

1. Introduction

Micro: Bit board boasts an built-in speaker, which makes sound to the programs easier. It is also able to make sound such as utter giggles, greetings and yawning as well as all kinds of tones, like playing the song Ode to Joy.

You can also turn off the built-in speaker to enjoy the beautiful music via headphones connected to GND and P0. In MakeCode, you need to turn off the speaker by “Turn off built-in speakers” block.

2. Components

Micro:bit mainboard *1

img

Micro USB cable *1

img

3. Connection

Connect the board to your computer via micro USB cable.

img

4. Test Code 1

Find code blocks:

img


img


img


Build blocks:

img

5. Test Result 1

After uploading code and powering on, the speaker utters sound and the LED dot matrix shows the logo of music.

upload the code to the development board

6. Test Code 2

Find code blocks:

img


img


img


Build blocks:

img

img

img

img

img

img


Ode to Joy:

img

For more information about musical notations: https://en.wikipedia.org/wiki/Numbered_musical_notation



Project 11: Microphone

img

1. Introduction

The Micro:bit mainboard is built with a microphone which can test the volume of ambient environment. When you clap, the microphone LED indicator turns on. So, you can make a disco lighting changing with music. The microphone is placed on the opposite side, and an LED indicator is next to the hole that lets sound pass. When the board detects sound, the LED indicator lights up.

2. Components

Micro:bit mainbaord *1

img

Micro USB cable *1

img

3. Connection

Connect the board to your computer via micro USB cable.

img

4. Test Code 1

Find code blocks:

img


img


Build blocks:

img

5. Test Result 1

After uploading test code to micro:bit main board and powering the board via the USB cable, the LED dot matrix displays when you clap, and appears when it is quiet around.

upload the code to the development board

6. Test Code 2

Find code blocks:

img


img


img


img


img


img


Build blocks:

img


7. Test Result 2

Upload test code and power on and click “Show console Device” as shown below:

upload the code to the development board

img

The louder the sound is, the greater the sound value will show on the serial monitor:

img

When the button A is pressed, the LED dot matrix displays the value of the biggest volume. Please note that the biggest volume can be reset via the Reset button. When you clap, the LED dot matrix shows the pattern of the sound.


Project 12: Play Music

1. Introduction

In the previous projects, we have learned about the touch-sensitive logo and the speaker respectively.

In the project, we will combine these two components to play music. We will apply the Logo to control the speaker to sing songs.

2. Components

Micro:bit mainbaord*1

img

Micro USB cable *1

img

3. Connection

Connect the board to your computer via micro USB cable.

img

4. Test Code

Find code blocks:

img


img


img


img


img


Build blocks:

img


5. Test Result

After uploading test code to micro:bit main board and powering the board via the USB cable, the speaker plays Birthday Song when the logo is touched.

upload the code to the development board


Project 13: Dodge Bullets

1. Introduction

We have learned about the two programmable buttons: button A and B. In this project, we will combine them with LED dot matrix to design a game: Dodge Bullets.

2. Components

Micro:bit mainboard *1

img

Micro USB cable *1

img

3. Connection

Connect the board to your computer via micro USB cable.

img

4. Game 1

Dodge bullets! Don’t get hit!

Find code blocks:

img


img


img


img


img


img


img


img


Build blocks:

img

img

6. Test Result 1

The game begins when the code is uploaded to the main board. The bullets fall off and we need to control the role G by Button A and B to shun them. If the role fail to avert the attacks, game is over.

upload the code to the development board

7. Game 2

Dodge bullets! Earn points!

Find code blocks:

img


img


img


img


img


img


img


img


img


img


Build blocks:

img

img

img

img


8. Test Result 2

The game begins when the code is uploaded to the main board. The bullets fall off and we control the role G by Button A and B to shun them. 1 score will be tallied for each successful dodging. If the role fail to avert the attacks, the game is over and gained scores displays.

Press buttons A and B at the same time, and the game starts again.

upload the code to the development board


Project 14: Bluetooth Wireless Communication

img

1. Introduction

The Micro:bit main board comes with a nRF52833 processor with a built-in BLE(Bluetooth Low Energy) Bluetooth 5.1 device and a 2.4GHz antenna for Bluetooth wireless communication, so that the board is able to communicate with a variety of Bluetooth devices, including smart phones and tablets.

In this project, we mainly concentrate on the Bluetooth wireless communication to transmit code or signals. Firstly, we should connect a device (a phone or an iPad) to the board.

Since setting up Android phones to achieve wireless transmission is similar to that of Apple devices, no need to illustrate again.

2. Components

Micro:bit mainbaord *1

img

Micro USB cable *1

img

smart phone/Pad *1

img

3. Connection

Connect the board to your computer via micro USB cable.

img

4. Procedures

We will demonstrate on iPhone/iPad/MAC devices. Android/Windows devices may take these as a referance.

(1) Firmware (iOS/MAC only)

iOS/MAC: https://www.microbit.org/get-started/user-guide/ble-ios/

Click “Download pairing HEX file” to download the Micro: Bit firmware and upload the downloaded firmware to the Micro: Bit main board.

img


img


img


(2) Micro:bit APP

Open App Storeimg and search “micro bit” and click img to download the APP.

img

(3) Connection

Connect your Apple device with Micro: Bit main board.

  • Turn on Bluetooth on the device.

  • Open img APP, ensure the board is connected to the device and select “Choose micro:bit”to start pairing Bluetooth.

    img

  • Pair a new micro:bit.

    img

  • Following the instructions to press button A and B at the same time(do not release them until you are told to) and press Reset & Power button for a few seconds.

    img

  • Release the Reset & Power button, you will see a password pattern shows on the LED dot matrix. Now , release buttons A and B and click “Next”.

    img

    • Set the password pattern on your Apple device as the same pattern showed on the matrix and click “Next”.

      img

  • Still click “Next”and a dialog box props up as shown below. Then click “Pair”. A few seconds later, the match is done and the LED dot matrix displays the “√” pattern.

    img

    img

    img

    img

  • After the match with Bluetooth, write and upload code with the App.

(4) Create Code

Click “Create Code” to enter the programming page and write code.

Click img and you will seeimg and then select “Create √”.

img

img

img

img

Name the project as “1 “and clickimg to save the code.

img

Click “Flash” to enter the uploading page.

The default code program for uploading is the one saved just now and named “1” and then click “Flash” to upload the code program “1”.

img

img

img

If the program “1” is uploaded successfully a few seconds later, the App will show as below and the LED dot matrix will display a heart pattern .

img


5. Micro:bit Button Piano Projects

The LED dot matrix should be mounted facing you.

img


5.1 Introduce to Piano

In this project, you will embark on the journey of piano exploration. With seven buttons connected on the board and each one corresponding to one tone, we will learn how to build a basic piano that may open the door to a wonderful world of tone.

img

Music Theory

The piano is versatile and usually consists of 88 keys, covering a wide vocal range. Tone is the basis of music, which is represented by black and white keys on the piano. In music theory, there are seven basic tones: C, D, E, F, G, A, B. They make up the scale for multiple musical compositions.

  1. C(Do)

    • On pianos, C is white key at the most left side.

    • C is the beginning note of the scale and the first note in the diatonic scale.

    • C major: C D E F G A B C

  2. D(Re)

    • D is the white key next to C.

    • D is the second note in scale.

    • D major: D E F# G A B C# D。

  3. E(Mi)

    • E is the white key next to D.

    • E is the third note in scale.

    • E major: E F# G# A B C# D# E。

  4. F(Fa)

    • F is the white key next to E.

    • F is the forth note in scale.

    • F major: F G A Bb C D E F。

  5. G(Sol)

    • G is the white key next to F.

    • G is the fifth note in scale.

    • G major: G A B C D E F# G。

  6. A(La)

    • A is the white key next to G.

    • A is the sixth note in scale.

    • A major: A B C# D E F# G# A。

  7. B(Si)

    • B is the white key next to A.

    • B is the seventh note in scale.

    • B major: B C# D# E F# G# A# B。

These seven basic tones and the interstitial relationships among them form the basis of music. With these tones, different scales, chords and melodies can be composed. Beyond that, semitone and whole tone are also included to have a better understanding of more complex aspects of music. Learning music theory can help piano players perform compositions.

img


Wiring

In this kit, in addition to the 7 basic syllable keys, there is also a high syllable key, totaling eight keys, enabling the playing of more intricate melodies.

Button

Pin

C

P1

D

P8

E

P12

F

P2

G

P13

A

P14

B

P15

C

P16

img

Connect the board to your computer via micro USB cable.

img


Read Single Button Value

Build code:

img

img

img

P1 pin is C tone.

img

Complete code:

img

Burn code to micro:bit.

Test result:

img

Open CoolTerm and connect to corresponding port. When the C button is pressed. 0 is displayed on the serial monitor; otherwise, it shows 1.

img

img


Make A Sound in C Tone

Build code:

img


img


img


img


Complete code:

Choose Middle C and upload code.

img


Test result:

When the button C is pressed, the piano plays a Middle C Tone.

img


A 8-key Piano

We now make all seven buttons to be able to play tones by pressing them.

Build Code

Duplicate the code block, as shown below. And then modify the tones and pins one by one.

img

img

Complete code:

img

Test result:

Each button corresponds to the related Middle Tone, and when you press them, the tone will be played.

img


5.2 High, Middle, Low Tone

To enrich the music, high, middle and low tone are inevitable. Yet only seven buttons integrated in the piano. Therefore, we may program to shift tones by the two programmable buttons and the touch-sensitive logo, which just correspond to high, middle and low.

Build code:

We create three tone functions first.

img

img

img

Put corresponding tones into these functions.

img

img

img

Add a logic program to determine the state of button A and B on the board as well as the touch logo.

img

Click the “+” to add a condition, because three in total are needed.

img

If you accidentally add too much conditions, click “-” to remove one.

img –> img

Make a variable pitch.

img

img

img

Determine whether the button A, B on the board is pressed and whether the logo is touched.

img

img


img


When they are pressed or touched, pitch will change into the set value.

img

Determine the pitch value.

img


img


img


img


When pitch=0, piano is in low tone.

When pitch=1, piano is in middle tone.

When pitch=2, piano is in high tone.

img


img


Complete code:

img


Test result:

When Button A on the board is pressed, piano is in low tone.

When the Logo on the board is touched, piano is in middle tone.

When Button B on the board is pressed, piano is in high tone.

img


5.3 Music with Light

In this project, we integrate the LED dot matrix to the piano to display different icons when pressing different buttons.

Build code:

img

Here we set to letters corresponding to buttons. You can modify to any other icons as you like.

imgimg

imgimg

imgimg

imgimg

imgimg

imgimg

imgimg

Complete code:

img

Test result:

Press the piano button, and LED will show related tone:

img


5.4 Music Box

We will program to build a music box so that we can change songs by pressing buttons.

1. Custom Snatch

img

You may define a snatch of music by yourself. The set music will be played from left to right, and up to low corresponds to High to Low tone.

img

The followings are snatches of music which are already provided in the Gallery.

img


2. Integrated Songs

img

img

The new micro:bit V2 board also includes some sounds expressing emotions.

img


Complete code:

img


Test result:

Press each button and different songs will be played with LED showing variety icons.

img

img

img


6. Troubleshooting

6.1 Code fails to download to Micro:bit

Problem

Recently, many users encounter the issue that Micro:bit board doesn’t respond when download code.

If the way you operate is correct, maybe you accidentally press the reset button and enter the Maintenance mode or the firmware is lost due to mis-operation.

Plug in Micro:bit board, the “MAINTENANCE” drive appears, which means the program can’t be downloaded.

img


Solution

  1. Download the hex file from this page to your computer.

    Down load the latest micro:bit firmware-0255:https://www.microbit.org/get-started/user-guide/firmware/ If you do not want to download from this website, we also provide it in our tutorial.

  2. After the latest firmware is downloaded, then drag it into the “MAINTENANCE” to make Micro:bit back to normal mode.

img


Avoid to Enter “MAINTENANCE”

  1. Make sure the Reset button is not pressed when plugging the board by USB cable.

img        2. Don’t unplug the cable suddenly during downloading micro:bit program, otherwise, the firmware will be lost and micro:bit will enter “MAINTENANCE” mode. 3. In the experiment, wrong wiring also cause short circuit or losing the firmware.


6.2 Troubleshooting-Download with WebUSB

Having trouble pairing the Micro: bit with WebUSB (/ device/usb/webusb)?


6.2.1 Step 1: Check cable

Make sure that your micro:bit is connected to your computer with a micro USB cable. You should see a MICROBIT drive appear in Windows Explorer when it’s connected.

img

If you can see the MICROBIT, please go to step 2.

If you can’t:

  • Make sure that the USB cable is working. Does the cable works on another computer? If not, find a different cable to use. Some cables may only provide a power connection and don’t actually transfer data.

  • Try another USB port on your computer.

  • Is the cable good but you still can’t see the MICROBIT drive? Hmm, you might have a problem with your micro:bit.

  • Try the additional steps described in the falut finding at microbit.org.

  • If this doesn’t help, you can create a support ticket to notify the Micro:bit Foundation of the problem. If you do so, skip the rest of these steps.


6.2.2 Step 2: Check firmware version

It’s possible that the firmware version on the micro:bit needs an update. Let’s check:

  1. Go to the MICROBIT drive.

  2. Open the DETAILS.TXT file.

img

  1. Look for the version number. It should say Version: … or Interface Version: …

img

img

If the version is 0234, 0241, 0243, you need to update the firmware on your micro:bit. Go to Step 3 and follow the upgrade instructions.

If the version is 0249, 0250 or higher, you have the right firmware, just go to step 4.


6.2.3 Step 3: Update firmware

  1. Put your micro:bit into MAINTENANCE Mode. To do this, please unplug the USB cable from the micro:bit and then re-connect the USB cable after pressing and holding the reset button. Once you insert the cable, you can release the reset button. You should now see MAINTENANCE instead of the MICROBIT drive. Also, a yellow LED indicator will stay on.

img

  1. Downlaod firmware .hex file: https://microbit.org/guide/firmware/

  2. Drag the file onto the MAINTENANCE drive.

  3. The yellow LED will flash while the HEX file is copying. After that, the LED will go off and the micro:bit resets. The MAINTENANCE drive now changes to MICROBIT.

  4. The upgrade is complete! You can open the DETAILS.TXT file to check the firmware version that matches the one of the HEX file you copied.

If you want to know more about connecting the board, MAINTENANCE Mode, and upgrading the firmware, please refer to Firmware guide.


6.2.4 Step 4: Check version of Browser

WebUSB may require you to update your browser.

Check that your browser version matches one of these: Android, Chrome OS, Linux, macOS and Windows 10 Chrome 65+.


6.2.5 Step 5: Pair device

Once you’ve updated the firmware, open the Chrome Browser, go to the editor and click on Pair Device in settings.

See WebUSB (/ device / usb / webusb) for pairing instructions.


Enjoy fast downloads!