MBC EXP6 6-Port Motor Expander (for LEGO® SPIKE™) × SPIKE × Official LEGO App

Interactive tutorialSPIKE

First time? Try the interactive tutorial in your browser first, then follow the steps below with your hub.

This page covers Official LEGO App (SPIKE 3, Robot Inventor) only: how to set it up for the MBC EXP6 6-Port Motor Expander (for LEGO® SPIKE™) on SPIKE Prime / Robot Inventor, how to read every value and examples. Use the switcher above to change product, host or software.

Setup

What you need

  • Sensor: MBC EXP6 6-Port Motor Expander (for LEGO® SPIKE™) (SPIKE edition). Each platform is a different factory edition; an EV3 edition is not recognised on a SPIKE hub.
  • Hub: SPIKE Prime (Education, yellow hub) or Robot Inventor (home edition, teal hub).
  • Cable: the standard cable in the box, or an original LEGO cable.
  • Software: Education uses the LEGO Education SPIKE App (the examples on this site use SPIKE 3); the home edition uses the LEGO MINDSTORMS Robot Inventor App.
  • Hub firmware: the original LEGO firmware. No need to switch to Pybricks.

Install the software

  1. Education: install the SPIKE App from the LEGO Education download page.
  2. Home edition: install the LEGO MINDSTORMS Robot Inventor App.
  3. If the hub has been flashed with Pybricks, switch it back to the original LEGO firmware with the SPIKE App first, or the official App cannot connect.

Note

The Education and home editions read values differently: in the home-edition App some blocks are limited to 0 ~ 126, and "Color" only goes up to 10. Use the readings for the edition you have.

Make the software see the sensor

No extension and no driver needed. Plug the sensor into the hub and the official App treats it as an original LEGO sensor (for most products a SPIKE Color Sensor); just use that sensor's blocks.

  • An official block returns one number at a time, so the product data is encoded into the "Color", "Reflected light" and "Raw red / green / blue" slots. See the readings below for what each slot means.
  • To open an example: download the .llsp3 (home edition: .lms) → open the App → top-left "File" → "Open" → pick the file.

Wiring

  1. Plug the sensor into hub port A with the cable (any of A~F works; choose the same port in your program).
  2. The plug only goes in one way: latch up, push it in gently, do not force it.
  3. When the hub is on, the light on the sensor comes on.

Wiring and power

  1. Host cable: plug the expander's Host cable into any SPIKE hub port (A~F).
  2. Separate power: the expander must have a 2S LiPo battery (7.4 V, 8.4 V fully charged, XT30 connector), which powers the motors and LEGO sensors; motor current is not drawn from the hub, and the hub signal lines go through an isolator. Do not use 3S or higher: above 9 V, EXP6 cuts power to LEGO Color / Ultrasonic sensors.
  3. Devices: plug LEGO sensors (colour, ultrasonic, force) and motors into any of the expander's ports 1~6.

Warning

The EXP6 supports SPIKE Prime, and Python in the Robot Inventor App on the Robot Inventor (51515) hub (see "Robot Inventor (51515)" at the end of this page); not EV3. Before switching to another programming method, power the EXP6 off once (turn off the hub or unplug the Host cable): once it has run a Pybricks program it keeps talking the Pybricks way until it restarts, and the official App cannot connect.

Install the EXP6 library (only once)

First time? Step-by-step version: Education install guide

The official App has no EXP6 blocks; Python text mode only (SPIKE 3; the library is marked for version 3.4.3). The library is plain Python without multitasking (async); every command runs synchronously.

  1. Download official App library + examples (.zip). The EXP6 needs firmware dated 2026-11-03 or later. The function reference is EXP6_Library_Manual.pdf in the pack.
  2. Paste the install script from the SPIKE_Education folder of the download (Install_MBC_exp6_Lib.py) into a SPIKE App Python project and run it once. The script writes the core library into the hub.
  3. After that, any new project can simply from MBC_exp6_SPIKE_App_Lib import MBC_EXP6; no more pasting long source code.
  4. When you no longer need it, run the uninstall script (Uninstall_MBC_exp6_Lib.py) from the download to remove the library from the hub cleanly.

