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 blocks

Read the SharpShot Vision with Pybricks blocks in three steps

Blocks go in the same order as MicroPython: first import the library under "set up", then create an object and give the sensor a name, and last use that name under "program" to call a function. Follow the steps on the left, and the blocks on the right grow with you. These block pictures were built and exported straight from Pybricks Code, so they look the same as on your screen.

Check first: Pybricks block coding needs a licence code or a Patreon membership. Without one, you can write MicroPython instead. It works exactly the same way (switch the right side to "Matching MicroPython" to see it).

1

Import the library

The first thing in a block program is a red "from … import …" block under the yellow "set up". It tells Pybricks to use the SharpShot library.

Pick one library (the blocks are exactly the same; only the name after from 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. Do not rename the file.
  3. Press "+" to add a new file, and choose blocks.
  4. From the block list, drag out the red "from … import …" block, attach it under "set up", and pick the two names.
2

Create an object: give the sensor a name

Drag another red "… is a …" block and attach it under the import block. On the far left is the name you give the sensor; after it come the port and whether to multitask. Every time you want a reading, you pick this name.

Which port is the sensor on?

Give it a name (in Pybricks you can use any English name; here are three to try):

Turn on multitasking? (the green true / false on the block)

The port box holds a number: SPIKE 1~6 = A~F, so 3 is port C.

3

Use the functions

Under "program", put a red function block: pick the name cam in the first box, await in the middle, and the function in the last box. Click a function, and the blocks 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 is 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.

Block examples for every function

15 functions, each with a set of blocks you can copy (name cam, multitasking true). Press "Try it" to jump to step 3; the blocks and the output on the right change to that example.

Good to know

  1. Import the library file into the project first. If MBC_cam_school.py is not imported, you cannot pick MBC_CAM_SCHOOL in the red blocks.
  2. await and call must match multitasking: multitasking true means pick await; multitasking false means pick call. If you mix them, the program gives an error on the hub.
  3. Behind the blocks is MicroPython. The code pane on the right of Pybricks Code shows the program the blocks make. It is the same as "Matching MicroPython" on this page (the multitasking version has one extra line, await wait(0), which Pybricks adds by itself).
  4. 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 from "Setup 2: TRACK". If you have not done Setup 1, hue is always 0, the same as red. When no blob is found, X, Y, width, height and area are all 0, so check with found first.
  5. Unplugging does not stop the program: if the sensor cannot be read, you get the last value it read, and the computer prints one warning line (in Chinese and English; it starts with MBC: Port). Use the sensor_ok function to check the connection.
  6. Which way is which: stand behind the robot and look forward. X: left 0, right 98, centre about 50 (X − 50 is negative on the left, positive on the right). Y is small at the bottom and big at the top (bottom 1, top 75). Only SPIKE can read device_id and firmware_version. On SPIKE, area and blob_xya need sensor firmware from 2026-10 or later.