This page has moved into the new guide: Pathfinder 16-Way › Arduino › Arduino IDE

Line Follower 16-ch × Arduino I2C (universal I2C edition)

Back to Line Follower 16-ch

The universal I2C edition of the Line Follower 16-ch speaks MBC I2C protocol v2: write one id, read 2 bytes = one int16 little-endian value; consecutive ids can be read in one go. This page has the value table, commands and wiring for this product; the shared rules (F0~F5 version & status, F8 re-address, EF reboot) are on the universal I2C protocol page.

SPIKEEV3Arduino I2CmBlockMATRIXmicro:bit

Tip

New to coding? Start with the Arduino examples; every sketch is copy-and-upload. The six-host reading of every value is in the reference.

Basics

Item Detail
I2C address 0x16(change with F8)
F0 device ID low byte 0x16、high byte 16
Model LINE16
Protocol F1 2
Speed 100 kHz (recommended) / 400 kHz; wait 2 ms after writing the id
Read 主機寫 [編號] → 等 2 ms → 讀 2×k byte(k≤16)= 從該編號起連續 k 個 int16 小端;空號回 -32768
Snapshot updated every 10 ms; a multi-value read is atomic

Wiring

Line Follower 16-ch × Arduino UNO
Sensor Arduino UNO / Nano Arduino R4 ESP32
SDA A4 SDA GPIO 21
SCL A5 SCL GPIO 22
5V 5V 5V 5V
GND GND GND GND

Works directly with 5 V hosts, no level shifter; two products with the same address cannot share a bus (re-address one with F8 first).

Value table

Each id returns one int16; click an id for the six-host reading and figure.

Id Value Range Meaning
01 line position linePos -16~+16 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)
02 fine position linePosFine -100~+100 sub-channel position: −100 to +100, 0 = centre, negative = left (same sign as line position)
03 line width lineWidth 0~16 路 number of channels on the line, 0~16; 0 = no line
04 line segments groupCount 0~8 number of separate line segments: 0 = lost, 1 = one line, ≥2 = fork / crossing
05 line bitmap bitmap 0~65535 bit bit0 = channel 1 (left) … bit15 = channel 16; 1 = that channel sees the line
06 last exit direction lastDir -16~+16 where the line was before it was lost: −16 to +16 (negative = left); keeps the last value
07 threshold threshold 1~99 reflect threshold for 'on line', 1~99, default 40 (firmware shipped before 2026-11-03: 50); set with E4
08 calibrations done calibCount 0~255 次 number of calibrations completed since power-on (button calibrations included)
10~1F channel 1~16 reflect light 0~100 calibrated reflect of channel 116, 0100 (channel 1 = left); ids 10~1F

Write commands

Id Command Parameters Meaning
E0 black line mode blackLine — follow a black line (default); RAM only, back to the default after reset
E1 white line mode whiteLine — follow a white line (F3 b1 = 1); RAM only, back to the default after reset
E2 calibrate black calibBlack — store the current reading as black (sensor over the black line), ~50 ms; saved to EEPROM(F3 bit2 = 1 while running)
E3 calibrate white calibWhite — store the current reading as white (sensor over the white surface), ~50 ms; saved to EEPROM(F3 bit2 = 1 while running)
E4 set threshold setThreshold threshold 1~99 threshold 1~99 (RAM only, back to 40 after reboot); on SPIKE an out-of-range value returns failed (state 2)
E7 5-second auto calibration calibAuto — sweep the sensor across black line and white surface for 5 s; min/max become the references; F3 b2 = 1 meanwhile(F3 bit2 = 1 while running)
E9 mirror left/right reverse mirrored 0~1 [0 normal / 1 mirrored]: for a sensor mounted backwards — channel order and line position are mirrored; calibration stays per physical channel; RAM only, 0 after reset (not in legacy mBlock); on SPIKE an out-of-range value returns failed (state 2)

Status flags F3

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)

Shared registers

Id Name Meaning
F0 device ID low byte = factory I2C address (unchanged after re-addressing), high byte = hw[0] (channels / sensors / variant)
F1 protocol version 2 for this release (same number reported in SPIKE mode 8 v[1])
F2 firmware version major×100 + minor (e.g. 102 = 1.2)
F3 status flags b0 = ready; other bits per product (see flags)
F4 update counter +1 every 10 ms snapshot, wraps 0~255 (2.56 s per cycle, not usable for reboot detection; frozen = module busy)
F5 uptime seconds seconds since boot, saturates at 32767 (~9 h); a drop means the module rebooted
F8 change I2C address [F8][new 0x080x77][new], saved to EEPROM, takes effect after reboot; [F8][0x00][0xFF] = back to factory address
EF reboot [EF][0xA5]; mBlock sends ACK first, then reboots

Single-file helper functions

