Laser Ranger 8-ch × micro:bit (MakeCode extension)
The universal I2C edition of the Laser Ranger 8-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 | must use external 5 V (share GND with the micro:bit) |
| GND | GND |
Reporter blocks
| Block | Returns | Id | Meaning |
|---|---|---|---|
| distance 8-ch nearest ([cm]) | 0~120 cm | 01 |
smallest of the 8 distances, 0~120 cm (a failed sensor counts as 120); 120 = nothing around |
| distance 8-ch nearest direction | -8~+8 | 02 |
direction of the nearest object: −7 (left) to +7 (right), 0 = straight ahead, negative = left; ±8 = nothing around (keeps the last side) |
| distance 8-ch most open (cm) | 0~120 cm | 03 |
largest of the 8 distances, 0~120 cm (a failed sensor always reads 120 and looks 'farthest') |
| distance 8-ch most open direction | -7~+7 | 04 |
direction of the most open side: −7 to +7, 0 = straight ahead, negative = left; 0 when all 8 read 120 |
| distance 8-ch front ([cm]) | 0~120 cm | 05 |
average of sensors 4 and 5 (both facing forward), 0~120 cm; EV3 mode 3 and SPIKE mode 6 carry the same thing in mm; 0x22 'C' is min(4, 5), not the average (see 10) |
| distance 8-ch nearest ([mm]) | 0~1200 mm | 06 |
smallest of the 8 mm readings, 0~1200 (failed sensor counts as 1200); 1200 = nothing around |
| distance 8-ch front ([mm]) | 0~1200 mm | 09 |
average of sensors 4 and 5 (the two facing forward), 0~1200 mm; 1200 = nothing ahead. cm version is 05 |
| distance 8-ch sensor [1~8] ([cm]) | 0~120 cm | 10~17 |
distance of each sensor 1 |
| distance 8-ch sensor [1~8] ([mm]) | 0~1200 mm | 18~1F |
distance of each sensor 1 |
More blocks (yes / no, events)
| Block | Related value |
|---|---|
| on distance 8-ch nearer than 10 cm | 01 |
Status
| bit | Name | Meaning |
|---|---|---|
| b0 | ready (ready) |
1 once all 8 sensors are initialised ( |
| b1 | any sensor failed (fault) |
1 if any sensor failed to initialise, has an I2C error or no update for 200 ms (08 ≠ 0 or 07 ≠ 255) |
JavaScript
if (!(mbc.waitReady(0x29, 5000))) {
basic.showIcon(IconNames.No) // nothing answers: check wiring and power
}
basic.forever(function () {
basic.showNumber(mbc.tof8Nearest(MbcDistUnit.Cm)) // nearest distance (cm)
basic.pause(100)
})Sources and assumptions
Generated by _build/gen-reference.mjs from _build/protocol/tof8.json (single source of truth, transcribed from the 2026-10-21 protocol decisions).
- 正前方 mm(EV3 模式 3、SPIKE 模式 6 v[1])在定案 §5 沒有獨立 I2C 編號 → 掛在 05 正前方 cm 底下,用 scale:mm 標示,不自己加編號。
- 0x22(使用者 2026-10-21 最終定案):只用一個位址,R~K 由左到右 7 個 cm:第 1、2、3 顆、min(第 4, 第 5)、第 6、7、8 顆;11、12 不放資料;最近距離/方向由主機自己比較。此排法只用在 0x22,EV3/SPIKE不動。
- SPIKE:0/5/7/9 鎖住,1、2、3、4、8 維持不動;模式 6 改 [最近 mm, 正前方 mm, 最近方向 −8
+8](原本 = 第 27 顆兩兩合併);模式 8 v[0] 改 ID|hw[0]<<8。 - 最空曠方向 04 範圍 −7~+7(maxDirection 永遠不會是 0/16,盤點 INO:1086-1088);最近方向 02 ±8 = 沒目標、沿用上次偏向側,開機預設 −8。
- 沒有寫入命令;F8 換位址/EF 重開機用共用的。
- 主對話 2026-10-21:補 09 正前方 mm(定案 §5 只有 05 正前方 cm,但 EV3 模式 3、SPIKE 模式 6 都送 mm,I2C/mBlock 應有同一個值)。
- 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.