KevsRobots Learning Platform
By Kevin McAleer, 3 Minutes
BurgerBot has a small MicroPython library that does the hard work of driving the motors and reading the sensors, so your own programs can be short and readable. It controls the motors, the range finder, the line sensor and the pen servo.
The library is a single file, burgerbot.py, in the BurgerBot GitHub repository.
The library works with the standard MicroPython firmware for the Pico. It only uses the built-in machine, time and gc modules, so you don’t need any special firmware.
Older versions
Earlier versions of the library needed Pimoroni’s MicroPython build and used method names like
turnleft(). If you’re following an old video, grab the latestburgerbot.pyand use the names below.
| Method or property | Description |
|---|---|
Burgerbot() |
Creates the robot object and sets the speed to 0.5 |
forward(duration) |
Drives forward for duration seconds (default 0.5) |
backward(duration) |
Drives backward for duration seconds |
turn_left(duration) |
Spins left on the spot for duration seconds |
turn_right(duration) |
Spins right on the spot for duration seconds |
stop() |
Stops both motors |
left_motor(speed) / right_motor(speed) |
Sets one motor’s speed, from -1 (full reverse) to 1 (full forward) |
speed |
The speed used by forward(), backward() and the turns, from -1 to 1. Read it with bot.speed, or change it with bot.speed = 0.3 |
distance |
The distance to the nearest object from the range finder |
line_detected |
True when the line sensor sees a line |
pen_up() / pen_down() / pen_middle() |
Moves the pen servo |
Movement keeps going
forward(2)starts the motors and waits for 2 seconds, but it doesn’t stop them. Callbot.stop()when you want the robot to stop.
The library expects this wiring:
| Part | Pico pins |
|---|---|
| Left motor | GP5 (speed), GP6 (direction) |
| Right motor | GP12 (speed), GP13 (direction) |
| Range finder | GP0 (trigger), GP1 (echo) |
| Pen servo | GP16 |
| Line sensor | GP17 |
from burgerbot import Burgerbot
bot = Burgerbot()
bot.speed = 0.5
bot.forward(1)
bot.turn_left(0.5)
bot.forward(1)
bot.stop()
print("Distance ahead:", bot.distance)
Quick quiz 1 of 2
What happens after bot.forward(2) finishes?
forward() sets the motor speed and waits. It doesn’t stop the motors afterwards.Quick quiz 2 of 2
How do you make BurgerBot drive more slowly?
speed sets how fast the motors run. The number passed to forward() is how long to drive for.
You can use the arrows ← → on your keyboard to navigate between lessons.
Comments