MBC Pathfinder 16-Way (Line16) × micro:bit (MakeCode)

Read the Pathfinder with a micro:bit in three steps

In MakeCode for micro:bit, first add the MBC extension, then wait for the sensor in "on start", and last put a reading block into "forever". Follow the steps on the left, and the blocks on the right grow with you. The block pictures come from MakeCode's own renderer, so they look the same as in the editor. Switch to JavaScript at the top right, just like the switch in MakeCode.

MakeCode is free and needs no login. Open it in Chrome or Edge. Click "Download" to save a .hex file and drag it onto the micro:bit.

1

Add the MBC extension and wire it up

The micro:bit does not know the Pathfinder yet. After you add the MBC extension, an "MBC Sensors" category appears, and the Pathfinder blocks are in its "Line" group. Pick your micro:bit version first; the hardware check below changes with it.

Which micro:bit do you have? (V2 has "V2" printed on the back)
  1. Open MakeCode and click "New Project".
  2. At the bottom of the toolbox, click "Advanced" → "Extensions".
  3. Paste https://github.com/contactmbcrobot/pxt-mbc-sensors into the search box, press Enter and click mbc-sensors.
  4. The blocks are in English. (Traditional Chinese is also included in the extension.)
2

On start: wait for the sensor

The sensor needs a moment to start. The program first waits until it is ready: tick = connected, cross = not connected. You find wiring problems at once.

I2C address of the sensor
  1. From "Logic", drag "if … then … else" into "on start".
  2. From "MBC Sensors" → "more", drag "wait for device at … ready, timeout … ms" into the condition. Pick 22 (0x16) and type 3000.
  3. From "Basic", drag two "show icon" blocks: one tick, one cross.
  4. Put "pause 100 ms" into "forever".

3

Use the reading blocks

The "MBC Sensors → Line" group has blocks for line position, light values, events, calibration and more. The "Device" group has shared blocks that every MBC sensor has. Pick one, and the blocks and the output switch to its example.

Sensor simulator (looking from behind the robot): drag the black line and watch the output on the right

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. The number in each circle is the light value (0 = black, 100 = white). A red ring = that channel sees the line.

An example for every block

Every block of the Line group and the Device group has an example you can copy (address 0x16). Click "Try it" to jump to step 3, and the blocks and output on the right switch to that example.

Good to know

  1. Unplugging does not stop the program: when the sensor cannot be read, reading blocks return 0 (true/false blocks return false), and nothing is printed. So "line position = 0" can mean "line in the centre" or "not connected". Use "device at … is ready" to tell them apart. Tick "Unplug the sensor" below and try it: even "on line lost" fires.
  2. Direction: stand behind the robot and look forward. Line on the left = negative, line on the right = positive. Channel 1 is on the far left.
  3. When the line is lost: the line position stays on the side where the line left (−16 / +16). To check "I really cannot see a line", use "line is seen" or line width = 0.
  4. The 8-way and 16-way both use 0x16: to connect two Pathfinders to the same P19 / P20, first move one with "change device at … to address …", then pick "changed address" in step 2.
  5. JavaScript extras: mbc.readValue(22, 0x01) reads any I2C value directly (−32768 = not connected), and mbc.writeCmd(22, 0xE0, []) sends a command. The value ids are in the I2C reference on the product website.