Products for USB Sensing and Control
Products for USB Sensing and Control

Create a 2D Plotter with Phidgets

Encoders and DC Motors for fun and precision

by Ben +

About Ben

I am an engineering physics student at UBC and had the opportunity to intern at Phidgets for the summer. Phidgets allowed me to explore my interests in robotics and control, while making some cool projects along the way!

Of all the projects, this was definitely my favorite: it combined robotics, the fancy math of control, and the fun of programming physical systems -- all the things I love about projects.

When I’m not making robots at Phidgets, I keep busy with a number of hobbies. These include playing the oboe in various ensembles, teaching sailing at the Glenmore Sailing School, or racing sailboats myself.


In this project, I created a 2D Plotter. The project allowed me to form a better understanding of how a CNC machine works, and the drawings produced were a great way to impress friends.

Background Knowledge

Before attempting this project, I had worked through the following projects:

  • The Getting Started Kit.
  • The Rover Kit

For more information, check out the Student Page


Hardware: Construct a device to move a pen/marker around a vertical surface.
Software: To create a program that would move a pen/marker around a surface to draw any given image.

Parts Inventory

The parts I used from Phidgets are listed below. The rest of the parts I used (the thread, marker and white board, etc.) can be found at a local hardware or office supply store.


Pen Mount

At the start I faced two major challenges: getting the pen to be positioned perpendicular to the white board, and designing a method to hang and move the pen.

To hang and move the pen I used two peices of fishing line. This setup will become more clear in later sections.

For the position of pen, I have opted for the simple solution of using the carboard from my phidgets boxes and a CD. The CD prevents the pen from tipping over during plotting.

Motor Assembly

I decided to use two identical motor assemblies to control the pen position. I mounted them to the top two corners of the whiteboard. The fishing line was attached from motor assembly to pen, so the pen was suspended between the two.

The motor assembly consisted of a DC motor, an encoder, a mounting bracket and a sprocket. When using DC motors with position control, encoders are required. This allows the DC Motor Phidget to keep track of the position and velocity of the DC motor. Installation instructions for the encoders can be found here.

Next, the motors must be mounted to a rigid structure. Here I have used the NEMA mounting brackets and a piece of aluminum.

To fix the strings to the sprockets, I wrapped the string around the sprocket 3 times for traction and then fixed it in place with a few overhand knots.

Lastly, I connected my motors to a power supply.


Plotter Mechanism

Part 1

This plotter makes use of two motors controlling lengths of string attached to a pen. Each motor can rotate to pull the pen closer to its side while gravity pulls the pen down.

The basic calculation to find the string lengths only requires the Pythagorean theorem for right triangles.

`l_0^2 = x^2 + y^2`

The only additional complicating factor is introduced by whatever mechanism is used to attach the strings to the motors. I chose a rectangular mount so I had to make some minor modifications to make things work.

Part 2

Next, to calculate the proper position of the motor, the difference in the string length for each encoder step must be calculated.

`"length per step" = (2pi)/"steps per revolution" * "gearing ratio" * "axel radius"`

In my setup the pen begins with both controlling strings at maximum extension and the step count at 0 in this position. Thus to calculate the new stepper position given a coordinate, the difference between fully extended and the coordinate must be calculated.

Implementing the Controller

I have opted to write this project in Python because there are many useful Python libraries already created that would be useful for this project:

  • MatplotLib - Mathematical Plotting Library
  • Numpy - Numerical Python
  • Pillow - Python Imaging Library

I developed a class to control the DC motors. It has two main features: an initialisation routine and a go-to-point function.

It is also helpful to have a method to engage/disengage and zero the motors.

This object should have the following flow:


As there is no way to lift the pen, this printer can only print one continuous line. This presents an interesting challenge. In order to print pictures using this printer, we need a method to generate lines that are darker in darker areas of an image.

Hilbert Curves

The method I used to print in one continuous line was inspired by this post. One response used Hilbert curves to generate an image. Using this method, a curve can be generated and then printed.

Sine Waves

The rendering method I selected uses sine waves to generate an image. The basic idea is to draw a line through an image which oscillates more when the image is darker (the frequency depends on the pixel values of an image). A single line approximation of the original image can then be printed using the plotter. When I rendered the image using MatPlotLib, numpy arrays significantly improved performance.

Finished Product

The final images were quite successful! It is worth noting that the images become clearer at a distance.


There are a lot of creative drawing options to explore with this printer. This also provides an introduction to controlling CNC type devices.

Get In Touch

Have a cool project or suggestions for future education projects? Let us know at