MBC Servo6 6-Port Servo Expander (for LEGO® SPIKE™) × LEGO SPIKE App

LEGO SPIKE App: control the Servo6 with Python

The blocks in the LEGO SPIKE App only cover LEGO's own motors and sensors. They have no servo commands, and they cannot read the current and status that the Servo6 reports. So use the app's Python instead. The SPIKE App library uses the same function names as the Pybricks library. These three steps get you started.

1. Download the SPIKE App library

Download MBC_Servo6_Official_App_Lib.zip. It contains the library MBC_servo6_SPIKE_App_Lib.py and an example, servo6_demo.py. Do not pick up the Pybricks library (MBC_servo6_Lib.py) by mistake: the two cannot replace each other.

2. Start a Python project and paste the whole library at the top

Open the LEGO SPIKE App → New project → choose "Python" (not Word Blocks). A SPIKE App project cannot hold extra files, so paste the whole content of MBC_servo6_SPIKE_App_Lib.py at the top of the program. Then write your code below it:

from hub import port
import time
# ↑ paste the whole MBC_servo6_SPIKE_App_Lib.py above this line

sv = MBC_SERVO6(port.C)        # expander on hub Port C

sv.servo_angle(1, 90)          # servo 1 to 90 degrees
time.sleep_ms(1000)
sv.servo_angle(1, 0, 10)       # turn slowly to 0 degrees, 60 degrees per second
sv.servo_wait(1)               # wait until it gets there
print("Servo 1 current mA:", sv.get_current(1))
sv.stop_all()                  # release all at the end

3. What is different from the Pybricks library

  1. To create the object, write MBC_SERVO6(port.C). Inside the brackets goes port.A to port.F. There is no multitask value.
  2. Each command waits for one hub update (about 20 to 50 milliseconds) before it goes out. So controlling 6 servos in a row takes about 6 updates.
  3. The servos do not release by themselves when the program ends. They stay at their last angle. To release them, call stop_all() at the end of the program.
  4. The other functions (servo_run, servo_release, servo_stall_config, is_stalled, get_total_current…) work the same as in the Pybricks library. To see what each one does, read the Pybricks (MicroPython) tutorial. The full list is in the Servo6 official SPIKE App guide.

Want to use blocks?

For now, the Servo6 can only be programmed with Pybricks blocks (the hub needs Pybricks firmware v4.0 or later, and block coding needs a Pybricks licence), or by writing Pybricks (MicroPython). The MBC Blocks website does not have Servo6 blocks yet.

The Servo6 is still being tested before release. The SPIKE App library has not yet been tried on every version of the app and hub. If something goes wrong, please tell us.