This page has moved into the new guide: Ranger 2-Way › micro:bit › MakeCode

Laser Ranger 2-ch × micro:bit (MakeCode extension)

Back to Laser Ranger 2-ch

The universal I2C edition of the Laser Ranger 2-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

Laser Ranger 2-ch × micro:bit
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
distance 2-ch [left] ([cm]) 0~120 cm 01 distance from the left sensor, 0~120 cm (left = sensor 0 seen from behind the robot); 120 = nothing in range / sensor failed
distance 2-ch [right] ([cm]) 0~120 cm 02 distance from the right sensor, 0~120 cm (right = sensor 1); 120 = nothing in range / sensor failed
distance 2-ch nearest (cm) 0~120 cm 03 the smaller of left and right, 0~120 cm
distance 2-ch [left] ([mm]) 0~1200 mm 04 left sensor distance 0~1200 mm; 1200 = nothing in range / sensor failed
distance 2-ch [right] ([mm]) 0~1200 mm 05 right sensor distance 0~1200 mm; 1200 = nothing in range / sensor failed
distance 2-ch average (mm) 0~1200 mm 08 (left mm + right mm) / 2, 0~1200; same number as EV3 mode 3 and the 3rd value of SPIKE mode 6

More blocks (yes / no, events)

Block Related value
on distance 2-ch nearer than 10 cm 03

Status

bit Name Meaning
b0 ready (ready) 1 once both sensors are initialised and snapshots are running
b1 any sensor failed (fault) 1 if any sensor failed to initialise, has an I2C error or no update for 200 ms (07 ≠ 0 or 06 ≠ 3)

JavaScript

if (!(mbc.waitReady(0x29, 3000))) {
    basic.showIcon(IconNames.No)   // nothing answers: check wiring and power
}
basic.forever(function () {
    basic.showNumber(mbc.tof2Distance(MbcTofSide.Left, MbcDistUnit.Cm))   // left distance (cm)
    basic.pause(100)
})

Sources and assumptions

Generated by _build/gen-reference.mjs from _build/protocol/tof2.json (single source of truth, transcribed from the 2026-10-21 protocol decisions).

  • 共識 #8:08 左右平均 mm 補進 I2C/mBlock 值表(定案 §5 已列)。
  • 0x22 命令 412 不動(4 左、5 右、6 最近、711 = 0、12 = 最近);schema 不收 11/12,所以 12 只寫在 03 的 note。
  • EV3:模式 0、2、4 鎖住(照盤點);模式 1 改 [左,右]×4(index 0/1 各代表左右)、模式 3 改平均 mm、模式 5 改 [左 mm, 右 mm];模式 1 描述表宣告 int8 −100~100,cm×100/120 在範圍內。
  • SPIKE:0/5/7/9 鎖住,另加模式 3 鎖住(網站 sensors/tof2/index.md read(3) = 左/右 cm,共識 #11);模式 6 改 [左 mm, 右 mm, 平均 mm];模式 1、2、4、8 維持不動;模式 8 v[0] 改 ID|hw[0]<<8(統一後共用函式)。
  • 「左」= 站在車後往前看的左(第 0 顆,XSHUT PA6);韌體只有 L/R 巨集名,盤點檔標為推測。
  • 沒有寫入命令;F8 換位址/EF 重開機用共用的。
  • The extension reads Int16LE and pauses 2 ms after writing the id (D5); with no sensor answering, reporters return 0 and yes / no blocks return false.
Email for a quoteBuying Guide