MBC SharpShot Vision × Arduino (I2C 0x4C)

Read SharpShot Vision with Arduino in three steps

Arduino reads the camera over I2C at address 0x4C; UNO, Nano, UNO R4 and ESP32 all work. In order: wire it, paste the helper and pick the camera mode; then in setup() start I2C, wait for the camera and switch the mode; then read values in loop(). Work down the steps on the left and watch the program grow on the right; drag things in the simulated camera view to see what the Serial Monitor prints.

v1 not yet hardware-verifiedThe value layout is final and passed computer tests; real-hardware numbers (fps, line thresholds, I2C pins) may change after hardware testing.

1

Wire it, paste the helper, pick the mode

No library to install: paste the "helper" into the sketch — the first few lines (address, structs) at the top, the functions at the bottom. Then you can call ucReadBlob() and friends.

  1. Wiring: camera 5V → 5V (the camera draws a lot; an external 5 V 2 A supply with joined GND is best), GND → GND, SDA → A4, SCL → A5 (UNO/Nano). UNO R4: the pins marked SDA/SCL; ESP32: GPIO 21 (SDA) / 22 (SCL).
  2. I2C pins are provisional until hardware testing: on the camera, SDA = IO3 and SCL = IO1 for now; the camera needs the "I2C" firmware (it shares IO1/IO3 with the LEGO serial firmware, so it is one or the other).
  3. Paste the program marked ① on the right into the Arduino IDE (the helper is at the bottom; "Show helper" shows it all, and "Copy program" always copies everything). You can also download MBC_UniCam.h into the sketch folder and use #include "MBC_UniCam.h" instead.
  4. Pick the camera mode: click a mode number below (mode number = camera mode × 10 + sub-option). Over I2C the program can switch the mode: the step-2 code does it at power-on.
2

setup(): start I2C, wait for the camera, switch the mode

The camera (ESP32) takes a few seconds to boot. setup() starts I2C, waits for the camera to answer (up to 8 s), then the E0 command switches it to the mode from step 1.

Switch the mode from the program at power-on?

3

Read values in loop()

Functions are grouped by camera mode; dashed ones belong to another mode (clicking one switches it, and MODE in the program follows). 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 loop(); the badge shows which modes it works in. "Try it" jumps to step 3.

Full examples

More examples (blob tracking, spot color, color order, line-follower car) are on the Arduino examples page.

Where are colors 1–4 (mode 13)

        

!Teach targets 1–4 on the camera first. "Copy" gives the whole program (helper included).

Line values (mode 41 black line)

        

!Left = negative. With no line it prints the side the line was lost, so turn that way.

Good to know

  1. When the camera cannot be read: ucReadBlob() and friends return false; single values (mbcRead, ucColorsFound) are −32768 (MBC_NONE). If the camera is missing at power-on, setup() prints a warning and stops; plug it in and press the Arduino reset button. Tick "Unplug the sensor".
  2. The I2C version gives 16 colors / 16 spots in every mode, as raw pixels (mode 11 too), so there is no grid to decode. Fields a mode does not give are −1 (e.g. mode 13 has no width/height).
  3. Check that something is seen first. X = 0 = not seen. Red's hue code is 0, so in color order use the total to know how many entries are real.
  4. Directions: X 0–159 left→right, Y 0–119 top→bottom (top = small), middle X = 80. Line offset: left = negative, right = positive (looking forward from behind the robot).
  5. Commands are saved in the camera: E0 (mode) and E1 (spot position) stay after power-off. Target colors can only be taught on the camera; v1 has no command to write them.
  6. Paste the helper in two parts: #include <Wire.h>, the address and structs at the top, the functions at the bottom (the structs must come first or Arduino will not compile).