STARLEAP / SPIKE PRIME PYTHON / 2026–27

Build 2026.09.22-090630-0400

On this page

Debugging Field Guide

Use this whenever a robot or program does not do what you expected.

Debug Routine

  1. Say what you expected.
  2. Say what actually happened.
  3. Point to the last line you changed.
  4. Read the first useful error line.
  5. Check the port labels against the wires.
  6. Run the smallest piece that should work.
  7. Make one fix and run again.

Common Bugs

SymptomCheck First
Nothing runshub connection, battery, play button
Motor does not movewrong port, loose cable, jammed build
Wrong motor movesport labels are swapped
Program stops immediatelymissing await or code finished
Syntax errormissing colon, capitalization, quotes, parentheses
Indentation errorcode inside main(), if, for, or while must be indented
Sensor never reactswrong port or sensor reading never becomes true

Usual Program Shape

CODE
import runloop

async def main():
    pass

runloop.run(main())

Replace pass with your code.

One-Motor Test

Check the cable first, then set test_motor at the top to the port being tested. Test one freely moving motor at a time.

CODE
from hub import port
import runloop
import motor

test_motor = port.A

async def main():
    await motor.run_for_degrees(test_motor, 180, 300)

runloop.run(main())

Stop before changing the cable. If the motor is connected elsewhere, change only the test_motor assignment and run again.

Force Sensor Test

CODE
from hub import port
import runloop
import force_sensor

force_port = port.D

async def main():
    print(force_sensor.pressed(force_port))

runloop.run(main())

Change the force_port assignment at the top if your sensor is plugged in somewhere else.

Distance Sensor Test

CODE
from hub import port
import runloop
import distance_sensor

distance_port = port.B

async def main():
    print(distance_sensor.distance(distance_port))

runloop.run(main())

The distance is in millimeters. -1 means the sensor does not see anything in range.

Print Labels

Add labels before steps so you know where the program is.

CODE
print("step 1: raise arm")
await raise_arm()

print("step 2: shoot")
await shoot()

If the program stops after step 1, look inside the code for step 1.