Ranger 2-Way (TOF2) × MATRIX × MATRIXblock stock blocks

Interactive tutorialMATRIX

First time? Try the interactive tutorial in your browser first, then follow the steps below with your hub.

This page covers MATRIXblock stock colour-sensor blocks (0x22) only: how to set it up for the Ranger 2-Way (TOF2) on MATRIX Mini R4, how to read every value, the commands it supports and examples. Use the switcher above to change product, host or software.

Which edition and how to connect

Get the MATRIX edition and connect it with the stock MATRIX 4-pin cable to I2C1 or I2C2 of the Mini R4 (address 0x22); pick that port in the block.

Ranger 2-Way (TOF2) × MATRIX Mini R4

Setup

What you need

  • Sensor: Ranger 2-Way (TOF2) (MATRIX edition).
  • Controller: MATRIX Mini R4.
  • Cable: the stock MATRIX 4-pin sensor cable.
  • Software: MATRIXblock (the stock MATRIX block software). This method needs no extra library.

Install the software

  1. Install MATRIXblock (default folder C:\matrixblock-r4\).

Make the software see the sensor

The Mini R4 sees the sensor as a stock colour sensor (I2C address 0x22); read it with the built-in blocks, no extension needed:

  • The "colour sensor → R / G / B / C / M / Y / K" blocks each read one 0 ~ 255 number. The firmware packs the product data into these seven slots; see the readings below for what each slot means.
  • MATRIXblock's Arduino mode works too: MiniR4.I2C1.MXColor.getColor(R).

Warning

Do not use the H / S / V or colour ID blocks: the controller computes those from R, G, B itself, so they mean nothing for MBC products. MATRIX removed the grey-level and colour-number blocks, so only these seven slots are usable.

Wiring

  1. Connect the stock MATRIX 4-pin sensor cable to the Mini R4 I2C1 or I2C2 port.
  2. Choose that port in the blocks (for example I2C1).
  3. 5 V direct, no level shifter needed.

Which side is left

Left and right are as seen from behind the sensor, looking the way it faces (left = J5, right = J3). Facing the sensor, they are the other way round, so when you test with your hand, stand behind the sensor and look the same way it does. "Left is closer" and "turn left" in the examples follow this direction.

First test

  1. Show the number from the "colour sensor → R" block.
  2. If the number changes with what is in front of the sensor, everything is connected.

FAQ

  • The numbers make no sense? Make sure you use the seven slots R / G / B / C / M / Y / K, not the H / S / V or colour ID blocks.

Reading values

Use the stock MATRIXblock colour-sensor R / G / B / C / M / Y / K blocks (not H / S / V or colour ID); the Arduino-mode line is shown too.

left distance (cm) leftCm

left distance (cm)
Range Meaning
0~120 cm distance from the left sensor, 0~120 cm (left = sensor 0 seen from behind the robot); 120 = nothing in range / sensor failed

Block "colour sensor → R"

int leftCm = MiniR4.I2C1.MXColor.getColor(R);   // left distance (cm)

right distance (cm) rightCm

right distance (cm)
Range Meaning
0~120 cm distance from the right sensor, 0~120 cm (right = sensor 1); 120 = nothing in range / sensor failed

Block "colour sensor → G"

int rightCm = MiniR4.I2C1.MXColor.getColor(G);   // right distance (cm)

nearer distance (cm) nearCm

nearer distance (cm)
Range Meaning
0~120 cm the smaller of left and right, 0~120 cm

Block "colour sensor → B"

int nearCm = MiniR4.I2C1.MXColor.getColor(B);   // nearer distance (cm)

Not readable here:left distance (mm), right distance (mm), init bitmap, fault bitmap, average distance (mm). Use Arduino / mBlock / micro:bit for these.

Examples

There is no full example program for this software yet. Each item under “Reading values” above comes with code you can use as is; put them together in order, or contact us for a full example.

More questions

Still stuck? Contact us with your software and a screenshot of the program.

Downloads

Sources

  • Host and software list:_build/guides.json
  • Values and commands:_build/protocol/tof2.json (single source of truth)
  • Setup:_build/guides/software/matrix-matrixblock.en.md、_build/guides/product/tof2/matrix-matrixblock.en.md
Email for a quoteBuying Guide