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 (School edition) × Pybricks built-in blocks

Read the SharpShot Vision (School edition) with Pybricks built-in blocks, no library

On a SPIKE hub the SharpShot Vision (School edition) shows up as a LEGO color sensor, so Pybricks' own color sensor blocks can read it: two numbers, reflection() and ambient(). The SharpShot Vision (School edition) packs values into each; split them with math blocks and use them. Work down the steps on the left and watch the blocks grow on the right; the block pictures are exported from Pybricks Code itself.

How this differs from Pybricks blocks (with the library)
  • This page: nothing to download or import, just open Pybricks; but it gives only the hue and the blob X, Y.
  • With the library: import MBC_cam_school.py first, but it gives 15 functions (e.g. saturation, brightness, blob size and area, motion), one block per function.

Check first: Pybricks block coding needs a license code or a Patreon membership. Without one, write the MicroPython directly; it is exactly the same (switch the right panel to "MicroPython").

1

set up: create the color sensor and pick the port

No library: under the yellow "set up" put Pybricks' own color sensor block (ColorSensor), pick the port the SharpShot Vision (School edition) is on, and name it cam.

Which port is the SharpShot Vision (School edition) on?
  1. In Pybricks Code press "+" to add a file and choose blocks.
  2. From "Sensors" drag the color sensor setup block (sensor icon) under "set up", rename it cam (any English name works) and pick the port above.
2

program: read reflection() and ambient()

Under "program" put "repeat while true", print cam reflected light (reflection) and cam ambient light (ambient) inside, then "wait 100 ms". Reading reflection switches the sensor to SPIKE mode 5 and ambient to mode 7 automatically; the SharpShot Vision (School edition) puts one set of numbers in each:

The simulator reads now:

On Pybricks 4.1 reflection() carries one decimal; made whole it is the hue (−1 = black, white or grey). ambient() keeps one decimal X.Y: before the point is X, the first decimal is the tens of Y.

3

Split with math blocks and use it

Store the reading in a variable with "set to" from Variables: r = reflection, a = ambient (as is). Then split it with // (whole part of ÷) and % (remainder) from Math, and print or test the values. Click a function and the blocks and 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

Every function has a set of blocks to copy (name cam, port C). "Try it" jumps to step 3, and the blocks and output on the right change to that example.

For more values use Pybricks blocks with the library or MicroPython.

Good to know

  1. Only 2 numbers. reflection() and ambient() hold one each; everything else is out of reach (listed under the step 2 table). For those use Pybricks blocks with the library.
  2. Pybricks 4.1 readings carry decimals: reflection() has one decimal (e.g. 81.3), so make it whole first (floor if ≥ 0, ceiling if negative) before // and %; ambient() keeps only one decimal, so split the integer part and the first decimal separately (floor, round(a × 10) % 10).
  3. Set up on the sensor first: "Setting 1: COLOR" picks the colour point and "Setting 2: TRACK" the colour to follow; the program has no place for these.
  4. Directions: X is small on the left and big on the right (middle about 50), Y is small at the bottom and big at the top; with no blob X and Y are both 0.
  5. Do not use the "color" block or color names. The SharpShot Vision (School edition) sends numbers: store them in variables and compare numbers. Unplugging the sensor makes the built-in blocks raise an error and stop the program (the library version does not).
  6. 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 "MicroPython" on this page.