Running the install script in the SPIKE App

Create the connection object

Assuming the EXP6 is on hub port F:

from hub import port
import time
from MBC_exp6_SPIKE_App_Lib import MBC_EXP6

exp6 = MBC_EXP6(port.F)   # expander on hub port F
time.sleep(1)             # wait 1 s for the expander to be ready

exp6.motor_power(1, 50)
time.sleep(3)
exp6.stop_all(1)          # always stop all motors before the program ends (1 = coast)

Important

No watchdog in the official App: if the program crashes or the hub disconnects, the motors keep the last command. Always end with exp6.stop_all(1); wait with plain time.sleep(), no heartbeat command needed.

MBC sensors on the EXP6, and sending them commands

MBC sensors (Line Follower, Laser Ranger, Controller, SharpShot Vision) just plug into EXP6 ports 1 to 6; the library already includes them:

line8 = exp6.line8(2)            # Line Follower 8-ch in EXP6 port 2
print(line8.pos100())            # -100 ~ +100
seq = line8.cmd(0xE4, 60)        # command: code 0xE0~0xEE + up to 5 parameters (-9999~9999), returns a number
ok = line8.wait_done()           # True done; False failed / rejected / timed out (10 s by default)
state = line8.cmd_state()        # 0 done, 1 busy, 2 failed (bad parameter), 3 rejected (no such command)
line8.busy()                     # True while not finished
line8.cmd(0xE4, 60, again=True)  # the same command + parameters is not resent unless again=True
  • Available: line8 line16 laser2 laser8 ps2 ps4 unicam(port, mode) (the camera mode must match the camera menu).
  • Command codes are the same as with the sensor on the hub (Line Follower 8-ch: command reference); each command takes about 0.1 to 0.2 seconds to come back. So far only the Line Follower 8-ch has been tested with commands (passed on 2026-11-05 on both the Education App and Robot Inventor).
  • Black/white calibration E2 / E3 and the 5-second calibration E7 are saved in the sensor, so do not send them while practising; E4 (threshold) and E9 go back to default on power-up.
  • The full demo is example 10 in the download pack (examples/10_MBC_Commands.py: threshold to 60 → bad parameter "failed" → unknown command "rejected" → back to 50); EXP6 in port F, Line Follower in EXP6 port 2.
  • The installer was slimmed down to 46.5 KB on 2026-11-05 (faster to paste, same usage); the library uses about 38 KB on the hub, leaving about 130 KB for your program.

Robot Inventor (51515)

The EXP6 also works with the LEGO MINDSTORMS Robot Inventor (51515) hub, using Python in the Robot Inventor App 10.x to control 6 LEGO motors, the LEGO colour / distance / force sensors and MBC sensors. Function names and usage are exactly the same as the Education version above (tested on Hub OS 3.4.0). The Robot Inventor App's word blocks cannot use this library.

Try it in your browser first: Robot Inventor App interactive tutorial

Install the library (once) 👉 Step-by-step version: Robot Inventor install guide

  1. Download Robot Inventor library + examples (.zip) (installer, uninstaller, 10 examples, library source). The EXP6 needs firmware dated 2026-11-03 or later.
  2. Turn the hub on and connect it in the Robot Inventor App: USB cable or Bluetooth, either works (USB is steadier and recommended).
  3. Make a new Python project, paste the whole of Install_MBC_exp6_Lib.py and run it. After about 6 seconds the console prints 安裝成功! (Installed OK) (after listing all 3 files as OK).
  4. The library lives in /projects/mbc_exp6/ on the hub and survives power-off; install it again after a hub firmware update. To remove it, run Uninstall_MBC_exp6_Lib.py.

Writing programs: only the import line differs from the Education version

from hub import port
import time
from projects.mbc_exp6.MBC_exp6_SPIKE_App_Lib import MBC_EXP6   # Education: from MBC_exp6_SPIKE_App_Lib import MBC_EXP6

