One step conversion of an image to gcode for Makerbot Unicorn and Reprap style 3D Printers

How to take an image like this:

and in one step generate the gcodes required to do this:

All credit for goes to the original creator Neil Gershenfeld of  MIT Center for Bits and Atoms and David Carr of Make Your Bot who optimised the code that is in use here.

By attaching a pen to a 3D printer it is easy to turn it into a basic pen plotter. However producing the G-codes require to drive your 3D printer as a pen plotter can be anything but easy. This short guide seeks to change that. There are currently a number of ways of producing plotting paths from images. A selection includes:

 Of these options I believe is by far the simplest as once it is setup you can convert an image directly to gcode in one go with one program and with out the need to use a command prompt. The following is how to install and use

Program Installation

Download the following software for your respective OS. Note that python 2.6 must be used for to work. Either un-install newer versions or dirct to work with python2.6 only.

Generating the gcodes.

Run the that suits your hardware. I have included three types all with the same interface but each outputs slightly different gcodes.

  • ( Plotting with Z axis -> For use with a three axis Cartesian bot such as a reprap, Makerbot etc. where the pen is lifted off the page due to the movement of the Z (vertical) axis.
  • ( Plotting with solenoid or ->For use with a 2 axis bot where the pen is lifted of the page by an action such as a solenoid or a cutting action like a laser is required. (Use fan port for solenoid as it is switched on off with gcode M106 and M107. Commands need to be switched for use with a laser, see “Optimisation” below.)
  • ( Plotting with Makerbot -> For use with Makerbot Unicorn system which uses a servo to lift the pen off the page.
If you see a command prompt for a split second and then nothing when you run one of the above then recheck you have all the correct programs installed and the correct version of python (2.6!).

When the program begins do the following to test your setup:

  1. Select the test image.png file by clicking the “Input File” button and navigating to the “Test Images” folder.
  2. Set “in. per unit”: 25.4
  3. Click “Cam” button
  4. Click “Output Format” and select file type: “.gcodes”
  5. Set the following values:
    1. maximum vector: 0.75
    2. tool diameter: 0.03
    3. tool overlap: 0.1
    4. contours: 1
  6. Click “contour” and wait for the paths to be generated. They appear as red lines over the image at its edges.
  7. Click the save butting and the file will be output to the input directory.

Thats it, your done. Now load up your desired host, run the gcode and watch your bot draw. Here is a timelaps of my plotter at work.


Now that you hopefully have the basics out of the way you may want to know a little more detail. It appears that takes a black and white image, performs edge detection on the black areas and then calculates tool paths based on that. When choosing your image I recommend you keep its size under 1000pixels or else the rendering time will be come very long (hours+). For best effect use images with clear distinctions between white and black. Although other image formats such as .jpg do work they dont appear to give the same results as png images. Therefore I recommend you convert .jpg to .png and make sure the image is in black and white with high saturation using your desired image software such as irfanview. When the plotting is started the image will be plotted in the positive dictions from where ever the pen is when printing begins. Therefore you can print many images on the same page by moving the pen to a new position between prints.

Furthermore you can copy and past past multiple gcode files into one as long as you add the new starting position at the end of each file. As mentioned above you have a number of variables to play with in To the best of my knowledge this is their functions:

  • Window sizes – Changes the size of the display window of A larger window can make it easier to see when you have the settings right.
  • X Width and Y Width – The size of the image when printed. Roughly equates to the size of the image printed in cm when a .png file is used. Best to do a ‘dry run’ with out a pen first to check the size of your image then adjust accordingly.
  • Zmin and Zmax – The distance the pen is lifted using the z axis (Works for ( Plotting with Z axis  only)
  • Intensity min/max – Change these to change the level of darkness that interpreted as an edge in an image. Often a low “Intensity Max” value will help the edge detection pickup less distinct areas.
  • Inches per unit – At 24.5 roughly 1cmx1cm image should plot an 1cmx1cm image. Change the value to change the size of your image.
  • Maximum vector fit error – How closely the edge detection fits to the image. Very small values (eg <0.2) take longer to process and can lead to jagged edges. Very high values (eg >1) can lead to corner cutting.
  • Tool Diameter – The most important parameter. The size of the pen end. Lower values mean more detail but longer processing time. To big a value (eg 0.05) and you will not see the detail. Too small (0.001) and you will get artefacts in the edge detection seen as small boxes and dots.
  • Tool overlap – How close two plotted paths are next to each other when more than one contour is used (see below)
  • Contours – The number of layers of infill that will be plotted in dark areas. Set to 1 only the outline will be plotted while -1 will give a complete infill.
  • Feed rate, spindle speed and tools – all not used.

If you wish to go even further then use a text editor to modify the python script its self (eg ( Plotting with Z axis Remember to back up the original before making changes.

  • Movement speed – Open with text editor, Use Replace All (Crtl + H for notepad) to replace “F2000” with your desired feed rate (eg F1500) and for the x/y axis or replace all “F300” for z axis. Then save the file. Gcode generated will now use that speed.
  • Reverse solenoid direction – Replace all “M106 S255 (Pen Up)” with “M106 (Pen Down)” and vice versa to change the solenoid direction or for using a laser. Currently the solenoid is off when the pen is down.
  • Change unicorn serve travel distance – Change the S value (eg S50 to S60) in the “M300 S50 (Pen Up)”  and “M300 S40 (Pen Down)” commands to change the servo travel distance.
  • Change delay time after pen up and down – Replace all “G4 P120” commands with your desired delay time in miliseconds. Eg P120 (120 miliseconds) to P150 (150 miliseconds.
I have only tested the output gcodes with the repetier firmware and host and using a solenoid as the pen lift method.

Finally as was originally designed to create tool paths for milling there is nothing to stop you from attaching an engraver, laser or similar and engraving your favourite pattern or quote on something interesting.

Posted in A Reprap Project | Tagged , , , , , , , , , | 6 Comments

DIY Dual H-Bridge to control a Pen Plotter

In my previous post I pulled apart an old pen plotter revealing it to be controlled by two brushed DC motors.  In order to power each DC motor a H-bridge was required but I had none on hand. However it turns out a H bridge can be constructed from a few transistors as can be seen in this useful guide.

What I came up with uses a Darlington array (ULN2003) to serve as the NPN transistors for both H-Bridges while 2N3906 transistors are used for the PNP side. These PNP transistors are switched using PN5856 NPN transistors so that the positive voltage output of the Arduino can be used. Its powered by 12V DC running at around 150mA (300mA stall current).

Throw in a few LED’s so that its clear when each direction is activated and the pen plotter now has bidirectional control for the x and y axis. Video of it in action below:

Please note this design was only thrown together to make use of what I had on hand and there are far more effective ways of building an H-bridge.

In the video you can see the two 5kOhm potentiometers. When connected to the ADC on the Arduino they give a full scale range of 726 (256 to 982). With the largest travel distance being 260mm for the x axis this gives an upper resolution limit of approximately 0.36mm. It seems likely that mechanical limitations would limit the resolution to a value far greater than this technical upper limit.

By writing a sketch to record each pot’s value and then pulse the motors until this value is reached it is quite simple to instruct the pen plotter to move to a position and then hold there.

To take this one step further I added two external potentiometers and used them to turn the pen plotter into an overly complicated Etch A Sketch.

You can find a copy of the sketch used to control the plotter here.

I might have a go some time at using the Arduino maths library to get the pen plotter to draw some interesting shapes.

Posted in A Reprap Project | Tagged , , , | 1 Comment

Old-school Scientific Pen Plotter Teardown

I recently acquired an old Rikadenki pen plotter from a lab I work in and have decided to pull it apart to investigate how it works. It turns out to be quite unlike any of the Cartesian bots currently used by the DIY community.

The pen plotter was originally used to plot magnetic hysteresis loops of magnetic materials onto paper using a pen fixed in a holder. A voltage from a scientific instrument was fed to each axis with the size and polarity of the voltage dictating the position of the pen.

Note that all images can be enlarged by clicking on them. 

In the image above you can see the pen plotter with its x and y axis. The pen is fixed in the holder attached to the y axis and can move vertically only. The entire Y axis assembly can then move horizontally to form the x axis.

With the pen plotter turned over and its base removed the internal electronics can be seen.

It appears to be quite old in its design. As I dont have an electrical engineering background I didnt attempt to repair its existing electronics and so they were removed.

With the electronics removed two brushed DC motors and two potentiometers can be seen, one for each axis.

A thin gauge wire is used to move each axis. The potentiometers are also connected to the motors and geared such that a full movement of an axis from one end to another results in 1 full rotation of the potentiometer. It appears the potentiometers were used as position feedback. Each axis slides on a stainless steel shaft with out the use of bearings.

Looking side on these gear reductions can be seen more clearly.

Note the wire is guided by rotating spindles (seen in the bottom left) and spools around the drive wheel to ensure it doesnt slip. Springs are used to maintain tension on the wire where they are fixed to the centre of some of the hubs.

The path of each of the thin gauge wires, one for each axis, is hard to see in these images so I have tried to draw it schematically in sketchup. Note that the actual path in the pen plotter differs, but the idea is the same. This is the x axis.

When the motor turns it pulls the wire through a series of rotating guides to form a continues loop. The whole y axis assembly (the vertical grey rectangle in the image) is attached to the wires at the red points and is then moved left or right depending on the direction of the wire.

Below is the Y Axis.

When the y axis motor turns it pulls on the y axis carriage from the top of the image while also letting out wire for the carriage at the bottom of the image. This causes the y axis to move up, or down if the motor direction is reversed. If the X axis moves the whole y axis moves to the left or to the right. However, the y axis carriage does not move in the vertical direction as the y axis motor is stationary and so wire is pulled in and let out from the right side of the image where its fixed.

Here is one last higher quality photo with more parts removed.

Needless to say the movement of the x and yaxis is a lot more complex than a typical DIY belt driven 3D printer. However this complexity does have its advantages. For example, I imagine wire bought in bulk could be far cheaper than timing belts. Also DC motors a lot easier to find/buy than stepper motors. Perhaps of most interest though is the ultra low weight of the x and y assembly which could allow for very fast direction changes.

The next step is to put a H bridge together with an arduino and see if this pen plotter can be brought back to life.

Posted in A Reprap Project | Tagged , , , , , , | 8 Comments

Playing around with a heated chamber design.

For quite some time I have lusted after a 3D printer with the following specifications:

  • A 20x20x15cm build area
  • A heating print bed
  • A heated build chamber (ambient to 100C) to possibly eliminate warping.
  • A respectable print resolution and speed

Over 12 months ago I made my first serious attempt at satisfying these by designing and half building a rep-strap based on the mantis CNC design. However serious limitations in the design and a lack of free time have resulted in the ‘gunstrap’ collecting dust for over 12 months.  Among others, the problems with the gunstrap were:

  • High rolling resistance due to metal on metal sleeve baring
  • Slow speed due to needing to physically move the heavy print bed and print head. assembly.
  • Poor resolution due to the design of the Z and Y axis.
  • Extruder stepper located within the build chamber.

To overcome each of these limitations I have spent some time designing a replacement in SketcUp, as seen below.

What you see above is a fully enclosed build chamber that will be constructed from 12mm wood fibre board or similar. The blue transparent section is a double layer glass viewing window that is opened by the handle below it.

When opened, the two axis print head and print bed are accessible. To the right of the window will be a 16 character 2 line LCD display for temperature readouts and the like.

This design features the following:

  • All electrical components and motors (ex end stops) are located outside of the heated build chamber.
  • Print head weight has been reduced to as little as possible to increase print speed and resolution.
  • Rolling resistance is lowered through the use of ball bearings.
  • Scissor lift Z axis for increased stability

The scissor lift Z axis will be constructed by modifying a  lab jack similar to the one shown here. If the wooden shell, which also acts as the main structure of the printer, is removed then the workings become more clear. The modified lab scissor jack coupled to a stepper motor can be seen below (click image to enlarge).

Looking from the front top down on the two axis print head stage its seen that its composed of stainless steel shafts for guides like a Mendel, a PTFE sleeve bearing for the print head holder similar to a Ultimaker. Rather than an expensive belt I plan on sourcing some fine braided wire to use as a pulley which I have seen work quite well on older mechanical pen plotters for lab work. I plan on cutting box section aluminium from corner to comer to make L pieces to hold the guide bearings.

Feeding filament into a wades extruder on the side of the printer will be a mounted filament spool. The wades extruder will force the filament up a PTFE tube which enters the printer at a hole located at the top of the printer.

Finally, in a side compartment insulated by double thickness paralleling will be the electronics. This includes a RAMPS based stepper driver system, ATX powersupply and cooling fans.

As no low melting point plastic components or electrical equipment is contained within the build chamber I believe the high build chamber environment of 100C should be achievable. The heat will be provided by the heated print bed and print head only and will be actively circulated by a fan at the top of the chamber.

I am plananing on sourcing the bearings from and modifing them to include a flange. The stepper motors will come from for around $85 for 4,  including shipping within Australia. I have a month off before starting a PhD in 2012 so hopefully that allows enough time to get this all built and calibrated.

You can find a copy of the 3D model from here. Some parts of the model were sourced from Googles 3D warehouse including the Steep Reel, bolt, Arduino Mega, character display and ATX powersupply.

I would love to hear what people think of this design and so welcome all comments and criticisms. If you have any suggestions for improvements or alternative ideas please leave a comment!

Happy new year to all!

Posted in A Reprap Project | Tagged , , , , , , , , , , , | 5 Comments

MIT: 3-D printing with variable densities

By variable densities this video is referring to the density of the infill, not the density of the material extruded. At least that was my take on it.

Hasn’t the DIY 3D printing scene been doing this for quite some time now with the use of spars internal structures for solid objects?

Posted in Mendel Build | 5 Comments

Mike Biddle: We can recycle plastic

An interesting TED talk.

Posted in A Reprap Project | Tagged , , , | 2 Comments

Printable PCB motor?

The holy grail of a self replicating 3D printer is the ability to print its own drive train. In the long term this may be possible with some form of multi-metal stintering system that can produce a stator layer by layer. However in the near term a more viable DIY option may be to use a piezoelectric “PCB Motor”.

The printing, routing or embedding of wires to form a circuit board track is now common place and with pick and place of components well on its well this could become feasible sooner than thought.

There was already an an entry on the RepRap wiki regarding PCB motors but I cant find any evidence that they have been successfully used.

Posted in A Reprap Project | Tagged , , | 4 Comments