MakeCode

In the CRICKIT block group, scroll down until you see the Stepper heading and the block crickit stepper move block. Be sure not to use the crickit drive stepper move block, that is for using a unipolar stepper on the Drive port shown further down.

Move a Motor Port Stepper One Direction Forever

Here is a simple program that tells the stepper to move 20 steps, then waits 10 milliseconds, and repeats forever:

You'll see the motor shaft slowly turning in the "positive" direction. If you use a bit of non-clear tape on the stepper's shaft as a small flag, you can see the rotation better.

The more steps you take at once, the more jerk in the movement but you travel faster. 10 milliseconds is the lowest value to wait between movements.

The number of steps can be positive or negative, with negative going in the opposite direction from positive, re. -20 moves 20 steps in the opposite way

Stepper motors may become warm or even hot when running continuously.

Move the Motor Port Stepper Different Directions With Buttons

An example: Moving a crane wire up and then down. This could also be any movement one way and then the opposite way. You might code this with blocks like these:

This code works as follows: When you push Button A on the Circuit Playground Express, the stepper starts to move in the positive direction. It takes 5 steps, waits 10 milliseconds, then repeats this 120 times for a total of 5 times 120 = 600 steps (3 to 6 revolutions, depending on the stepper) in a time of 120 times 50 milliseconds = 2 seconds.

If you push Button B, the same thing happens as in Button A but in reverse, because the steps taken are -5 and negative steps moves in the opposite direction.

Once you have the code running, you can change things to suit you. If 3 to 6 revolutions is too little, increase the value 120. If the speed is too slow, up the steps per movement (in positive and negative direction). If the movement is too fast, you can decrease the steps and increase the wait time.

Note that while the stepper is moving, any MakeCode music functions will stop until the stepper stops, then music can resume.

Using a Stepper on the Drive Port in MakeCode

In the CRICKIT block group, scroll down until you see the Stepper heading and the block crickit drive stepper move block.

Move a Drive Port Stepper One Direction Forever

Here is a simple program that tells the stepper to move 20 steps, then waits ten milliseconds, and repeats forever. 10 milliseconds should be the smallest pause between steps to ensure the motor settles before the next movement.

If you want to move the motor in the opposite direction, make the value negative, re. -20. The block takes positive and negative values.

Move a Drive Port Stepper Different Directions With Buttons

An example: Moving a crane wire up and then down. This could also be any movement one way and then the opposite way. You can code this with blocks like these:

This guide was first published on Jul 04, 2018. It was last updated on Jul 04, 2018.
This page (MakeCode) was last updated on Sep 17, 2020.