exp = MBC_EXP6(port.F)      # EXP6 on hub port F (you can also write 'F')
exp.motor_run(1, 50)        # motor on expansion port 1 at 50% speed
time.sleep(2)
exp.motor_stop(1, "brake")  # stop: coast, brake, hold, or continue (do nothing)

MBC sensors work the same way: line8 = exp.line8(2) (Line Follower 8-ch in EXP6 port 2), print(line8.pos100()); available: line8 line16 laser2 laser8 ps2 ps4 unicam(port, mode). Just plug the sensor in; the first time you use a kind of sensor the hub takes about 1 second to load it. Sending commands (cmd(), wait_done(), cmd_state()) works the same as in the Education section above.

Important

3 things that differ from the Education version

  1. EXP6 stays in Robot Inventor mode until you take out its battery: once a program has created MBC_EXP6, the App's device screen no longer sees the EXP6. To go back to a SPIKE Prime hub, or to let the App see it, take the EXP6 battery out and put it back.
  2. No heartbeat to write: the library handles it in the background.
  3. The motors stop by themselves after the program ends: a motor still running when the program ends stops within about 10 seconds. To keep a motor running longer than 10 seconds while your program calls nothing, wait with exp.keep_alive_wait(ms), for example exp.keep_alive_wait(15000).

10 examples (all run on a real hub; EXP6 in hub port F, motors in EXP6 ports 1 and 2; the examples print their messages in Chinese)

Example What it does
01_Motor_Basic Motor speed, forward / back, stop
02_Motor_Advanced Encoder angle, turn by degrees, absolute angle
03_Drive_Base Two-motor drive base (straight, turns)
04_Sensor_Distance_Force LEGO distance and force sensors
05_Sensor_Color_Pro LEGO colour sensor: colour code, reflection, RGB, HSV
06_System_Misc Voltage, device codes, raw values
07_Motor_Inverted Motor mounted normally / reversed
08_Stop_Modes The 4 stop modes compared
09_MBC_Sensors Line Follower, Laser Ranger 2-ch, PS4 gamepad, SharpShot Vision (sensor in EXP6 port 2)
10_MBC_Commands Commands to a Line Follower 8-ch: change the threshold, failed, rejected, restore

Troubleshooting

What you see Why What to do
ImportError: no module named 'projects.mbc_exp6…' Not installed yet, or a firmware update wiped it Run the installer again
ImportError with the line from MBC_exp6_SPIKE_App_Lib import … That is the Education version's import Change it to from projects.mbc_exp6.MBC_exp6_SPIKE_App_Lib import …
"讀不到擴充板資料" (cannot read the expander) Wrong hub port, or EXP6 has no power Check MBC_EXP6(port.X) against the real port, and the EXP6 battery
The App's device screen cannot see EXP6 EXP6 is in Robot Inventor mode Take the EXP6 battery out and put it back
The motors stop after a while Nothing called the library for 10 seconds Wait with exp.keep_alive_wait(ms)
The hub switches off during install The transfer was interrupted Install again over USB
MemoryError The program is too big and uses many kinds of MBC sensor (core about 26 KB, MBC sensors up to another 19 KB; the App has about 98 KB, leaving about 37 KB) Split the program and restart the hub
Garbage readings from an MBC sensor (e.g. the gamepad shows many buttons pressed) The declared sensor is not the one plugged in Declare the sensor that is really there

The old SPIKE Prime App 2.x has not been tested; use SPIKE 3 (Education) or the Robot Inventor App.

First test

  1. Connect the hub to the App over USB or Bluetooth.
  2. Open example 1 on this page and press Run.
  3. Move your hand or the mat in front of the sensor: if the number changes, everything is connected.

FAQ

  • Nothing happens when I plug it in? Check in order: both ends of the cable firmly in → another hub port → another cable → another hub.
  • Different Apps give different numbers? The Education (yellow hub) and home (teal hub) editions use different formats. Check which edition you have and use its readings.
  • Do I need an adapter or a driver? No. The connector and protocol are the same as a LEGO hub port; it is recognised automatically.
  • Example 6 won't open in the official App? Examples marked "Pybricks only" use a new mode in firmware from 2026-10 on, which the official App blocks cannot read.

