Legacy edition, no longer supported: SharpShot Vision units shipped before 2026-10 (School and WRO editions) are no longer supported; their guides and examples stay here for reference. To upgrade to the current SharpShot Vision, contact the distributor you bought it from and send it back: the firmware update is free, and the buyer pays shipping both ways. Looking for the current SharpShot Vision? →
MBC SharpShot Vision (ESP32CAM) School edition × Pybricks

Read the SharpShot Vision with MicroPython in three steps

A Pybricks program always goes in this order: first import the library, then create an object and give the sensor a name, and last use that name to call a function. Follow the steps on the left, and the program on the right grows with you. In the pretend camera picture you can drag the blob, change its colour and change its size, and see what the program prints.

Your hub:
1

Import the library

The first thing in the program tells Pybricks "I want to use the SharpShot library". Without this line the hub does not know what MBC_CAM_SCHOOL means, and you get a NameError.

Pick one library (both work the same way; only the import line is different):

  1. Download the library (save the file and keep its name): MBC_cam_school.py (only this sensor) or MBC_sensors.py (the all-in-one library). You picked MBC_cam_school.py.
  2. In Pybricks Code, press "Import a file" in the file panel on the left and import it into the same project.
  3. Do not rename the file, and do not put it in a sub-folder.
  4. Go back to the main program and type the lines below at the very top (the lines marked ① on the right).
2

Create an object: give the sensor a name

A robot can have several sensors, so you "create an object": you tell the program which port the sensor is on, and you give it a name. Every time you want a reading, you use this name.

Which port is the sensor on?

Turn on multitasking?

The 3 in the program is the port number: SPIKE 1~6 = A~F. You can also write Port.C, but then you also need from pybricks.parameters import Port.

3

Use the functions

You always write "cam.function_name()": the name, a dot, then the function. Click a function, and the program and the output change to its example.

Pretend sensor (what the camera sees): drag the blob and watch the output on the right

The pretend picture is only a guide: the numbers are simplified, and a real sensor can be a few steps off because of the light. Cross = sample point (the spot you picked on the sensor in "Setup 1: COLOR"); hue, saturation and brightness are read at the cross. Green box = the blob the sensor is tracking (the colour you picked in "Setup 2: TRACK"). X: left 0, right 98. Y: bottom 1, top 75.

An example for every function

15 functions, each with a short example you can put straight into a loop. Press "Try it" to jump to step 3; the program and the output on the right change to that example.

Full examples

Turn to follow a blob (SPIKE, left wheel E, right wheel F)

        

!First pick the colour on the sensor with "Setup 2: TRACK". Only change the "things to change" at the top. The robot keeps shaking left and right: make KP smaller. It turns too slowly to keep up: make it bigger. The blob is on the left but the robot turns right: make KP a negative number.

Multitasking version (advanced)

        

!When you create the object, write True as the 2nd value, and create the object outside run_task(). Put await in front of every function.

Use it with other MBC sensors

        

!Switch to the all-in-one library: only change the import line, and import MBC_sensors.py. Do not import both libraries at the same time.

Good to know

  1. Unplugging does not stop the program. If the sensor cannot be read, you get the last value it read. If it was never read, you get None, and the computer prints one warning line (in Chinese and English; it starts with MBC: Port). Plug it back in and it works again by itself. Use sensor_ok() to check the connection. Tick "Unplug the sensor" on the right to see this. If you unplug while following a blob, the robot keeps turning toward the last place it saw the blob.
  2. You set the colours on the sensor, not in the program. Hue looks at the sample point from "Setup 1: COLOR". The blob is the colour you picked in "Setup 2: TRACK". You can only set them with the buttons on the sensor. If you have not done Setup 1, hue is always 0, the same as red, so the program thinks it sees red.
  3. Check that a blob is found first. When no blob is found, blob_x(), blob_y(), blob_w(), blob_h() and area() are all 0, which looks like "the blob is in the bottom-left corner". So check with found() (or area() == 0) before you look at the position.
  4. Reading the same data group again within 10 ms is not slower. read_all(), hue to blob height, found() and area() are one group, so you can call several of them together. On SPIKE, blob_xya() is another group, and so are device_id() and firmware_version() (put these outside the loop). EV3 cannot read device_id() or firmware_version(); everything else is the same. On SPIKE, area(), blob_xya() and device_id() need sensor firmware from 2026-10 or later. With older firmware the area is always 0, so use blob_w() * blob_h() instead.
  5. Which way is which: stand behind the robot and look forward. X is left and right: left 0, right 98, centre about 50, so blob_x() - 50 is negative on the left and positive on the right. Y is up and down: small at the bottom, big at the top (bottom 1, top 75). If left and right are swapped, turn on H-Mirror in the sensor's camera menu.
  6. The motion value is only right when the robot is still. If the robot is moving or the camera shakes, the whole picture keeps changing, and the motion value stays high.