MBC EXP6 6-Port Motor Expander (for LEGO® SPIKE™) × MBC SPIKE Blocks website

Control EXP6 with the MBC Blocks website in three steps

On the MBC SPIKE Blocks website you do not import the EXP6 library yourself. First, inside "Run once at start", tell the website which port EXP6 is on. Then add the main loop. Finally, put reading blocks and action blocks inside it. Work through the steps on the left and the blocks on the right grow with you. These block pictures were built on the website and exported as they are, so they look exactly like what you see there.

The website's blocks are in Chinese. Every block below comes with an English explanation: each name is written as "Chinese block name (English meaning)" so you can match it with what you see on screen. The Python the website makes also has Chinese comments; the code itself is the same.

The website is free and needs no login. The hub needs Pybricks firmware (the website's "SPIKE 主機" (SPIKE Hub) menu can install it for you). EXP6 only works with SPIKE Prime, and it needs its own battery, or the motors will not move.

1

Set up: which port EXP6 is on

The first thing in your program is the block "○ 埠 接 MBC EXP6六路馬達擴充" (port ○ has the MBC EXP6 expander) under the yellow "開機時執行一次" (Run once at start) block. That is how the website knows which port has EXP6.

Which hub port is the EXP6 Host cable plugged into?
  1. Open the MBC SPIKE Blocks website and click "+" to start a new program.
  2. In the block categories on the left, click "MBC 感應器" (MBC sensors) → "EXP6六路馬達擴充" (EXP6 expander). The first block is "○ 埠 接 MBC EXP6六路馬達擴充".
  3. Attach it under "開機時執行一次" (Run once at start) and choose C in the drop-down.
2

Add the main loop

Reading sensors and controlling motors usually has to repeat again and again, so you need the yellow "主迴圈(一直重複)" (Main loop, repeat forever). Put a "等待 100 毫秒" (wait 100 ms) block inside it first, so it goes round once every 0.1 seconds.

  1. From "控制" (Control), drag out "主迴圈(一直重複)" (Main loop) and drop it in an empty space below the setup block (they do not need to snap together).
  2. Drag a "等待 100 毫秒" (wait 100 ms) block into the main loop.

The program the website makes is put into a multitasking (async) structure for you, and it uses the EXP6 library's run_task automatically: it keeps saying hello to EXP6 in the background, so you can wait with the normal wait block, and the motors stop when the program ends.

3

Use reading blocks and action blocks

"MBC 感應器 → EXP6六路馬達擴充" has 7 reading blocks (rounded) and 9 action blocks (square). In the middle of each block, choose the same port as in step 1 (C). The "擴充孔 1" (expansion port 1) after it is the port on EXP6: enter the 1 to 6 printed on the board. Click a function and the blocks and output switch to its example.

Simulated EXP6 (seen from above): choose what is plugged into each expansion port, then watch the motors turn and see what is printed on the right

At the start, expansion ports 1 and 2 have motors, port 4 a colour sensor, port 5 an ultrasonic sensor and port 6 a force sensor, the same ports the examples use. The simulation is only an illustration: 1% motor speed counts as 10 degrees per second (a real motor depends on its model), and the sensor values are simplified. The red pointer shows which way the motor shaft points; ↻ = clockwise. When you unplug the expander, the motors stop and every reading becomes 0 (not the last value). The library prints its connection warnings in both Chinese and English, so you see them here exactly as on the hub. The website's program has a main loop and never ends by itself, so the motors keep doing the last command until you press the stop button on the hub.

An example for every block

16 blocks (7 reading, 9 action), each with an example you can copy (EXP6 on port C). Actions that run once, such as turning by an angle or stopping, go inside "開機時執行一次" (Run once at start). Things that repeat go in the main loop. Click "Try it" to jump to step 3; the blocks and output on the right switch to that example.

Things to know

  1. Use only one setup block. Each port can be set up only once. The port in the middle of every reading and action block must match the setup block; if you pick the wrong port, the website warns you before downloading.
  2. Do not mix up the two kinds of port number: the "C 埠" (port C) in the middle of a block is the hub port (where the EXP6 Host cable goes); the "擴充孔 1" (expansion port 1) after it is the port on EXP6. EXP6 only accepts LEGO motors and the LEGO colour, ultrasonic and force sensors. Plug MBC sensors straight into the hub.
  3. No library to download and no heartbeat to worry about. When the website downloads your program, it sends the EXP6 library to the hub too, and it keeps saying hello to EXP6 in the background, so just use the wait block. A turn moves on right away and does not wait for the turn to finish, so add a wait after it. Right after power-on, the motors need about 1 second to get ready, so the examples start with "等待直到" (wait until) device code = 5.
  4. Functions the website has no block for yet (use Pybricks for these): motor heading (get_motor_abs_angle), colour code and red/green/blue/hue (get_color_color, get_color_rgb, get_color_hsv, get_color_red/green/blue, get_color_hue/sat/val), stop both wheels (drive_stop; use "全部馬達停止" (stop all motors) instead), tune motor correction (motor_set_pid), raw value and data format (get_port_raw, set_port_mode), send a heartbeat by hand (keep_alive, keep_alive_wait; the website does this for you), and whether it is connected (connected).
  5. Unplugging the expander does not stop the program: readings become 0 (not the last value), the terminal prints a warning at most once a second, and it reconnects by itself when you plug it back in. Tick "Unplug the expander" on the simulated EXP6 to see this.