Introduction: CNC Hanging Plotter

About: 55+ years in electronics, computers, and teaching ... now retired.

This instructable describes an experimental "hanging plotter" that uses two "Arduino Uno R3" microcontrollers each of which is connected to a stepping motor. A vertical line is obtained if both motors rotate at the same speed for the same period of time. A sloping line is obtained if the motors rotate at different speeds. [1]

Using two arduinos simplifies construction as there is no limit (other than the limits imposed by I2C) as to how far the motors may be spaced. This is a distinct advantage if your motors have short leads. It also simplifies the plotting algorithm as each "motor" can have a different delay.

G-code co-ordinates are sent to the plotter via a bluetooth link. This process, along with an Inkscape tutorial on how to create images such as the flower, are fully described in my instructable https://www.instructables.com/id/CNC-Robot-Plotter/

On receipt of a g-code XY co-ordinate, the "master" arduino determines how much "cord" each motor must "pay-out", or "reel-in", the direction each motor must turn, and the required delay-between-steps such that both motors start and stop at the same time. The "master" then sends this information to the "slave" after which both motors start. Two-way I2C handshaking between the "master" and "slave" keeps the motors in "sync".

[1] The lines will actually have a slight curve depending on the length of each cord. For a given plotting area this curve decreases as the cord length is increased. Good results are obtained with cord lengths around 1000mm. Failing that just add some intermediate plotting points.

Step 1: Mathematics

Pythagoras is used to calculate the required cord-lengths for any given XY co-ordinate.

To move the pen from point A to point B we need to calculate to the difference in cord-lengths between successive co-ordinates. In this example motor 1 is required to pay-out (a1-a2) whereas motor 2 must reel-in (b1-b2).

Both motors must start and finish at the same time if you are to obtain a straight-line path between points A and B. Since each motor requires a different number of steps to move the pen from point A to point B, different delay-times are used between each of the the motor steps.

As shown, the above diagram is not practical as the pen would swing from side-to-side if we tried to plot the Inkscape XY co-ordinate 0,0. There needs to be tension in cords a1 and b1 at all times to prevent the pen from swinging. This is achieved by moving motor 1 to the left and adding this extra distance to every g-code "x" co-ordinate.

Similarly motor 2 must be moved to the right if we intend plotting along the right-hand edge of the plotting-area (shown in gray). This extra distance must be added to "X".

[Note: The 0,0 co-ordinate from Inkscape is always at the bottom-left corner of the plotting area.]

Step 2: Some Design Considerations

Resolution:

The hanging-plotter is deceptively simple. Unfortunately there is a catch. The plotter resolution changes with distance across the drawing area. Depending on the geometry this change can be significant.

The above diagram shows two motors, each at the top corner of a large square.

If motor 1 releases 1 unit of cord when the pen is at the top left corner of the square the pen is able to move 1 unit along the top edge of the square to point A. But if motor 1 releases one unit of cord when the pen is at the bottom left corner of the square the pen is able to move 6 units along the bottom edge of the square to point B. The resolution has decreased!!!!

Linearity:

If motor 2 draws a diagonal arc between the corners of the large square the pen will trace out "Arc 1" which looks nothing like a straight line. But if we reduce the plotting area the pen will trace out "Arc 2" which is fairly close to becoming a straight line.

The small square represents a 200mm x 200mm drawing area with motor cord-lengths of 1000mm. Longer cords will improve the linearity.

Extra plotting points will improve the apparent linearity.

Drum Size:

Assuming that 4096 steps are required for one revolution of the drum, the plotter has a resolution along the top edge of the plotting area of (PI * 50mm)/4096 = 0.0384 mm/step, or 26 steps/mm.

A smaller drum size will increase the number of steps/revolution. However care must be taken to avoid the cord winding over itself as this will effectively increase the drum diameter and cause distortion.

Design Notes:

  • use as small a drum as possible.
  • use long cord lengths
  • there needs to be some tension in both cords at all times to prevent the pen from swinging side-to-side.
  • a good starting point is to position the mid-point of your drawing area over the point at which the motor cords intersect at 90 degrees.With this setup one motor stays still when you draw the diagonals of a square.
  • the Inkscape 0,0 co-ordinate should be below and to the left of the mid-point by equal amounts.
  • extra plotting points will improve the linearity

Step 3: Circuit

The plotter comprises two arduino microcomputers that communicate via an I2C link. Power to both arduinos is from an external 9 volt 1 amp supply.

Both arduinos have a power supply "shield" to isolate the microcomputer from the motor (and pen-lift) load currents. Separate arduinos allow the motor controllers to be spaced further apart.

Connect the following points together:

  • all circuit grounds
  • all points labelled +5V
  • all points labelled +9V
  • all points labelled +V1
  • all points labelled +V2
  • all points labelled +Vin1
  • all points labelled +Vin2

The "master" arduino controls the left-hand motor and pen-lift. It also contains a g-code interpreter that talks to your desktop computer via a "bluetooth" serial link. The "slave" arduino controls the right-hand motor.

The 560 ohm resistors (which can be omitted) provide short-circuit protection to the arduinos and make it easier to wire the shields. The 5V TX output from the master arduino is dropped to 3.3V at the HC-06 bluetooth input by means of a 1k2 ohm / 2K2 ohm voltage-divider. The 3.3V TX output from the HC-06 bluetooth is high enough to operate the arduino RX input.

1mS and 1.5mS pulses at 20mS intervals are used to control the SG90 pen-lift.

Step 4: Motor Assemblies

