Import the library
The first thing in the program tells Pybricks: "I want to use the Servo6 library." Without this line, the hub does not understand MBC_SERVO6 later on, and you get a NameError.
- Download the library (save the file and keep its name): MBC_servo6_Lib.py. The file name is
MBC_servo6_Lib.py. - In Pybricks Code, click "Import a file" in the file area on the left. Add it to the same project.
- Do not rename the file, and do not put it in a subfolder.
- Go back to the main program. Write these lines at the very top (marked ① in the program on the right).
The hub needs Pybricks firmware v4.0 or later. Older firmware cannot power the servos. The library file is about 25 KB, so uploading takes a little longer when you press run.