STARLEAP / SPIKE PRIME PYTHON / 2026–27
Build 2026.09.22-090630-0400
On this page
Project 06: Bouncing Rhino Arena
You need: a LEGO SPIKE Prime set and the SPIKE App Python editor.
Goal
Make Rhino drive until the bumper hits something, back away, turn, and keep going.
This is a core class challenge. Multiple Rhinos can run in the same arena if they bounce away safely.
Build
Build Rhino from the LEGO SPIKE Prime building instructions.
Starting ports:
- left wheel: Port B
- right wheel: Port A
- bumper force sensor: Port C
If your build uses a different bumper port, change the bumper label.
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
- A helper function gives a group of code a name.
runloop.until()waits for the bumper.while Truerepeats until you manually stop the program.- Printing labels helps you see what the robot is doing.
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: Stop On Bump
Open a new Python project named Rhino Arena.
Start with this short code:
from hub import port
import runloop
import motor_pair
import force_sensor
left_wheel = port.B
right_wheel = port.A
bumper = port.C
def bumper_pressed():
return force_sensor.pressed(bumper)
async def main():
motor_pair.pair(motor_pair.PAIR_1, left_wheel, right_wheel)
motor_pair.move(motor_pair.PAIR_1, 0, velocity=350)
await runloop.until(bumper_pressed)
motor_pair.stop(motor_pair.PAIR_1)
runloop.run(main())
Run the program facing a wall, box, or bin.
Observe: Rhino stops when the bumper is pressed.
Step 2: Add Helper Functions
Add these above main():
def go_forward():
print("forward")
motor_pair.move(motor_pair.PAIR_1, 0, velocity=350)
def stop():
print("stop")
motor_pair.stop(motor_pair.PAIR_1)
async def back_turn():
print("back turn")
await motor_pair.move_for_degrees(motor_pair.PAIR_1, -180, 80, velocity=300)
Change main():
async def main():
motor_pair.pair(motor_pair.PAIR_1, left_wheel, right_wheel)
go_forward()
await runloop.until(bumper_pressed)
stop()
await back_turn()
Run the program.
Observe: Rhino drives, bumps, stops, backs away, and turns.
Step 3: Name The Whole Behavior
Add this above main():
async def bounce_once():
go_forward()
await runloop.until(bumper_pressed)
stop()
await back_turn()
Change main():
async def main():
motor_pair.pair(motor_pair.PAIR_1, left_wheel, right_wheel)
await bounce_once()
await bounce_once()
Run the program.
Observe: Rhino should bounce twice.
Step 4: Keep Bouncing
Change main():
async def main():
motor_pair.pair(motor_pair.PAIR_1, left_wheel, right_wheel)
while True:
await bounce_once()
Run the program in the arena.
Stop the program manually when you are done.
Physical Challenge: Bouncing Rhino Arena
- Level 1: Rhino bounces away once
- Level 2: Rhino bounces away three times without help
- Level 3: Rhino runs with another Rhino in the same arena
- Level 4: Rhino bounces away without getting stuck in a corner
Tune one value at a time:
- forward velocity
- reverse degrees
- steering during the reverse turn
- reverse velocity
Extra setup idea: Try the Walled Cleanup Area from the Challenge Setups sheet.
Teacher Check
Show your teacher:
bumper_pressed()bounce_once()- Rhino bouncing more than once
- one number you tuned to make it safer
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.