Line Follower 16-ch × micro:bit (MakeCode extension)
The universal I2C edition of the Line Follower 16-ch works with BBC micro:bit V1 / V2 through the MakeCode extension pxt-mbc-sensors v2 (which speaks MBC I2C protocol v2). Installation and hardware notes (3.3 V, power): micro:bit overview.
SPIKEEV3Arduino I2CmBlockMATRIXmicro:bit
Important
Extension v2 is not yet verified on hardware; block names follow the published release: https://github.com/contactmbcrobot/pxt-mbc-sensors
Wiring
| Sensor | micro:bit |
|---|---|
| SDA(RX) | P20 |
| SCL(TX) | P19 |
| VCC | micro:bit 3V (external 5 V recommended on batteries) |
| GND | GND |
Reporter blocks
| Block | Returns | Id | Meaning |
|---|---|---|---|
| line position | -16~+16 | 01 |
which channel the line is under: −16 (far left) to +16 (far right), 0 = centre; seen from behind the robot, negative = left (normally ±15; ±16 only for 200 ms after the line leaves the outermost channel) |
| fine line position | -100~+100 | 02 |
sub-channel position: −100 to +100, 0 = centre, negative = left (same sign as line position) |
| line width | 0~16 路 | 03 |
number of channels on the line, 0~16; 0 = no line |
| line segments | 0~8 | 04 |
number of separate line segments: 0 = lost, 1 = one line, ≥2 = fork / crossing |
| line bitmap | 0~65535 bit | 05 |
bit0 = channel 1 (left) … bit15 = channel 16; 1 = that channel sees the line |
| last exit direction | -16~+16 | 06 |
where the line was before it was lost: −16 to +16 (negative = left); keeps the last value |
| line threshold | 1~99 | 07 |
reflect threshold for 'on line', 1~99, default 40 (firmware shipped before 2026-11-03: 50); set with E4 |
| line calibration count | 0~255 次 | 08 |
number of calibrations completed since power-on (button calibrations included) |
| channel [1~16] reflect | 0~100 | 10~1F |
calibrated reflect of channel 1 |
More blocks (yes / no, events)
| Block | Related value |
|---|---|
| line is seen | 04 |
| on line [lost] | 04 |
| channel 1 is on the line | 05 |
| line follower is calibrating | 08 |
Command blocks
| Block | Id | Meaning |
|---|---|---|
| line follower follow [black] line | E0 |
follow a black line (default); RAM only, back to the default after reset |
| line follower follow [white] line | E1 |
follow a white line (F3 b1 = 1); RAM only, back to the default after reset |
| line follower calibrate [current reading is black] | E2 |
store the current reading as black (sensor over the black line), ~50 ms; saved to EEPROM |
| line follower calibrate [current reading is white] | E3 |
store the current reading as white (sensor over the white surface), ~50 ms; saved to EEPROM |
| line follower set threshold 50 | E4 |
threshold 1~99 (RAM only, back to 40 after reboot); on SPIKE an out-of-range value returns failed (state 2) |
| line follower calibrate [auto (sweep for 5 s)] | E7 |
sweep the sensor across black line and white surface for 5 s; min/max become the references; F3 b2 = 1 meanwhile |
Status
| bit | Name | Meaning |
|---|---|---|
| b0 | ready (ready) |
always 1 |
| b1 | white line mode (whiteMode) |
1 = following a white line |
| b2 | calibrating (calibrating) |
E2/E3/E7 in progress; new calibration commands are ignored |
| b3 | line lost (lost) |
segment count = 0 |
| b4 | fork (fork) |
segment count ≥ 2 |
| b5 | mirrored (reversed) |
E9 = 1 (sensor mounted backwards, left/right mirrored) |
JavaScript
if (!(mbc.waitReady(0x16, 3000))) {
basic.showIcon(IconNames.No) // nothing answers: check wiring and power
}
basic.forever(function () {
basic.showNumber(mbc.linePosition()) // line position
basic.pause(100)
})Sources and assumptions
Generated by _build/gen-reference.mjs from _build/protocol/line16.json (single source of truth, transcribed from the 2026-10-21 protocol decisions).
- B-11:細位置 02 與線位置 01 同號(負 = 左);韌體 F16:1290 註解寫反,程式碼同號(IR:11 為準)。
- B-12:E7 五秒動態校準補回(v1 的 0x20=0x01),定案表沒列。
- EV3:模式 0~2 鎖住;模式 3 原本不送 → 16 bit 位元圖;模式 4 原本不送 → 同模式 2;模式 5 ID 格式 B(共用函式)。
- SPIKE:0/5/7/9 鎖住,1
4、6 維持不動;教育版模式 0 的 16 路光值是 2-bit(玩具版 1-bit),跟 8 路的 4-bit 不同;byte 815 補 0(#65 已改,使用者保留);模式 9 排法照盤點(四路 4-bit 一個 int16,v6 = 位元圖);模式 8 v[0] 改 ID|hw[0]<<8。 - 線段數 04 範圍:定案沒寫,16 路最多 8 段(交錯壓線),採 0~8。
- mBlock 舊版:MBC_MBLOCK_LEGACY=1 時逐 byte 同 2026-10-21 統一後韌體(0x01 位置、0x02 線寬、n<<4|03 反向兩路壓一 byte、0x07 細位置 0~200),0x0B 回 1(B-1)。
- Flash:C031 硬體鎖 28 KB,I2C 版餘 848 B;不夠時照 B-17 順序瘦身,JSON 不受影響。
- The extension reads
Int16LEand pauses 2 ms after writing the id (D5); with no sensor answering, reporters return 0 and yes / no blocks return false.