Examples

Example 1: One motor turns one full turn

What this example does: the motor on expansion port 1 turns one full turn (360 degrees) and the hub display shows the angle; then it turns one full turn back to where it started and the display shows about 0.

What you need

  • 1 SPIKE hub, 1 EXP6 (with battery connected)
  • 1 LEGO motor

How to wire it: EXP6 Host cable → hub port C; motor → EXP6 expansion port 1.

Download the program

Official LEGO App
ex01_one_turn.llsp3
🟨 Official LEGO App program (Python)
# EXP6 範例 1:一顆馬達轉一圈再轉回來(官方 SPIKE App・Python)
# 接線:EXP6 的 Host 線 → 主機 C 孔;馬達 → EXP6 擴充孔 1;EXP6 接上電池
# 第一次用:先執行一次 install_exp6_lib.llsp3,把函式庫裝進主機
from hub import port, light_matrix
import time
from MBC_exp6_SPIKE_App_Lib import MBC_EXP6

exp6 = MBC_EXP6(port.C)      # EXP6 接在主機 C 孔
time.sleep(2)                # 等 2 秒,讓擴充孔上的馬達準備好(太早下指令會被忽略)

exp6.motor_run_degrees(1, 50, 360, 2)    # 擴充孔 1:速度 50%,轉 360 度(一圈),到了就煞車(2)
time.sleep(1.5)                          # 等它轉完(還沒轉完就送下一個轉角度指令,會被丟掉)
light_matrix.write(str(exp6.get_motor_angle(1)))   # 螢幕顯示現在的角度(大約 360)
time.sleep(2)

exp6.motor_run_degrees(1, 50, -360, 2)   # 角度寫負的 = 反方向轉一圈,回到原來的位置
time.sleep(1.5)
light_matrix.write(str(exp6.get_motor_angle(1)))   # 大約 0
time.sleep(2)

exp6.stop_all(1)             # 最後一定要全部停止(1 = 滑行)

Understanding the program step by step

  1. Connect to EXP6: tell the hub that EXP6 is on port C. The official App writes port.C; Pybricks writes 3 (1=A, 2=B, 3=C...); on the MBC Blocks website it is the "C connect MBC EXP6 6-way motor expander" block.
  2. Wait for the motor to be ready (rule ①).
  3. Turn 360 degrees: "expansion port 1, speed 50, turn 360 degrees, brake when done".
  4. Wait 1.5 seconds for it to finish turning (rule ②), then show the angle on the hub display.
  5. Turn -360 degrees: a negative angle = the opposite direction, back to where it started.
  6. Stop all (rule ③).

What you should see when it runs: the motor turns one full turn and stops, and the display shows about 360; 2 seconds later it turns back one full turn and the display shows about 0 (being off by a few degrees is normal).

Common problems

  • The motor does not move at all? → ① Is the battery connected and charged? ② Is the motor in port 1? ③ Is the Host cable in hub port C?
  • Only the first turn happened, not the second? → The wait in between is too short; the first turn was not finished yet. Make "wait 1.5 seconds" longer.
  • Want it to turn the other way? → Make the angle negative. The official App library only looks at the sign of the angle, so a negative speed does nothing; to keep all three versions behaving the same, speeds on this page are always positive.

Example 2: Three motors turn together

What this example does: 3 motors turn at the same time at different speeds for 3 seconds (slow, medium, fast), then all reverse together for 3 seconds, then all brake and the hub beeps once.

What you need: the same as example 1, but with 3 motors.

How to wire it: EXP6 Host cable → hub port C; motors → EXP6 expansion ports 1, 2, 3.

Download the program

Official LEGO App
ex02_three_motors.llsp3
🟨 Official LEGO App program (Python)
# EXP6 範例 2:三顆馬達一起轉(官方 SPIKE App・Python)
# 接線:EXP6 的 Host 線 → 主機 C 孔;馬達 → EXP6 擴充孔 1、2、3;EXP6 接上電池
from hub import port, sound
import time
from MBC_exp6_SPIKE_App_Lib import MBC_EXP6

