MBC Pathfinder 16-Way (Line16) × MATRIX Mini R4 (MATRIXblock)

Read the Pathfinder 16-Way (Line16) with MATRIXblock in three steps

In MATRIXblock, the software for the MATRIX Mini R4, the Pathfinder 16-Way (Line16) 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 Pathfinder 16-Way (Line16) 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 Pathfinder 16-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 Pathfinder 16-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 behind the robot): drag the black line and watch the output change

The simulator is only a picture. The maths is simpler than the real thing, so a real sensor may be off by a channel or two. Each circle shows the level MATRIX reads for that channel (0 = darkest, 3 = brightest). A red ring = that channel sees the line. The bottom row shows what the seven slots read.

An example for every reading

11 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 Pathfinder 16-Way (Line16)).
  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. Calibrate once first. Hold the calibration button for about 0.5 seconds, then let go. While the green light is on (5 seconds), sweep all 16 points over the black line and the white floor. MATRIXblock cannot send a calibration command, so always use the button.
  4. Only 4 levels per channel: one MATRIX slot holds 8 bits, so each light value is squeezed to 0 to 3 (0-24 → 0, 25-49 → 1, 50-74 → 2, 75-100 → 3). Channel 2 = floor(Cyan / 16) mod 4, channel 3 = floor(Cyan / 4) mod 4.
  5. Values MATRIXblock cannot read: line segments, line bitmap and so on. Use Arduino, mBlock or micro:bit if you need them.
  6. Lost line and direction: when the line leaves, Red stays on that side (−16 or +16 after taking away 16); to check for "no line", use width = 0. Stand behind the robot: line on the left = negative. Channel 1 is on the far left.