Micro:bit MU Vision Sensor - Object Tracking

Introduction: Micro:bit MU Vision Sensor - Object Tracking

About: Thorsgaard is an efterskole in Denmark that works with technology and innovation amongst other things. The instructables here are mainly made by the teachers, but a few of them are made by students.

So in this instructable we are going to start programming the Smart Car that we build in this instructable and that we installed a MU vision sensor on in this instructable.

We are going to program the micro:bit with some simple object tracking, so that the MU sensor can track traffic cards.

Supplies

Materials

1 x Micro:bit

1 x Motor:bit

1 x MU vision sensor

1 x 2 axis camera mount

4 x M3 x 30 screws

6 x M3 x 6 screws

6 x M3 Spacer

10 x M3 nuts

1 x Caster wheel

2 x Smart car motors

2 x TT130 motor

2 x Wheels for the TT130 motor

1 x 9 volt battery + baterry holder

A bit of wire. In two different colours if possible

4 mm plywood (170 x 125 mm should do)

A small piece of double sided tape

Velcro tape (Hook and loop)

Hot glue

Tools:

Screwdrivers

Soldering

Iron

Wirecutter

Lasercutter

Hot glue gun

Drill

2.5 and 3 mm drill bits

Step 1: Setting Up the MU 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:

00 UART

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 the MU Sensor

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: Wiring the Camera Mount

The servo motor controlling horizontal movement should be connected to pin 13 and the servo motor controling vertical movement should be connected to pin 14.

Step 4: 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 5: 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 traffic 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 the wires on the MU vision sensor are connected properly to the right pins.

The two red blocks sets the starting position for the camera mount.

Step 6: The Program

The two first red blocks controls the servo motors that controls the camera mounts. The first one controls vertical movement and the second one controls horizontal movement.

The first outer "IF" blocks checks if the MU sensor can detect any traffic cards. If it can, then we move on to the two "IF" statements inside.

The first "IF" statement check the vertical placement of the detected card in the vision field. If a card is placed in the center of the vision field, then we will get the value 50 from the vertical value algorithm. Now for the card to be exactly in the middle is kind of rare. We have to hit very precise, so if we go with 50 as the only value where the camera should satnd still, then it will be moving more or less all the time. So instead we count anything betwen 45 and 55 as in the middle. So if the cards vertical placement is below 45, then we move the camera a bit down, by changing the vertical variable by +1. In the same way we move the camera a bit up if the vertical placement is above 55, by changing the vertical variable by -1. I might seem odd that the camera goes up, when we raise the variable and down when the variable goes up, but that is how the motor is placed.

The second "IF" statement does the exact same, but for the horizontal position. So when the traffic card is to far to the right of the vision field, then the camera will move to the right and when it is to far to the left of the vission field, then the camera will move to the left.

You can find the program here.

Step 7: Finished

Now upload your program to the Smart Car and test it out.

You can increase how quick the camera reacts to movement by increasing the change in the variables to 2 or 3 instead of 1. You can also try to decrease how large an amount of the field is consideret the middle. Try to make it from 47 to 53 instead.

Be the First to Share

    Recommendations

    • Summer Fun: Student Design Challenge

      Summer Fun: Student Design Challenge
    • Metal Contest

      Metal Contest
    • First Time Author Contest

      First Time Author Contest

    Comments