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
motor_pair.pair()connects two motors in code.move_for_time()runs a motor pair for a chosen time.- Steering
0goes straight. Positive and negative steering turn different ways.
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:
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:
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:
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:
right_motor = port.F
move_time = 2000
steering = 0
speed = 300
Replace the movement line inside main() with this line:
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:
- Level 1: cross the finish line
- Level 2: stop close to the finish line
- Level 3: curve around an obstacle
- Level 4: add the hub signal from Project 01 before Hopper moves
Extra setup idea: Try the Line Ladder from the Challenge Setups sheet.
Teacher Check
Show your teacher:
- where the motors are paired
- the steering value
- one number you tuned for the challenge
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.