Welcome to Building:bit Superkit repository
7.Drive stepper motor
1.Learning goals
In this course, we mainly learn how to drive stepper motor connected to the superbit expansion board through Python programming.
Stepper motor interface is located on the expansion board as shown in the figure below.

2.Wiring of motor
The stepper motor wiring need to be inserted into the Super:bit expansion board B1,B2 interface, red wiring connect to VM pin, as shown below.

3.Code and analysis
The program for this course, please view .py file.
First, we need to import the library needed for this lesson from micro:bit, superbit library is dedicated to super:bit expansion board;
display.show(Image.HEART):Display heart pattern on micro:bit matrix.
In an infinite loop, control motor rotation.
4.Writing and download code
1.You should open the Mu software, and enter the code in the edit window, , as shown below.
Note! All English and symbols should be entered in English, use the Tab key (tab key) to indent and the last line must be a space.
2.You can click the “Check” button to check if our code has an error.
If a cursor or underline appears on a line, it indicates a syntax error, please check and modify. If there is no error in the program, the bottom left of the interface will prompt that there is no problem in detection.

3.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] .

4. After the program is written, use a micro USB cable to connect the computer and the micro:bit board. Please click the ‘Flash’ button to download the program to the micro:bit motherboard (You need to click the ‘REPL’ button again to close the function of importing library files before you download the program).

5.If the download failed, please confirm whether the micro:bit is connected to the computer through the micro USB data cable, and confirm whether the Super:bit Python library has been imported.
5.Experimental phenomena
After the program is successfully downloaded, the micro: bit dot matrix will display the heart pattern.
Then, we can see that the stepper motor of the B1 interface rotates 1/4 turn (90°), the stepper motor of the B2 interface rotates 90°, and then the two rotate 360° (one cycle) together, and keep the cycle in this state .
If you need to restart, press the reset button on the back of the micro:bit board.