For ease of placement, each motor, along with its associated controller and arduino, are mounted on a small sheet of plastic. The motor assemblies are then mounted behind the drawing board with each motor-shaft protruding through a hole to the front,

In the opening photo the master arduino is shown on the right along with the HC-06 bluetooth module and SG90 servo.

The slave arduino is on the left. The 4K7 ohm I2C pull-up resistors are on the slave unit.

The master and slave arduinos are connected by a 4-wire cable that carries the 9V power supply and I2C SCLK and SDA data lines.

Current drain with the motors stopped is approximately 130mA rising to around 500mA with both motors running.

Step 5: The Drawing Board

The drawing board is made from a sheet of 6.5mm composition board. The dimensions are not critical.

The motors, and electronics, are mounted behind the board.

30mm shaft-extenders are used to extend the motor-shafts through the board to the winch-drums. The winch drums are 65mm R/C (radio control) wheels with the tyres removed. The wheels and shaft-extenders were obtained from http://aliexpress.com

The cord from each motor is passed over a 12mm spacer to ensure that the X-spacing is constant regardless of the gondola position.

Nylon fishing line is used for the cords as it is thin. The cord is attached to each drum by passing it through a small hole in the center of of each drum and tying the ends to a 3mm nut.

Only a few turns of nylon are required as the circumference of a 50mm drum is approximately 150mm.

Step 6: The Gondola

The light-weight gondola is made from a CD container, the base of which has a hollow vertical spigot. This spigot forms the pen-holder when the top is removed.

Wrap a few turns of masking tape around the barrel of your pen, such that it forms a friction fit inside the spigot, and adjust the pen height by sliding it up and down.

I originally considered using CD centers for the bearings as these are a perfect fit around the spigot, but a much simpler approach is to place two cable ties around the spigot and loop your nylon cords between the cable-ties.

The pen is lifted by an SG90 servo, the horn of which protrudes slightly higher than the pen-tip when the servo is actuated. The drawing board angle at which the gondola and pen maintain contact at all times determines the optimum length of the servo-horn. Three point contact with the drawing board must be maintained when the pen is lifted otherwise the gondola will become unstable. If necessary shorten the servo-horn.

Two 12mm mounting posts have been attached to the lower edge of the spigot assembly. This provides three-point stability ... two posts and the pen-tip ... or two posts and the servo-horn that is used to raise or lower the pen.

A fishing sinker has been attached with cable-ties to the lower edge of the gondola. This weight provides provides tension to the plotter cords and a slight downward pressure to the pen-tip.

,

Step 7: The Code

The attached files contain the .ino code for the "master" and "slave" arduinos.

Each of these files needs to be in a folder of the same name as the .ino code. The easiest way of doing this is to copy the "master" code into a new sketch and save the sketch as "hanging plotter master".

Before attempting to upload the "master" code to your "master" arduino:

  • change the X, Y, and OFFSET values to match your plotter dimensions
  • unplug the HC-06 bluetooth module (replace the HC-06 module once the code has been uploaded)

Now copy the "hanging plotter slave.ino" code into a new sketch and upload it to the "slave" arduino. In this case there is no need to unplug the HC-06 bluetooth module.

Third Party Code

In addition to the above .ino code you will need the following software packages which are free / donation-ware:

Detailed installation instructions for each of the above third party packages may be found in my article https://www.instructables.com/id/CNC-Robot-Plotter/

[The code for my interpreter was inspired by https://github.com/MarginallyClever/gcodecncdemo]

Step 8: Code Pre-processing

This plotter only requires four of the Inkscape gcodes (viz: G0, G1, G2, G3). The code will execute significantly faster if we remove all unnecessary gcodes and comments.

In order to do this you need a copy of "Notepad++". This free text editor contains a "regular expression" search engine for finding and removing unwanted text. Notepad++ is available from https://notepad-plus-plus.org/download/v6.9.2.html

Open the file to be modified with Notepad++ and position your cursor at the top of the file.

Select "View/Show Symbol/All Characters" followed by "Search/Replace..." from the top menu bar.

Click the "Regular Expression" check box (see 1st image) and enter each of the following code sequences into the search box. Click "Replace All" after each entry:

  • %
  • \(.*\)
  • ^M.*$
  • Z.*$

The above regular expressions remove all % symbols, all comments shown in brackets, all M codes, all Z codes and the codes which follow.

Now click the "Extended Expression" checkbox (see 2nd image) and enter the following code sequence:

  • \r\n\r\n\r\n

This expression removes the unwanted carriage-returns and line-feeds created by the first sequence.

Save your file under a different name using "Save As".

Done.

Step 9: The Menu

Make a bluetooth connection with your plotter using "Teraterm". Switch your "caps lock" on as all commands are in upper case. Type the letter 'M' and a menu should appear as shown above.

The menu is reasonably self explanatory:

  • M (or M0) brings up the menu
  • G0 allows you to send the pen to a specific XY co-ordinate with the pen raised.
  • G1 allows you to send the pen to a specific XY co-ordinate with the pen lowered.
  • T1 allows you to position your pen over your 0,0 co-ordinate. Type 'E' to exit.
  • T2 allows you to scale your drawiing. For example "T2 S2.5" will scale your drawing 250%. The default scale is 100%
  • T3 and T4 allow you to raise or lower the pen.
  • T5 draws an "ABC" test pattern.

Notes:

  • all pen moves use the drawing scale set using menu option T2
  • the "17:" and "19:" numbers are the "Xon" and "Xoff" terminal handshake codes from the master arduino.

  Click here   to view my other instructables.