# Building a DIY Pen Plotter: midTbot


Earlier this year, I built a DIY pen plotter (mostly) from scratch. I'd been
meaning to post a build log, because this was one of the more enjoyable hardware
projects I've worked on recently. However, it's taken a while to write-up this
project because, well,
[there was a lot of stuff going on](/blog/2020/03/24/March-Updates/).

![Completed Plotter with Ruler for Scale](https://benjamincongdon.me/blog/2020/07/12/Building-a-DIY-Pen-Plotter-midTbot/full_plotter.jpg)

## Why Build a Plotter?

So, why is it worth building a pen plotter? The short answer is, "they're cool".
The longer answer is that, despite commercial printers (ink jet, laser, etc.)
working better for general purpose printing, the quality of a pen-plotted image
is noticeably different than something that's been traditionally printed.
Plotted images can have a more natural, organic feeling to them, because they're
produced by raising and lowering a pen manually, like a human does.[^1]

I've also had a persistent curiosity with
[generative art](/blog/2019/03/07/Generative-Doodling/). Much of the community
built around generative art (colloquially,
[#plottertwitter](https://twitter.com/hashtag/plottertwitter)) uses pen plotters
to turn "bits into atoms". While most folks opt to buy a commercial plotter like
the [Axidraw](https://axidraw.com/) or restore vintage plotters from the 1980's,
there's a growing community of people building their own plotters.

## Assembling the Components

The first step in the project was collecting the bill of materials (BOM).
There's a well-researched BOM on the
[project Github](https://github.com/bdring/midTbot_esp32/blob/master/Docs/mechanical_BOM.md).
Other than the midTbot PCB, which is for sale
[on Tindie](https://www.tindie.com/products/33366583/midtbot-esp32-v2-controller-kit/),
I had to order:

-   Linear shafts and Linear Bearings (Amazon)
-   Pulleys and Idler Pulleys (Amazon)
-   Rubber Timing Belt (Amazon)
-   2 Stepper Motors (Amazon)
-   Stepper Motor Controllers (Amazon)
-   12V 3A Power Supply (Already had one)
-   Basic Hobby Servo Motor (Already had one from previous Arduino projects)
-   Assorted M3/M5 Head Screws (Home Depot, Ali Express)

I was pleasantly surprised how available most of the parts were online --
everything except for the screws/nuts were available on Amazon.

Once I received my midTbot PCB, there was some soldering and assembly to do. I
followed
[these instructions](https://github.com/bdring/midTbot_esp32/wiki/Controller-Kit-Assembly-Instructions)
to attach the homing switches, power supply, and header pins to the board.

### Printing the Chassis

The chassis of the midTbot is entirely 3D printed. There are ~7 things that you
need to print
([source files](https://github.com/bdring/midTbot_esp32/tree/master/STL) on
Github), and they're all fairly simple shapes, so the prints were easy to do.

![Completed prints of the 'feet' and tailblock pieces](https://benjamincongdon.me/blog/2020/07/12/Building-a-DIY-Pen-Plotter-midTbot/completed_print.jpg)

The hardest thing to print (and the most finicky part of the project in general)
was the
[pen mount](https://github.com/bdring/midTbot_esp32/blob/master/STL/midt_esp32_pen_mnt.stl).
This piece has some overhangs on it, so it was important to configure the
printer to add support material.

## Assembly

With the PCB assembled, mechanical parts purchased, and chassis pieces printed,
it was time to do the final assembly. Again, I followed the
[assembly instructions](https://github.com/bdring/midTbot_esp32/wiki/Assembly-Instructions)
on the project Github.

The assembly process was straightforward: the PCB gets screwed into one of the
printed pieces, the pulleys and linear rods get screwed in to the "feet" and
carriage block pieces, and the stepper motors are secured to the chassis with
the PCB "sandwiched" in between the chassis and the motors.

One difficult step was attaching the stepper motors to the PCB. Per the project
instructions, you're supposed to solder the stepper motor wires into plastic
[pin sockets](https://en.wikipedia.org/wiki/Pin_header), so you can easily
detach the motors from the PCB. But, after I tried and failed several times to
solder the stepper motors into the female socket block, I simply soldered the
female sockets to the board directly and soldered the stepper motor wires onto
solid-core jumper wires. The end result wasn't as clean as what's shown in the
project instructions, but still allowed me to hot-swap the motors if needed.[^2]

![Controller (Bottom Left), Motor Drivers (Top Left), Stepper Motors (Right)](https://benjamincongdon.me/blog/2020/07/12/Building-a-DIY-Pen-Plotter-midTbot/electronics.jpg)

Once the main "chunk" of the plotter was assembled (pictured above), the only
things left to do were to thread the timing belt around the pulleys, and attach
both ends of the belt to the pen head with a small amount of tension.

![Belt Attach Points (circled)](https://benjamincongdon.me/blog/2020/07/12/Building-a-DIY-Pen-Plotter-midTbot/full_plotter2.jpg)

The last step in assembly (and, unfortunately the most fiddly part of the whole
process) was attaching the pen holder to the "head" block. The long screw that
makes the joint between the pen holder and "head" block needs to be tuned
meticulously: If the screw is too tight, then the pen can get stuck in the "up"
position -- not returning to the "down" position when the servo retracts. On the
other hand, if the screw is too loose, then this translates to "slop" in the
pen's position, which results in wiggly drawings that are unusable.

![Pen Lift Servo Mechanism, Joint Screw/Nut (Arrow)](https://benjamincongdon.me/blog/2020/07/12/Building-a-DIY-Pen-Plotter-midTbot/servo.jpg)

At this point, the bot was assembled! I powered it on and installed a specific
version of the [Grbl_Esp32](https://github.com/bdring/Grbl_Esp32) firmware
designed for the midTbot per the
[project instructions](https://github.com/bdring/midTbot_esp32/wiki/Compiling-Firmware-for-the-MidTBot).
Grbl_Esp32 is a really nifty piece of software: it allows you to upload an run
Gcode (basically, machine readable instructions for how to move the pen) on the
plotter's Esp32 controller. Since the Esp32 has built-in wifi (and bluetooth),
its able to serve a basic web UI:

![Grbl_Esp32 Web UI](https://benjamincongdon.me/blog/2020/07/12/Building-a-DIY-Pen-Plotter-midTbot/webui.png)

The Web UI is sufficient for most tasks: homing, minor positioning adjustments,
starting/pausing/resuming prints. There are only a few tasks -- like calibration
-- that require you to drop down to the Grbl "command line".

It took me a while to get my midTbot calibrated. The project documentation was a
bit light on the specifics, so there was a lot of trial-and-error and
troubleshooting.

## Plotting, Software

Now that I had a functioning plotter bot, the next thing to do was try it out.
Of course, to do so you need to actually produce Gcode that the bot can use.
There are tons of tools to do this -- and a full discussion of Gcode/plotter
software is worth a whole other post. Suffice it to say, there are a variety of
resources on the [Drawing Bots](https://drawingbots.net/knowledge/tools)
community page that serve as a good starting point.

I spent most of my time working with [Inkscape](https://inkscape.org/)'s
Gcodetools plugin. Axidraw (which makes a commercial pen plotter) also has some
useful
[Inkscape plugins](https://wiki.evilmadscientist.com/Axidraw_Software_Installation),
although some of the functionality won't work with the midTbot. Gcodetools
nominally allows you to translate SVGs to Gcode, however this is a tedious
process. _Not just any_ SVG will work well with it; the SVG basically already
needs to be a line drawing for Gcodetools to have any hope of working correctly.
It has basic support for infilled regions too, but again you have to be careful
with it -- any slight hiccup, and it produces unusable Gcode.

To be honest, the software aspect of pen plotting is the most frustrating part
of the workflow. I haven't yet found a great toolchain for the "art" -> Gcode
pipeline, so there's a lot of finicky steps. (It doesn't help that Inkscape is a
second-class X11 app on macOS...)

## Additional Hardware Modifications

After I ordered a midTbot PCB, the creator added me to a Slack group. Some of
the other folks who'd built midTbots contributed back modifications they'd made
to their builds. I took a couple of these and added them to my bot too:

![Magnetic Pen Mount with Thumb Screw](https://benjamincongdon.me/blog/2020/07/12/Building-a-DIY-Pen-Plotter-midTbot/pen_mount.jpg)

First, I ordered heftier thumb screws for the pen attachment (as pictured); the
screws in the original BOM are tricky to manipulate by hand. Second, I printed a
magnetic detachable pen holder (as pictured) which makes it easier to add/remove
pens without disturbing the rest of the setup. If you want to do multicolor
prints, this modification is a must. Finally, I printed wider supports for the
bots frame. Supposedly, this allows you to increase the available print size of
the bot (if you also order longer linear rods). I didn't get around to actually
increasing my bot's print size, but the wider supports made the bot more stable,
and easier to attach to a work table.

## Results

After an afternoon of calibrating the bot and installing the mods I discussed
above, I got some prints that I'm pretty happy with.

![[Sierpiński triangle](https://en.wikipedia.org/wiki/Sierpi%C5%84ski_triangle)](https://benjamincongdon.me/blog/2020/07/12/Building-a-DIY-Pen-Plotter-midTbot/triangle.jpg)

Sierpinski's triangle (above) is a single line, but has a lot of intricate
detail. This is a good exercise of the precision of the stepper motors, which as
you can see is quite good. The precision also requires the pen mount to be
calibrated correctly, so that there isn't any "slop" between the pen and the
body of the plotter.

![Isometric Cube](https://benjamincongdon.me/blog/2020/07/12/Building-a-DIY-Pen-Plotter-midTbot/cube.jpg)

This was a slightly harder pattern for the bot to draw. The lines are all
straight, but there are a fair number of pen raises. Generally, the more pen
up/down cycles a print has, the greater the likelihood of failure.

I've also noticed that _where_ the pattern is in the print area of the bot makes
a difference. The closer the pen head is to the main bot chassis, the more the
pen is pulled away from the paper due to the counterweight of the "tail"
section. As such, I tried to position the prints as close to the middle of the
print area as possible. Below is what happens when the pen holder misbehaves:

![Somewhat failed 'Space Invaders' Print (Note the discontinous/missing lines)](https://benjamincongdon.me/blog/2020/07/12/Building-a-DIY-Pen-Plotter-midTbot/space_invader.jpg)

The plot isn't a complete failure, but many of the lines don't get drawn or only
get partially drawn. This is often caused by the pen mount screw being too
tight, causing the pen to get stuck in the "up" position periodically.

After I'd spent some time acclimating myself to the bot, its firmware, and
creating Gcode, I was able to get it to be pretty consistent -- even when a
print had a large number of pen cycles. I'm at the point where I can have it
print text (albeit quite slowly) without any noticeable glitching or broken
lines:

![On a lucky day, text renders quite well!](https://benjamincongdon.me/blog/2020/07/12/Building-a-DIY-Pen-Plotter-midTbot/star_wars_text.jpg)

## Conclusion

This was a fun project! I flexed my soldering skills and learned how to use a 3D
printer. I'm very happy with how the hardware portion of this project turned
out. There are still a few ergonomic things I'd like to adjust to make the
plotter more consistent -- perhaps affixing it semi-permanently to a drawing mat
to make it easier to align paper under the printer.

There's still quite a bit of work on the software front to make the printing
process easier. Ideally, this is something that you'd want to be able to iterate
quickly on -- trying different pen sizes, making slight adjustments to the
printed pattern, et cetera. Right now, the process is too fiddly for that to be
a fun experience.

I'd recommend building one of these if you're interested in pen plotters and/or
generative art. The build process was fun, and the completed bot is quite
functional!

### Additional Resources

-   [midTbot on Tindie](https://www.tindie.com/products/33366583/midtbot-esp32-v2-controller-kit/)
    (PCB kits for purchase)
-   [midTbot on Github](https://github.com/bdring/midTbot_esp32)
-   [midTbot on Thingiverse](https://www.thingiverse.com/thing:2587684)

[^1]:
    This is why most
    [automatic signature robots](https://en.wikipedia.org/wiki/Autopen) are
    essentially pen plotters.

[^2]:
    It turns out that having the ability to connect/disconnect the stepper
    motors quickly is important, as in the calibration process you may need to
    reverse the polarity of one or both of the motors.

