MBC Ranger 8-Way (TOF8) × MATRIX Mini R4 (MATRIXblock)

Read the Ranger 8-Way (TOF8) with MATRIXblock in three steps

In MATRIXblock, the software for the MATRIX Mini R4, the Ranger 8-Way (TOF8) shows up as a stock "colour sensor" (I2C address 0x22), so the built-in blocks can read it and no library is needed. First put Color Sensor Initialize in Setup of "Mini Begin", then a wait in Loop, and finally the colour sensor reading blocks in the loop. Follow the steps on the left and the blocks on the right build up; these pictures are drawn by MATRIXblock's own block code, so they look the same as in the software.

MATRIXblock is the free block software from MATRIX (installed in C:\matrixblock-r4\ by default). Buy the MATRIX edition of the sensor and connect it to I2C1 or I2C2 with the stock 4-pin sensor cable.

1

Set up: which port the Ranger 8-Way (TOF8) uses

The first thing in the program is a "Color Sensor ○ Initialize" block inside "Setup" of the blue "Mini Begin" block, so the MATRIX starts talking to the Ranger 8-Way.

Which port is the sensor plugged into?
  1. Open MATRIXblock. A new project already has a blue "Mini Begin" block (if not, drag one from the "Mini Core" category).
  2. Click the "Sensing" category and find "Color Sensor I2C1 Initialize" (not "Color Sensor V3").
  3. Put it inside "Setup" and pick I2C1 in the dropdown, the same port the sensor cable is plugged into.
2

Put a wait in the loop

Blocks inside "Loop" repeat forever. First add "wait 100 millisecond" so it reads every 0.1 seconds and the Information Window does not scroll too fast.

  1. Drag "wait 1000 millisecond" from "Control" into "Loop" and change the number to 100.

Leave "UART: On" and "Baud: 9600" on "Mini Begin" as they are: the examples use "USB Serial Print … with New Line" to show values in the Information Window (set the Information Window to 9600 too).

3

Use the reading blocks

The "Color Sensor I2C1 Red" block in "Sensing" has 7 usable slots in its dropdown: Red, Green, Blue, Cyan, Magenta, Yellow and Key. Each slot holds one value from the Ranger 8-Way; the cards below tell you what each slot is and how to work it out. Pick the same port as in step 1 (I2C1). Click a function and the blocks and output change to its example; the example goes inside "Loop", above the wait.

Simulated sensor (seen from above, front at the top): move the obstacle and watch the output change

The simulator is only a sketch: direction and distance come from a simple position-based estimate, so a real sensor may differ by a step or two. Red sector = that laser sees something; grey sector = it reads 120 (nothing that way). Lasers 4 and 5 both face straight ahead; Cyan holds the nearer of the two.

An example for every reading

10 examples you can copy block by block (port I2C1); they go inside "Loop", above the wait. Press "Try it" to jump to step 3; the blocks and output on the right change to that example.

Things to know

  1. Use the seven slots only: in the "Color Sensor" dropdown pick Red, Green, Blue, Cyan, Magenta, Yellow or Key (R, G, B, C, M, Y, K), each 0 to 255. Do not pick ColorID, Hue, Saturation or Value (the controller works those out from Red, Green and Blue, so they mean nothing for MBC products), and do not use the "Color Sensor V3" blocks (they are for another MATRIX sensor and cannot read the Ranger 8-Way (TOF8)).
  2. Unplugging does not stop the program: when the MATRIX library cannot reach the sensor, all seven slots read 255 and the program keeps running. Use the "Is it plugged in?" card to check; plug it back in and it works again.
  3. Wait 2 to 4 seconds after power-on: the Ranger 8-Way needs no calibration, but the 8 lasers take 2 to 4 seconds to get ready and read 120 until then. You can put "wait 3000 millisecond" in Setup.
  4. All seven slots are in cm: left to right Red, Green, Blue, Cyan, Magenta, Yellow, Key; Cyan = straight ahead (the nearer of lasers 4 and 5). MATRIXblock cannot read the nearest direction, most open direction, millimetres or fault data; use Arduino, mBlock or micro:bit for those.
  5. Mounting: sensor face forward, parts side up. Put your hand on the robot's left: Red should get smaller. If Key gets smaller instead, it is mounted the other way round, so swap left and right.