exp6 = MBC_EXP6(port.C)
time.sleep(2)                # 等馬達準備好

exp6.motor_run(1, 30)        # 擴充孔 1:速度 30%(慢)
exp6.motor_run(2, 50)        # 擴充孔 2:速度 50%
exp6.motor_run(3, 70)        # 擴充孔 3:速度 70%(快)
time.sleep(3)                # 一起轉 3 秒

exp6.motor_run(1, -30)       # 速度寫負的 = 反轉
exp6.motor_run(2, -50)
exp6.motor_run(3, -70)
time.sleep(3)

exp6.stop_all(2)             # 全部停止(2 = 煞車,馬上停)
sound.beep(880, 200)

Understanding the program step by step

  1. Wait for all 3 motors to be ready: the MBC Blocks website and Pybricks check "device code = 5" one motor at a time.
  2. Run continuously: "expansion port 1 speed 30", "expansion port 2 speed 50", "expansion port 3 speed 70". Once a run command is sent, the motor keeps turning and the program moves straight on, so all 3 start almost at the same time.
  3. Wait 3 seconds.
  4. Change the speeds to negative → all 3 reverse together, then wait another 3 seconds.
  5. Stop all, 2 = brake, then one beep.

What you should see when it runs: 3 motors turn together, one slow, one medium, one fast; after 3 seconds they all turn the other way; after another 3 seconds they all stop and the hub beeps.

Common problems

  • One of them does not turn? → That motor is in the wrong port number, or is not plugged in firmly. Move it to a different port to find out whether the problem is the motor or the port.
  • Speed 100 is very fast and very strong? → EXP6 drives the motors straight from the battery; at high speed a motor mounted in a mechanism can easily break something, so start with 50 or lower.

Example 3: Light switch (color sensor controls a motor)

What this example does: hold a sheet of white paper in front of the color sensor (bright) → the motor turns and the hub light turns green; take it away (dark) → the motor stops and the light turns red. Hold the left and right buttons together to end the program.

What you need

  • The same as example 1, plus
  • 1 SPIKE Color Sensor, 1 sheet of white paper

How to wire it: EXP6 Host cable → hub port C; motor → expansion port 1; color sensor → expansion port 4.

Download the program

Official LEGO App
ex03_light_switch.llsp3
🟨 Official LEGO App program (Python)
# EXP6 範例 3:光控開關(官方 SPIKE App・Python)
# 感應器前面亮(放一張白紙)→ 馬達轉、主機燈變綠;暗 → 馬達停、燈變紅
# 接線:EXP6 的 Host 線 → 主機 C 孔;馬達 → 擴充孔 1;顏色感應器 → 擴充孔 4;EXP6 接上電池
from hub import port, button, light
import color
import time
from MBC_exp6_SPIKE_App_Lib import MBC_EXP6

exp6 = MBC_EXP6(port.C)
time.sleep(2)

while not (button.pressed(button.LEFT) and button.pressed(button.RIGHT)):   # 左右鍵一起按住 → 結束
    bright = exp6.get_color_reflection(4)    # 擴充孔 4 的顏色感應器:反射光 0~100(越亮越大)
    print(bright)                            # 在電腦畫面印出來,方便看數字
    if bright > 50:                          # 亮 → 馬達轉
        exp6.motor_run(1, 50)
        light.color(light.POWER, color.GREEN)
    else:                                    # 暗 → 馬達停
        exp6.motor_stop(1, 2)
        light.color(light.POWER, color.RED)
    time.sleep(0.1)

exp6.stop_all(1)             # 結束前一定要全部停止

Understanding the program step by step

  1. Repeat until the left and right buttons are held together: everything inside keeps running; pressing both buttons at once jumps out.
  2. Read the reflected light: how bright the color sensor on expansion port 4 sees (0 to 100, bigger = brighter), stored in a variable called "brightness" (a variable is a box with a name that holds one number), and also printed on the computer screen.
  3. If brightness > 50 → the motor turns and the light turns green.
  4. Else → the motor stops (brake) and the light turns red.
  5. Wait 0.1 seconds, then check again.
  6. After jumping out → stop all.

