KevsRobots Learning Platform

Build your own BurgerBot

72% complete

Reset my progress

Drawing with a Pen

Add a pen to BurgerBot and make it draw shapes.

By Kevin McAleer,    3 Minutes


Watch the video


The pen upgrade

BurgerBot can carry a felt-tip pen in the middle of the robot. A small SG90 servo raises and lowers it, so the robot can draw as it drives, a bit like the classic Logo turtle.

Because the pen sits between the wheels, BurgerBot can turn on the spot without smudging a curve into your drawing.


Parts

The servo turns the cog, which pushes the pen holder up and down. Fit the servo holder to the robot, slide in the pen holder, then add the cog to the servo. Test fit the pen so it slides freely but doesn’t wobble.


Wiring the servo

Servo wire Pico
Brown (GND) GND
Red (power) VBUS / 5V
Orange (signal) GP16

Moving the pen

from burgerbot import Burgerbot
from time import sleep

bot = Burgerbot()

bot.pen_up()
sleep(1)
bot.pen_down()
sleep(1)
bot.pen_middle()

If the pen doesn’t reach the paper, or lifts too far, loosen the cog, turn it a few teeth and refit it.


Drawing a square

from burgerbot import Burgerbot
from time import sleep

bot = Burgerbot()
bot.speed = 0.3

bot.pen_down()
sleep(0.5)

for side in range(4):
    bot.forward(1.5)
    bot.stop()
    bot.turn_right(0.8)    # adjust until your corners are 90 degrees
    bot.stop()

bot.pen_up()
  • pen_down() lowers the pen before we start moving, and sleep(0.5) gives the servo time to get there
  • Each side is a forward movement followed by a turn
  • pen_up() lifts the pen at the end so the robot doesn’t leave a trail when you pick it up

Try it yourself

  1. Draw a triangle. How long does a 120-degree turn take?
  2. Draw a dashed line by lifting and lowering the pen as you drive
  3. Write a polygon(sides) function that draws any regular shape

Quick quiz

Why do we sleep() after pen_down() before driving?


< Previous Next >

You can use the arrows  ← → on your keyboard to navigate between lessons.


What are you looking for?
Watch Videos Get Ideas Learn Something Read a Review Read the Blog Search
... Z Z z