Welcome to Building:bit Superkit repository
4.Drive 270° building block servo
Drive 270° building block servo
Drive 270° building block servo1. Learning Objectives2. Servo Wiring3. Code Analysis4. Write and download the program5. Experimental phenomenon
1. Learning Objectives
In this course, we mainly learn how to drive the building block servo connected to the superbit expansion board through Python programming.
The servo interface is located on the expansion board as shown in the figure below.

2. Servo Wiring
The building block servo wiring is inserted into the Super:bit expansion board S1 interface, and the servo orange wiring is inserted into the yellow pin of S1, as shown in the figure below.

3. Code Analysis
For the program of this course, please see the Drive 270° building block servo.py file.
xxxxxxxxxxfrom microbit import *import microbitimport superbitFirst, import the libraries needed for this lesson from microbit: the superbit library is dedicated to the superbit expansion board;
xxxxxxxxxxdisplay.show(Image.HEART)superbit.servo270(superbit.S1, 0)microbit.sleep(1000)display.show(Image.HEART): Display a heart pattern on the microbit dot matrix;
superbit.servo270(superbit.S1, 0): Initialize the servo to 0°;
microbit.sleep(1000): Delay 1 second.
xxxxxxxxxxwhile True: superbit.servo270(superbit.S1, 0) microbit.sleep(1000) superbit.servo270(superbit.S1, 90) microbit.sleep(1000) superbit.servo270(superbit.S1, 180) microbit.sleep(1000) superbit.servo270(superbit.S1, 270) microbit.sleep(1000) superbit.servo270(superbit.S1, 180) microbit.sleep(1000) superbit.servo270(superbit.S1, 90) microbit.sleep(1000)Infinite loop controls the servo to rotate to different angles.
4. Write and download the program
- Open the Mu software and enter the code in the editing window. Note! All English and symbols should be entered in English, use the Tab key for indentation, and the last line ends with a blank program.
- Click the thumb 'Check' button to check if there are any errors in our code. If a cursor or underline appears in a line, it means a syntax error. Please check and modify it. If there is no error, the lower left corner will prompt that there is no problem with the detection.

- Click the 'REPL' button to check whether the Superbit library has been downloaded. If not, please refer to [Preparation before class] --> [2.4 Python Programming Guide].

- After the program is written, connect the computer and microbit mainboard with a microUSB data cable, please click the 'Flash' button to download the program to the micro:bit mainboard. (You need to click the 'REPL' button again to turn off the import library file function before you can download the program normally).

- If the download fails, please confirm whether the microbit is connected to the computer normally via the microUSB data cable and the Superbit Python library has been imported.
5. Experimental phenomenon
After the program is downloaded successfully, turn on the power switch, the micro:bit dot matrix will display a heart pattern, the servo is initialized to 0°, and then we can see that the servo starts to rotate, 0°->90°->180°->270°->180°->90°->0°, the time interval is 1 second.
If you need to restart, please press the reset button on the back of the micro:bit motherboard.