What you should see when it runs: with nothing in front of the sensor: red light, motor not moving. Bring the white paper close to the sensor (1 to 2 cm): green light, motor turns. Take it away and it stops again. Hold the left and right buttons together: the program ends and the motor stops.

Common problems

  • Always red / always green? → Look at the numbers printed on the computer screen: note the value with the paper in place and with it away, and change "50" to a value between the two.
  • The official App's numbers differ from the other two versions? → That is normal. The official App library estimates brightness from the sensor's red, green and blue readings, while Pybricks and the MBC Blocks website read the sensor's true reflected light, so the same sheet of paper gives slightly different numbers.
  • Always reads 0? → Is the color sensor in port 4? EXP6 only recognizes the LEGO SPIKE Color Sensor.

Example 4: Control a motor with the hub buttons

What this example does: hold the left button → the motor turns forward; hold the right button → it reverses; let go → it stops. Hold the left and right buttons together to end the program.

What you need: the same as example 1.

How to wire it: EXP6 Host cable → hub port C; motor → expansion port 1.

Download the program

Official LEGO App
ex04_button_motor.llsp3
🟨 Official LEGO App program (Python)
# EXP6 範例 4:用主機按鈕控制馬達(官方 SPIKE App・Python)
# 按住左鍵 → 正轉;按住右鍵 → 反轉;放開 → 停;左右鍵一起按 → 結束
# 接線:EXP6 的 Host 線 → 主機 C 孔;馬達 → EXP6 擴充孔 1;EXP6 接上電池
from hub import port, button
import time
from MBC_exp6_SPIKE_App_Lib import MBC_EXP6

exp6 = MBC_EXP6(port.C)
time.sleep(2)

while not (button.pressed(button.LEFT) and button.pressed(button.RIGHT)):   # 左右鍵一起按住 → 結束
    if button.pressed(button.LEFT):          # 按住左鍵
        exp6.motor_run(1, 50)                # 正轉,速度 50%
    elif button.pressed(button.RIGHT):       # 按住右鍵
        exp6.motor_run(1, -50)               # 反轉
    else:                                    # 都沒按
        exp6.motor_stop(1, 2)                # 停止(2 = 煞車)
    time.sleep(0.05)

exp6.stop_all(1)             # 結束前一定要全部停止

Understanding the program step by step

  1. Repeat until the left and right buttons are held together (same as example 3).
  2. If the left button is held → expansion port 1 speed 50 (forward).
  3. Else, if the right button is held → speed -50 (reverse).
  4. Neither pressed → stop (brake).
  5. Wait 0.05 seconds, then check the buttons again.
  6. After jumping out → stop all.

What you should see when it runs: hold the left button and the motor turns, let go and it stops; hold the right button and it turns the other way. Hold both together and the program ends.

Common problems

  • Why not use the center button? → The center button is the hub's power switch and also the stop-program button, so the examples on this page do not use it to control the motor.
  • A short delay after pressing before it turns? → The program checks the buttons every 0.05 seconds, and the official App also takes a moment to send the command, so a small lag is normal.
  • Pressed stop in the official App but the motor is still turning? → Rule ③: the official App has no automatic protection. End the program by "holding the left and right buttons together"; if it really will not stop, turn the hub off.

Example 5: Two-wheel car drives a square

What this example does: a two-wheel car drives straight about 35 cm → turns right 90 degrees in place, repeated 4 times, driving a square and coming back to the start.

What you need

  • The same as example 1, plus
  • A two-wheel car (two motors as wheels, wheel diameter 56 mm, wheel spacing 112 mm, i.e. the standard LEGO car)
  • A flat floor area (about 50 × 50 cm)

How to wire it: EXP6 Host cable → hub port C; left wheel motor → expansion port 1, right wheel motor → expansion port 2.

Download the program

Official LEGO App
ex05_square.llsp3
🟨 Official LEGO App program (Python)
# EXP6 範例 5:兩輪小車走正方形(官方 SPIKE App・Python)
# 接線:EXP6 的 Host 線 → 主機 C 孔;左輪馬達 → 擴充孔 1;右輪馬達 → 擴充孔 2;EXP6 接上電池
# 小車:輪子直徑 56 mm、兩輪距離 112 mm(樂高標準小車)
from hub import port
import time
from MBC_exp6_SPIKE_App_Lib import MBC_EXP6

