MBC Servo6 6-Port Servo Expander (for LEGO® SPIKE™) × SPIKE × Pybricks
Interactive tutorialSPIKE
First time? Try the interactive tutorial in your browser first, then follow the steps below with your hub.
This page covers Pybricks (Python) only: how to set it up for the MBC Servo6 6-Port Servo 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 Servo6 6-Port Servo Expander (for LEGO® SPIKE™) (SPIKE edition).
- Hub: SPIKE Prime or Robot Inventor.
- Computer: Chrome. Open code.pybricks.com and start writing; nothing to install.
- Hub firmware: must be switched to Pybricks firmware v4.1 first (the stable code.pybricks.com is v4.1.1; v4.1.0 from the MBC SPIKE Blocks website works too). Every example on this site is written for v4.1.
- Library: `` (only needed for the "import the library" method). For a new program of your own, import just
MBC_sensors.py: one file for every MBC sensor.
Note
The Pybricks 3.6.1 libraries and examples are no longer updated (the 2026 SPIKE Prime hubs cannot run 3.6.1 either). For hubs that have not been upgraded, the old files are under "Legacy (no longer updated)" on the Downloads page.
Install the software
- Open code.pybricks.com in Chrome.
- Switch the hub to Pybricks firmware. The easiest way is the MBC SPIKE Blocks website: top menu "SPIKE Hub → Install/Update Pybricks firmware", about 3 minutes.
- To go back to the official LEGO App later, switch back to the original LEGO firmware with the SPIKE App.
Make the software see the sensor
Pybricks can read the sensor two ways; pick one:
- Built-in commands (no library): read the sensor with Pybricks' own sensor commands. No extra file, quickest to start.
- Import the library: download to get more data, such as the high-resolution position and every channel.
To import the library:
- In code.pybricks.com, click "Import a file" in the file panel on the left.
- Import both the example file and ``, so they are in the same project list.
- Open the example and press ▶ to run.
Important
New projects: use
MBC_sensors.py. Old projects: just replace the one file they already use.MBC_sensors.pyis one file for every MBC sensor (the EXP6 and Servo6 expander libraries are separate downloads); writefrom MBC_sensors import MBC_LINE8, with the same class names as in the old files. The old file names (such as `` used by the examples on this page) are kept for existing programs: swap in the new file with the same name and the program needs no changes. But every old-name file is the whole shared library, so importing 3 or more of them in one program goes over the SPIKE program slot limit of about 51 KB; to mix several sensors, import onlyMBC_sensors.py.
Tip
The file name must match the name in the program's
importexactly, or you will get anImportError. The library files on this site have no version suffix, so you do not need to rename them.
Tip
Most libraries take a
multitaskargument when you create the object:Falseis normal mode, one line after another;Trueis multitask mode, where every call needsawaitin front so the robot can do several things at once.
Wiring
- Plug the sensor into hub port A with the cable (any of A~F works).
- Use the same port in the program: built-in commands use
Port.APort.F; a library'sportargument is usually16for A~F. - Latch up, push the plug in gently.
Note
Servo6 is coming soon: circuit and firmware are done and final hub testing is under way; specifications follow the release version. SPIKE Prime only (not Robot Inventor or EV3).
Wiring and power
- Host cable: plug the expander's SPIKE cable into any hub port (A~F).
- Servos: plug the 3-wire servo connectors into CN1~CN6 following the board markings (signal / VCC / GND). Servos with 500~2500 µs signals such as SG90 and MG996R work.
- No battery needed: after the handshake the hub sends battery voltage to the expander and the green LED changes from fast blinking to steady. Total servo current is limited to about 0.75 A; check the working current of high-torque servos first.
Tip
At power-on the expander outputs no pulses, so servos do not twitch. The first angle command moves straight to position (no speed ramp); later commands use the speed you set.
Add the library
- The hub needs Pybricks firmware v4.0 or later.
- Download Pybricks library + examples (.zip) and put
MBC_servo6_Lib.pyin your Pybricks project (next to the main program) so you canimportit.
Press Y on the first run
The library opens UARTDevice(port, 115200, power_pin=1) to ask the hub to send battery voltage to the expander. On the first run the console shows:
Custom electronics may damage your LEGO hub ... Press Y to proceed.Press Y (only once; the hub remembers). If you press N, the servos get no power.
from pybricks.tools import wait
from MBC_servo6_Lib import MBC_SERVO6
sv = MBC_SERVO6(1, False) # expander on port A (1=A … 6=F), False = normal mode
sv.servo_angle(1, 90) # CN1 to 90°
wait(1000)
sv.stop_all() # release all servos before the program endsTip
The expander has no watchdog: after the program ends the servos hold their last position. Call
stop_all()at the end to release them (the library'srun_taskdoes it automatically in multitask mode). After a stall auto-release, sending the same angle again does not re-power the servo; send a different angle first, orservo_release()first.
First test
- Turn on the hub and connect it in code.pybricks.com.
- Import and open example 1 on this page, then press ▶.
- If the numbers printed in the console change with what is in front of the sensor, everything is connected.
FAQ
ImportError? The library was not imported into the same project, or its file name differs from theimportname. Rename it to `` and import it again.- The example does not run, or a command is unknown? The hub firmware is too old: the examples on this site are written for Pybricks v4.1, so update the hub to v4.1 first. 3.6.1 is no longer updated; the old files are on the Downloads page.
- What happens if the sensor cable comes out? The program keeps running: the library returns the last value it read and prints one notice in the console (in Chinese and English:
MBC: Port C 讀不到感應器,先回傳上一次的值 / no sensor, using the last value); if the sensor was never connected it returnsNone. To check in your program, call the object'ssensor_ok():Trueif the last read worked,Falseif not (addawaitin multitask mode). Once you plug it back in the library keeps reading; if the sensor was missing from the start and you use multitask mode, run the program again. - An example marked "Pybricks only" shows strange numbers? It uses a new mode in sensor firmware from 2026-10 on; older firmware returns different numbers.
- The official App cannot connect any more? The hub now runs Pybricks firmware: switch back to the original LEGO firmware with the SPIKE App.
Examples
Example programs for this software are being prepared and will go live with the product; contact us if you need one sooner.
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 distance (ultrasonic) 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-pybricks.en.md、_build/guides/product/servo6/spike-pybricks.en.md - Examples:
sensors/servo6/spike-examples.md