MBC SharpShot Vision × EV3 MicroPython (Pybricks)

Read SharpShot Vision with EV3 MicroPython in three steps

Programs always go in this order: first import the library and pick the camera mode, then create an object and name the camera, then call its functions with that name. Work down the steps on the left and watch the program grow on the right; drag the blobs, papers, blocks or line in the simulated camera view to see what the program prints.

Verified on EV3 hardwareRun on real EV3 bricks on 2026-11-03 with shipping firmware v1.0-261101: the stock EV3 firmware (EV3-G infrared blocks, all 13 camera modes read slot by slot) and Pybricks v4 examples 1~4; ev3dev / EV3 MicroPython v2 checked against the mode table only (same as the LEGO infrared sensor). The EV3 edition cannot take commands from the hub; switch camera modes in the camera MENU.

1

Import the library, pick the camera mode

The first thing in the program tells the hub "I am using the SharpShot Vision library". Without it the hub does not know UniCam and stops with NameError.

  1. Download the library (save the file, keep its name): MBC_UniCam_EV3.py.
  2. EV3 MicroPython (VS Code): put it in the project folder next to main.py. Pybricks (code.pybricks.com): use "Import a file" in the same project.
  3. Plug the camera into port 1–4 with an EV3 cable; the hub powers it. The EV3 sees it as an infrared sensor.
  4. Pick the camera mode: choose the camera mode and sub-option in the camera's MODE menu, and click the same mode number below (mode number = camera mode × 10 + sub-option).
2

Create the object: name the camera

A robot can have several sensors, so you "create an object": tell the program which port the camera is on and which mode it is in, and give it a name. You use that name for every reading.

Which port is the camera on?

Write the mode number in the program?

The number after mode= is the mode number from step 1; switch the camera menu to the same mode (otherwise the library decodes the wrong layout and the numbers make no sense).

3

Use a function

Always write "cam.function()": name + dot + function. Functions are grouped by camera mode; dashed ones belong to another mode (clicking one switches the mode for you). Click a function and the program and output switch to its example.

Simulated camera view: drag things in the picture and watch the output change

The view is a sketch: values come straight from where things are on screen (X 0–159 left→right, Y 0–119 top→bottom, area % = width × height ÷ whole picture); a hue code is the color the paper or block really has (red 0, yellow 40, green 80, blue 160, purple 200, white table 244, black tape 252). It is not the camera's own algorithm, and real numbers vary with the light. Color tracking assumes 4 colors were taught on the camera: color 1 red, 2 green, 3 blue, 4 yellow. In object detection you pick each shape yourself (the camera does not judge it here); objects 1, 2… are sorted by area, largest first; X, Y is the shape's centroid (white dot), the dashed box is its bounding box, and the angle is the rotation you set.

An example for every function

Every function has an example you can drop into the loop; the badge shows which modes it works in. "Try it" jumps to step 3 (and switches the mode if needed).

Full examples

Press "Copy" for the whole program. More examples (multi-color, spot color, color order, stop at junctions) are on the EV3 examples page.

Turn toward a blob (mode 13, left wheel B, right wheel C)

        

!Teach "target 1" on the camera first and set the camera menu to mode 13. Turns the wrong way? Make KP negative.

Line following (mode 41 black line)

        

!Point the camera down and forward. Left = negative, so "line on the left → turn left" is turn = KP * e. No line: spin toward the side it was last seen.

Good to know

  1. Unplugging does not stop the program, but readings become None. The EV3 library returns None (not the last value) and prints "MBC: ... no sensor" once. Comparing None gives TypeError, so check if v is None: in real programs. Tick "Unplug the sensor" to see it.
  2. The mode number must match the camera menu. With mode= the library uses what you wrote; without it, it reads infrared mode 0. A function the mode does not have raises ValueError (the message says which mode to use).
  3. Check that something is seen first. (0, 0) or area 0 = not seen. Red's hue code is 0, so in color order read total() first to know how many entries are real.
  4. Directions: X 0–159 left→right, Y 0–119 top→bottom (top = small); the middle is X = 80. EV3 positions are 8×6 grid-cell centres (±10 px); grid() gives the raw cell (raw EV3 Y is bottom = small). Line offset: line on the left = negative, right = positive (looking forward from behind the robot).
  5. Each EV3 infrared mode switch takes about 1.1 s. Most values are in mode 1; line edges(), far_width(), marker(), line_all() and color order also read mode 2. Do not switch back and forth in one loop. The EV3 has no lost(), cell(), colors_found() or firmware_version(); count() is mode 14 only.
  6. Colors are taught on the camera. "Target 1" is color 1 in the program; the program cannot change target colors. Sample-spot positions are also set on the camera.