No library to install. Paste it in two parts: part ① (2 lines) at the top of the sketch, part ② at the bottom. #include <Wire.h> and MBC_NONE must appear before setup() uses them; pasting everything at the bottom will not compile.

① At the top of your sketch (before setup())

#include <Wire.h>

const int16_t MBC_NONE = -32768;   // no answer / undefined id

② At the bottom of your sketch (after loop())

// read k consecutive values (k ≤ 16) starting at id, int16 little-endian
bool mbcReadMany(uint8_t addr, uint8_t id, uint8_t k, int16_t *out) {
  Wire.beginTransmission(addr);
  Wire.write(id);
  if (Wire.endTransmission() != 0) return false;
  delay(2);                                        // always wait 2 ms (ESP32 products cannot clock-stretch)
  if (Wire.requestFrom(addr, (uint8_t)(k * 2)) != (uint8_t)(k * 2)) return false;
  for (uint8_t i = 0; i < k; i++) {
    uint8_t lo = Wire.read(), hi = Wire.read();
    out[i] = (int16_t)(lo | (hi << 8));
  }
  return true;
}

// read one value; MBC_NONE when nothing answers
int16_t mbcRead(uint8_t addr, uint8_t id) {
  int16_t v;
  return mbcReadMany(addr, id, 1, &v) ? v : MBC_NONE;
}

// write a command (0~3 parameters)
// with 2 parameters whose first is 0, write (uint8_t)0, e.g. mbcWrite(ADDR, 0xF8, (uint8_t)0x00, 0xFF); otherwise it clashes with the array form below and will not compile
void mbcWrite(uint8_t addr, uint8_t id, const uint8_t *args, uint8_t n) {
  Wire.beginTransmission(addr);
  Wire.write(id);
  for (uint8_t i = 0; i < n; i++) Wire.write(args[i]);
  Wire.endTransmission();
}
void mbcWrite(uint8_t addr, uint8_t id) { mbcWrite(addr, id, nullptr, 0); }
void mbcWrite(uint8_t addr, uint8_t id, uint8_t a) { mbcWrite(addr, id, &a, 1); }
void mbcWrite(uint8_t addr, uint8_t id, uint8_t a, uint8_t b) { uint8_t p[2] = {a, b}; mbcWrite(addr, id, p, 2); }
void mbcWrite(uint8_t addr, uint8_t id, uint8_t a, uint8_t b, uint8_t c) { uint8_t p[3] = {a, b, c}; mbcWrite(addr, id, p, 3); }

// wait until ready (F3 bit0 = 1), at most ms milliseconds
bool mbcWaitReady(uint8_t addr, unsigned long ms) {
  unsigned long t0 = millis();
  while (millis() - t0 < ms) {
    int16_t st = mbcRead(addr, 0xF3);
    if (st != MBC_NONE && (st & 1)) return true;
    delay(20);
  }
  return false;
}

Example: print the whole value table

// helper part ①
#include <Wire.h>

const int16_t MBC_NONE = -32768;   // no answer / undefined id

const uint8_t ADDR = 0x16;

void setup() {
  Serial.begin(115200);
  Wire.begin();
#if defined(WIRE_HAS_TIMEOUT)
  Wire.setWireTimeout(25000, true);   // AVR: never hang when the module is silent
#endif
  if (!mbcWaitReady(ADDR, 2000)) Serial.println("module not found: check wiring and address");
  Serial.print("ID 0x"); Serial.println(mbcRead(ADDR, 0xF0), HEX);   // low byte address, high byte hw[0]
  Serial.print("FW ");    Serial.println(mbcRead(ADDR, 0xF2));
}

void loop() {
  Serial.print("linePos: "); Serial.println(mbcRead(ADDR, 0x01));   // line position
  Serial.print("linePosFine: "); Serial.println(mbcRead(ADDR, 0x02));   // fine position
  Serial.print("lineWidth: "); Serial.println(mbcRead(ADDR, 0x03));   // line width
  Serial.print("groupCount: "); Serial.println(mbcRead(ADDR, 0x04));   // line segments
  Serial.print("bitmap: "); Serial.println(mbcRead(ADDR, 0x05));   // line bitmap
  Serial.print("lastDir: "); Serial.println(mbcRead(ADDR, 0x06));   // last exit direction
  Serial.print("threshold: "); Serial.println(mbcRead(ADDR, 0x07));   // threshold
  Serial.print("calibCount: "); Serial.println(mbcRead(ADDR, 0x08));   // calibrations done
  { int16_t a[16]; mbcReadMany(ADDR, 0x10, 16, a); Serial.print("light: "); for (uint8_t i = 0; i < 16; i++) { Serial.print(a[i]); Serial.print(' '); } Serial.println(); }
  Serial.println();
  delay(200);
}

// paste part ② of the helper functions below

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 鎖住,14、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 不受影響。
  • Pin table uses each board's common defaults (ESP32: change with Wire.begin(sda, scl)).
Email for a quoteBuying Guide