STARLEAP / SPIKE PRIME PYTHON / 2026–27

Build 2026.09.22-090630-0400

On this page

Project 03: Hopper Driver

You need: a LEGO SPIKE Prime set and the SPIKE App Python editor.

Goal

Use two motors together and tune steering, speed, and time.

Build

Build Hopper from the LEGO SPIKE Prime building instructions. Connect the motors to Ports E and F unless your build instructions say otherwise.

Using the code: gray lines are already in your program; dark lines are the edit. Keep the shown indentation. Replace a displayed main() definition as a whole, keeping imports and the final start call.

What You Will Learn

Before you run: use a clear floor area away from table edges. Test the wheel direction with the wheels lifted, then stop before placing the robot on the floor.

Step 1: Pair The Motors

Open a new Python project named Hopper Driver.

Start with this short code:

CODE
from hub import port
import runloop
import motor_pair

left_motor = port.E
right_motor = port.F

async def main():
    motor_pair.pair(motor_pair.PAIR_1, left_motor, right_motor)
    await motor_pair.move_for_time(motor_pair.PAIR_1, 2000, 0, velocity=300)

runloop.run(main())

Run the program.

Observe: Hopper should move for 2 seconds.

Step 2: Tune Speed

Replace the movement line inside main(). Change only its velocity value:

EDIT VIEW · Gray = already there; dark = add or change
async def main():
    motor_pair.pair(motor_pair.PAIR_1, left_motor, right_motor)
    await motor_pair.move_for_time(motor_pair.PAIR_1, 2000, 0, velocity=200)

This changes only velocity from 300 to 200. Run the program, then try 500 in the same position.

Run the program after each change.

Step 3: Tune Steering

Change only the steering number:

EDIT VIEW · Gray = already there; dark = add or change
async def main():
    motor_pair.pair(motor_pair.PAIR_1, left_motor, right_motor)
    await motor_pair.move_for_time(motor_pair.PAIR_1, 2000, 40, velocity=500)

Run the program.

Change only 40 to -40, then run the program again.

Observe: Positive and negative steering turn different ways.

Step 4: Use Labels

Add these variables above main(), at the left edge:

EDIT VIEW · Gray = already there; dark = add or change
right_motor = port.F
move_time = 2000
steering = 0
speed = 300

Replace the movement line inside main() with this line:

EDIT VIEW · Gray = already there; dark = add or change
async def main():
    motor_pair.pair(motor_pair.PAIR_1, left_motor, right_motor)
    await motor_pair.move_for_time(
        motor_pair.PAIR_1, move_time, steering, velocity=speed,
    )

Run the program.

Physical Challenge

Make Hopper travel from a start line to a finish line:

Extra setup idea: Try the Line Ladder from the Challenge Setups sheet.

Teacher Check

Show your teacher:

Before You Put The Kit Away

Save your program. Stop the program before moving wires or changing the build. Show the teacher your working behavior, point to one changed line, and explain what it controls. Keep your place for next time.