MBC SharpShot Vision × EV3 clev3r (EV3 BASIC)

Read SharpShot Vision with clev3r in three steps

clev3r needs no library: on the EV3 the camera is a LEGO infrared sensor, each EV3 mode sends back a few numbers (cells), and what each cell holds depends on the camera mode. In order: create the project and pick the camera mode, then pick the port and set the EV3 mode, then read the cells, split them into values and show them on the EV3 screen. Work down the steps on the left and watch the program grow on the right; drag the blobs, papers, blocks, line or shapes in the simulated camera view to see what the EV3 screen shows.

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

Create the project, pick the camera mode

clev3r needs no extension and no file to import: on the EV3 the camera acts as the LEGO infrared sensor (type 33), so you read it with the built-in Sensor commands. The first line, folder, decides which EV3 folder the program goes into.

  1. Install clev3r (this site was tested with v1.7.1.0), start a new program and write the lines on the right.
  2. Plug the camera into port 1–4 with an EV3 cable; the EV3 powers it. Turn the EV3 on first.
  3. Press "Compile and download", then run it from the MBC_unicam folder in the EV3 file menu.
  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). The same EV3 cell holds different things in different camera modes.
2

Pick the port, set the EV3 mode

Sensor.SetMode(port, EV3 mode) picks which infrared-sensor mode to read; every cell you read after that comes from it. This "EV3 mode" is not the camera menu's "camera mode":

  • EV3 mode 0 proximity (1 cell): the camera's current mode number (e.g. 13).
  • EV3 mode 1 beacon (8 cells, 0–7): most values are here.
  • EV3 mode 2 remote (4 cells, 0–3): colors/spots 9–12 in modes 11 and 21, blocks 9–11 and the total in color order, line edges, far width, marker count, object 5 and the object count.
  • EV3 modes 3 and 4 always send 0 (not used); EV3 mode 5 (2 cells): device ID and firmware version.
Which port is the camera in?

In Sensor.SetMode(1, 1) the first number is the port (1–4) and the second is the EV3 mode, which follows the reading you pick in step 3. Try to use one EV3 mode per program: each switch takes about 1.1 s.

3

Read cells, show them on the EV3 screen

Sensor.ReadRawValue(port, cell) reads one cell of the current EV3 mode (counting from 0). A cell often holds two numbers (e.g. X×10 + Y); split them with Math.Floor(v / 10) and Math.Remainder(v, 10). LCD.Text writes on the EV3 screen. Functions are grouped by camera mode; dashed ones belong to another camera mode (clicking switches it for you).

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 reading has an example you can drop into clev3r: Sensor.SetMode picks the EV3 mode, then the While loop reads. The badge shows the camera modes it works in; the same value can sit in a different cell in another camera mode, so the example follows the mode you picked. "Try it" jumps to step 3.

Full examples

Press "Copy" for the whole program. More examples are on the EV3 examples page (Pybricks code; the cell layout is the same).

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

        

!Teach "target 1" on the camera and set the camera menu to mode 13. X is the 8×6 cell turned into pixels (cell centre); blob on the left = X below 80 = turn left. Turns the wrong way? Change 0.3 to -0.3.

Line following (mode 41 black line, left wheel B, right wheel C)

        

!Point the camera down and forward. The ones digit of cell 5 is the line-seen flag; 0 = no line, so spin toward the side the line was last seen. Left offset is negative, so the left wheel slows and the robot turns left.

List the objects on screen (mode 51)

        

!Set the camera menu to mode 51 and teach target colors 1–8 (you can set a shape while teaching). EV3 mode 1 has the codes and cells of objects 1–4; object 5 and the count are in EV3 mode 2, which costs another 1.1 s, so this example reads mode 1 only.

Good to know

  1. Unplugged reads 0 and the program keeps running. clev3r's Sensor.ReadRawValue returns 0 when there is no data: a position of 0 = "not seen", and a hue of 0 looks like red. To know the camera is connected, use Sensor.GetType from the "Is the sensor connected" card (33 = connected). Tick "Unplug the sensor" to see it.
  2. The camera menu mode must match the program. A cell holds different things in different camera modes, so a mismatch gives meaningless numbers. clev3r can read EV3 mode 0 for the camera's current mode number and check it first (the "Which camera mode" card).
  3. Each EV3 mode switch takes about 1.1 s. Most values are in EV3 mode 1; only colors/spots 9–12 in modes 11 and 21, blocks 9–11 and the total in color order, line edges, far width, marker count, object 5 and the object count are in EV3 mode 2. Do not switch back and forth in one loop. EV3 modes 3 and 4 are always 0.
  4. Positions are 8×6 cells: X×10 + Y, X 1–8 left→right, Y 1–6 bottom→top (bottom = small, the opposite of pixels), 0 = not seen. To pixel centres: X = (cell X − 1) × 20 + 10, Y = 109 − (cell Y − 1) × 20 (picture 160×120, top = 0). Line offset: left = negative, right = positive (looking forward from behind the robot).
  5. An EV3 cell only holds −127–100. Hue codes 0–240 are sent as hue × 100 ÷ 240 (0–100) and white/grey/black as −1 to −15; the examples turn them back into hue codes (±2). Mode 23 sends the raw hue code in two cells (hundreds, remainder) instead. Object angles are sent as (angle + 1) ÷ 2; multiply by 2. Colors are taught on the camera; the program cannot change them.
  6. The EV3 screen shows only English letters and digits, so LCD.Text labels are short English words, padded with spaces to wipe out longer text from before.