Introduction: Micro:bit MU Vision Sensor for Beginners - Label Values and Number Card Recognition

This is my second guide to the MU vision sensor. In this project we will program the micro:bit to recognize the different number cards by using label values.


1 x BBC micro:bit

1 x Morpx Mu Vision Sensor 3

1 x Micro:bit breakout board - It needs to have access to pin 19&20, which not all breakout boards have. I use elecfreaks motorbit, because I like that board.

4 x Jumper wires (Female-Female)

Step 1: Setting Up the Sensor

Before we start connecting anything we want to setup the sensor properly.

The Mu Vision sensor have 4 switches. The two on the left decides its output mode and the two one the right decides its address.

Since we want the address to be 00, both switches on the right should be turned off.

The different output modes are:


01 I2C

10 Wifi data tansmission

11 Wifi picture transmission

We want to work in the I2C mode, so the two switches should be on 01, so the left most should be turned off and the other should be on.

Step 2: Wiring

Wiring is pretty easy, just use four jumper wires to connect the Mu sensor with your breakout board.

Mu sensor -> Breakout board

SDA -> pin 20

SCL -> pin 19

G -> Ground

V -> 3.3-5V

Step 3: Getting the Extension

First we go to the Makecode editor and start a new project. We then go to "Advanced" and select "Extensions". Be aware that since I am danish, these buttons have slightly different names in the pictures. In extensions we search for "Muvision" and select the only result we get.

Step 4: Initializing Connection and Enabling the Algorithm

When you use this extension you will get some "Cannot read property of undefined" errors. That is just because the micro:bit animation is missing. It doesn't affect the compilation and runing of the program.

The first orange part of the code initialize the I2C connection.

The second orange part of the code enables the number card recognition algorithms.

Showing numbers is used to trouble shoot.

If the micro:bit doesn't count to three when you run the program, then check that your wires are connected properly to the right pins.

Step 5: The Main Program

Detect number card gives either a 0 or 1. If a number card is detected we get a 1(true) and a 0(false) if a number card is not detected.

The "Get algorithm label value" give us a label value depending on what we think we are looking at and what the MU vision sensor think it is seeing. So if we were looking at colours we would get a number from 0 to 8. 8 would mean that the MU vision sensor had detected purple, 1 would mean that it had detected black or dark grey and 0 would mean that it had detected an unknown colour.

For number cards the label value corresponds to the number on the card, so if the number 8 is detected, then the MU sensor would give it the label value 8. That means we don't need to tell the program what each label value means. The program simply just need to show us the value, so we use the "Show String" command. Which is "Vis streng" in danish.

Program can be found here.

Step 6: Runing the Program

When you run the program, the Mu sensor and micro:bit should be able to recognize all the number cards.You can try to expanded the program so it can both recognize number and shape cards.

Here is some of the other algorithms and their corresponding labels.

Shape cards label:

Check -> 1

Cross -> 2

Circle -> 3

Square -> 4

Triangle -> 5

Invalid -> 0

Traffic cards label:

Forward -> 1

Left -> 2

Right -> 3

Turn around -> 4

Park -> 5

Invalid -> 0

Colour label:

Black/Dark Grey -> 1

White -> 2

Red -> 3

Yellow -> 4

Green -> 5

Cyan -> 6

Blue -> 7

Purple -> 8

Unknown -> 0