STARLEAP / SPIKE PRIME PYTHON / 2026–27

Build 2026.09.22-090630-0400

On this page

Project 16: Driving Base Mission Lab

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

Goal

Build a reliable multi-step robot mission using named functions.

This project is good for pairs who are ready for longer routines.

Build

Use one of these from the LEGO SPIKE Prime building instructions:

Starting ports in this packet:

Change the labels to match your build.

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: Test Wheels

Open a new Python project named Mission Lab.

Start with this short code:

CODE
from hub import port
import runloop
import motor_pair

left_wheel = port.B
right_wheel = port.F

async def main():
    motor_pair.pair(motor_pair.PAIR_1, left_wheel, right_wheel)
    await motor_pair.move_for_degrees(motor_pair.PAIR_1, 360, 0, velocity=300)

runloop.run(main())

Run the program.

Observe: The robot drives forward. If it spins, stop and check the physical motor orientation and whether the wires match the left and right wheel labels. Test again with the wheels lifted before putting it on the floor.

Step 2: Build Mission Functions

Update your existing program to match this version. Keep the gray reference lines; add or change the dark lines:

EDIT VIEW · Gray = already there; dark = add or change
from hub import light_matrix, port
import runloop
import motor
import motor_pair

left_wheel = port.B
right_wheel = port.F
attachment_motor = port.A

drive_degrees = 720
turn_degrees = 180

async def drive_forward():
    print("drive forward")
    await motor_pair.move_for_degrees(
        motor_pair.PAIR_1, drive_degrees, 0, velocity=300,
    )

async def turn_right():
    print("turn right")
    await motor_pair.move_for_degrees(
        motor_pair.PAIR_1, turn_degrees, 100, velocity=250,
    )

async def use_attachment():
    print("use attachment")
    await motor.run_for_degrees(attachment_motor, 90, 300)
    await motor.run_for_degrees(attachment_motor, -90, 300)

async def main():
    motor_pair.pair(motor_pair.PAIR_1, left_wheel, right_wheel)
    light_matrix.show_image(light_matrix.IMAGE_ARROW_N)
    await drive_forward()
    await turn_right()
    await use_attachment()
    light_matrix.show_image(light_matrix.IMAGE_YES)

runloop.run(main())

Run the program.

Observe: The robot does three named steps.

Step 3: Test One Function At A Time

In main(), comment out two steps:

CODE
    await drive_forward()
    # await turn_right()
    # await use_attachment()

Run the program with only one movement call active until it works.

Then test the next step.

Physical Challenge: Mini Mission

Choose one mission:

Levels:

Extra setup ideas: Try Line Ladder, Crater Turn Course, Collect And Return, or Disaster Site Lite 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.