exp6 = MBC_EXP6(port.C)
exp6.set_motor_inverted(1, True)   # 左輪是反過來裝的:設成「反裝」,速度正的才會往前
time.sleep(2)                      # 等馬達準備好

for side in range(4):              # 正方形有 4 個邊
    exp6.reset_angle(2)                        # 右輪角度歸零,用來量走了多遠
    exp6.drive(1, 2, 40, 40)                   # 左輪孔 1、右輪孔 2,兩輪都 40% → 直走
    while exp6.get_motor_angle(2) < 720:       # 右輪轉滿 720 度(2 圈,大約 35 公分)
        time.sleep(0.01)
    exp6.stop_all(2)                           # 煞車
    time.sleep(0.3)

    exp6.reset_angle(2)
    exp6.drive(1, 2, 30, -30)                  # 左輪往前、右輪往後 → 原地右轉
    while exp6.get_motor_angle(2) > -180:      # 右輪倒轉 180 度 ≈ 車子轉 90 度
        time.sleep(0.01)
    exp6.stop_all(2)
    time.sleep(0.3)

exp6.stop_all(1)                   # 結束前一定要全部停止

Understanding the program step by step

  1. Set the left wheel as "inverted": the car's two motors are mounted mirror-image, so the left wheel turns the opposite way from the right wheel. Once it is set as inverted, both wheels follow "positive speed = forward".
  2. Wait for both motors to be ready.
  3. Repeat 4 times (4 sides of the square):
    1. Reset the right wheel angle to zero: we will use it to measure how far the car has gone.
    2. Drive both wheels: "left wheel port 1, right wheel port 2, left 40, right 40" → straight ahead. EXP6 keeps the two wheels in sync, so it drives straighter.
    3. Wait until the right wheel has turned 720 degrees (2 turns ≈ 35 cm) → stop all (brake), pause 0.3 seconds.
    4. Reset the right wheel angle again, "left 30, right -30" → left wheel forward, right wheel backward → turn right in place.
    5. Wait until the right wheel has turned back 180 degrees → the car has turned exactly 90 degrees (wheel turns 180 degrees × wheel diameter 56 ÷ wheel spacing 112 = 90 degrees) → stop.
  4. Stop all (coast).

What you should see when it runs: the car drives a stretch, turns right, drives a stretch, turns right... after 4 sides it ends up roughly back where it started.

Common problems

  • The car spins in place and does not go forward? → The left wheel is not set as inverted, or the two motors are swapped (the left wheel must be in port 1).
  • The car drives backward? → The motors are mounted the opposite way from the standard LEGO car: set expansion port 2 as inverted instead (official App / Pybricks: change the 1 in set_motor_inverted(1, True) to 2; MBC Blocks website: change the expansion port in the "mounting direction" block to 2); no need to change the wiring.
  • Turns less than 90 degrees / more than 90? → The floor is slippery or the wheels are not the same size. Make 180 bigger (not turning enough) or smaller (turning too much), 5 to 10 at a time.
  • The sides are not the same length? → Make 720 bigger or smaller. 720 degrees ≈ 35 cm, so every 100 degrees is about 5 cm.

More questions

  • The hub does not detect the sensor? Unplug and replug, wait 2 s, try another port. The official app shows it as a colour sensor — that is expected.
  • Can I use the official app and Pybricks on the same hub? One firmware at a time: Pybricks and the MBC Blocks website need Pybricks firmware, the official app needs LEGO firmware; you can switch back any time with the SPIKE app.

Still stuck? Contact us with your software and a screenshot of the program.

Downloads

Sources

  • Host and software list:_build/guides.json
  • Setup:_build/guides/software/spike-official.en.md、_build/guides/product/exp6/spike-official.en.md
  • Examples:sensors/exp6/spike-examples.md
Email for a quoteBuying Guide