DIY Pen Plotter with Automatic Tool Changer/CNC Drawing Machine
-
In this tutorial by How To Mechatronics You will be shown how to built a CNC pen plotter or a drawing machine but with one cool feature and that’s automatic tool change. In other words, the machine will be able to automatically change colors and so you can draw really cool stuff with it.
The construction of the machine uses 3 NEMA 17 stepper motors for the X, Y and the Z axis motion, and a small servo for the gripper. The brain of this CNC Pen plotter machine is an Arduino UNO board in combination with a CNC shield and three A4988 stepper drivers.
The work area of fairly big, 360x280mm, and the level of details this pen plotter can output is in my opinion quite impressive too. I was actually surprised how good and precise the drawings came out, especially the ones where I used a 0.6mm gel pen.
Nevertheless, now I will explain everything you need to know about building a drawing machine like this, including how to design it, connect the electronics, what firmware and software to use and how to generate G-code for it.
The work area of fairly big, 360x280mm, and the level of details this pen plotter can output is in my opinion quite impressive too. I was actually surprised how good and precise the drawings came out, especially the ones where I used a 0.6mm gel pen.
Nevertheless, now I will explain everything you need to know about building a drawing machine like this, including how to design it, connect the electronics, what firmware and software to use and how to generate G-code for it.
To begin with, let’s have a look at the design of this CNC machine.
The two main components are the MGN15H linear rails, together with their suitable sliding blocks. The motion for the X and the Y axes is provided through two GT2 Belts and some GT2 pulleys. As for the Z-axis, we have a simple reciprocating motion where the moving part slides up and down on two 6mm linear rods and suitable linear bearings. A small, hobby servo is used for gripping the pen.
A homing procedure is essential for this pen plotter as the pen holders have a specific fixed position, so the machine must have a starting point. Therefore, we must have a limit switch for each axis.
The two main components are the MGN15H linear rails, together with their suitable sliding blocks. The motion for the X and the Y axes is provided through two GT2 Belts and some GT2 pulleys. As for the Z-axis, we have a simple reciprocating motion where the moving part slides up and down on two 6mm linear rods and suitable linear bearings. A small, hobby servo is used for gripping the pen.
A homing procedure is essential for this pen plotter as the pen holders have a specific fixed position, so the machine must have a starting point. Therefore, we must have a limit switch for each axis.
Here are all the parts needed for assembling the pen plotter.
Here’s a list of components needed for assembling this DIY CNC machine. The list for the electronics components can be found below in the circuit diagram section of the article.
Once we have the two sides ready, we can secure the X-axis linear rail to them with two bolts on each side. These MGN15H rails provide very smooth and play free motion, as their sliding blocks have balls or rollers inside them.
However, before installing them, it’s a good idea to clean and grease them well in order to work properly.
Next, the Y-axis rail should go on top of the X-axis sliding block and for securing them together we will use a central mounting plate. First, we can install the Y-axis rail to the central plate using three bolts.
Then we can install the two NEMA 17 stepper motors. One goes on the top side and the other at the bottom side of the plate. As I mentioned earlier, we need some M5 bolts and nuts for installing the GT2 pulleys in place. The two pulleys here are actually idler pulleys which are used for providing grip for the X-axis GT2 belt and the toothed pulley which goes on the stepper motor.
As for installing that pulley, we should measure and level it according to the idler pulleys. As for the Y-axis, we only need one idler pulley which goes on the other side of the rail, as the belt for this axis will be installed in a loop.
Ok, next is the marriage or connecting the two axes together. We simply do that by securing the central plate to the X-axis sliding block using four M3 bolts. With this the machine got its main shape and now the Y-axis sliding block can reach any position in the work area.
We can continue now with assembling the pen lifter mechanism. This mechanism is composed of two parts, one fixed that’s bolted to the Y-axis sliding block, and the other one that will be sliding up and down. Once the fixed part is secured in place, we can install the Z-axis stepper motor on it. This stepper is also a NEMA 17 but it’s shorter, 23mm instead of 40mm, in order to cut on weight.
Then we can install the lifter which is simply attached to the shaft of the stepper. The grub screw that I had was a bit long for it, so I put lifter to the shaft without it, but its hole has a shape as the shaft so the motion will be transferred well. I actually ended up modifying this part a little but, no worries you will get the updated version of it in the download files.
Next, I inserted the four linear bearings into the sliding part and secured the micro servo in place. Then I also secured the pen holder part right next to the servo.
For connecting the fixed and the sliding parts together, first we need to pass the servo wire through a hole in the fixed part and then insert the 6mm rods from the top, through the bearings and the fixed part hole. While installing this rod, we should also insert a spring in-between the fixed and the sliding part in a way that it pushes the sliding part down.
This will help the pen to have a better contact with the work surface. At the bottom side of the fixed part, there are opening where we can insert M3 nuts and use them for securing the 6mm rods in place.
Next, we can assemble the pens holder unit that goes on one side of the machine. It’s composed of top and a bottom part with openings to accommodate up to 12 pens.
I continued with installing the belts. First, we need to measure how much length we need and cut it approximately to size. For attaching the belt to the sliding block, I made these cool belt connectors, where the belt goes around a hollow shaft and in between two walls that doesn’t allow the belt to move.
Using a M3 bolt we can secure the first connector on one side of the block, and repeat the same procedure for the other side. We can move the connectors along these slots here and so tension the belt as much as we want.
As for the X-axis, the belt will go in a straight line from one to the other side, while passing through the pulleys in a way that will provide tension or grip with the stepper motor pulley.
For tensioning the X-axis belt, I made these connectors that have a shape as the belt and so we can tight them to the sides of the machine.
Next, we can install the limit switches.
I actually ended up lowering a bit this Z-axis limit switch, and as for the X and Y limit switches I used the ones from my previous project which already had wires connected to them.
Here’s a list of components needed for assembling this DIY CNC machine. The list for the electronics components can be found below in the circuit diagram section of the article.
- MGN15H Linear Rail
- Linear Rod 6mm
- Linear Bearing 6mm
- Stepper Motor – NEMA 17
- GT2 Belt + Tooth Pulley
- GT2 Idler Pulley
- Spacer Nuts
- Bolts and Nuts set + Flat Head Screws 3x16mm
Once we have the two sides ready, we can secure the X-axis linear rail to them with two bolts on each side. These MGN15H rails provide very smooth and play free motion, as their sliding blocks have balls or rollers inside them.
However, before installing them, it’s a good idea to clean and grease them well in order to work properly.
Next, the Y-axis rail should go on top of the X-axis sliding block and for securing them together we will use a central mounting plate. First, we can install the Y-axis rail to the central plate using three bolts.
Then we can install the two NEMA 17 stepper motors. One goes on the top side and the other at the bottom side of the plate. As I mentioned earlier, we need some M5 bolts and nuts for installing the GT2 pulleys in place. The two pulleys here are actually idler pulleys which are used for providing grip for the X-axis GT2 belt and the toothed pulley which goes on the stepper motor.
As for installing that pulley, we should measure and level it according to the idler pulleys. As for the Y-axis, we only need one idler pulley which goes on the other side of the rail, as the belt for this axis will be installed in a loop.
Ok, next is the marriage or connecting the two axes together. We simply do that by securing the central plate to the X-axis sliding block using four M3 bolts. With this the machine got its main shape and now the Y-axis sliding block can reach any position in the work area.
We can continue now with assembling the pen lifter mechanism. This mechanism is composed of two parts, one fixed that’s bolted to the Y-axis sliding block, and the other one that will be sliding up and down. Once the fixed part is secured in place, we can install the Z-axis stepper motor on it. This stepper is also a NEMA 17 but it’s shorter, 23mm instead of 40mm, in order to cut on weight.
Then we can install the lifter which is simply attached to the shaft of the stepper. The grub screw that I had was a bit long for it, so I put lifter to the shaft without it, but its hole has a shape as the shaft so the motion will be transferred well. I actually ended up modifying this part a little but, no worries you will get the updated version of it in the download files.
Next, I inserted the four linear bearings into the sliding part and secured the micro servo in place. Then I also secured the pen holder part right next to the servo.
For connecting the fixed and the sliding parts together, first we need to pass the servo wire through a hole in the fixed part and then insert the 6mm rods from the top, through the bearings and the fixed part hole. While installing this rod, we should also insert a spring in-between the fixed and the sliding part in a way that it pushes the sliding part down.
This will help the pen to have a better contact with the work surface. At the bottom side of the fixed part, there are opening where we can insert M3 nuts and use them for securing the 6mm rods in place.
Next, we can assemble the pens holder unit that goes on one side of the machine. It’s composed of top and a bottom part with openings to accommodate up to 12 pens.
I continued with installing the belts. First, we need to measure how much length we need and cut it approximately to size. For attaching the belt to the sliding block, I made these cool belt connectors, where the belt goes around a hollow shaft and in between two walls that doesn’t allow the belt to move.
Using a M3 bolt we can secure the first connector on one side of the block, and repeat the same procedure for the other side. We can move the connectors along these slots here and so tension the belt as much as we want.
As for the X-axis, the belt will go in a straight line from one to the other side, while passing through the pulleys in a way that will provide tension or grip with the stepper motor pulley.
For tensioning the X-axis belt, I made these connectors that have a shape as the belt and so we can tight them to the sides of the machine.
Next, we can install the limit switches.
I actually ended up lowering a bit this Z-axis limit switch, and as for the X and Y limit switches I used the ones from my previous project which already had wires connected to them.
With this the mechanical part of the machine is ready and we can move on with connecting the electronics.
As I mentioned, we are using an Arduino Uno board in combination with a CNC shield and three A4988 stepper drivers.
For attaching the Arduino board to machine I made an additional 3D printed part that goes on the side panel. I secured the Arduino board with two M3 bolts, and on top of it I inserted the CNC shield.
Here we need to insert three jumpers for each stepper driver in order to select 16th/step resolution, and then we insert the stepper drivers.
Then we can connect the motors to the CNC shield appropriately. For connecting the micro limit switches in place, I simple soldered wires directly to them, and on the other side soldered female pin headers which I got them from some jump wires.
As for the servo motor, I used some servo extension cables so that it can reach the CNC shield. For powering the machine, we need 12V power supply. Here’s a circuit diagram of how everything needs to be connected.
As I mentioned, we are using an Arduino Uno board in combination with a CNC shield and three A4988 stepper drivers.
For attaching the Arduino board to machine I made an additional 3D printed part that goes on the side panel. I secured the Arduino board with two M3 bolts, and on top of it I inserted the CNC shield.
Here we need to insert three jumpers for each stepper driver in order to select 16th/step resolution, and then we insert the stepper drivers.
Then we can connect the motors to the CNC shield appropriately. For connecting the micro limit switches in place, I simple soldered wires directly to them, and on the other side soldered female pin headers which I got them from some jump wires.
As for the servo motor, I used some servo extension cables so that it can reach the CNC shield. For powering the machine, we need 12V power supply. Here’s a circuit diagram of how everything needs to be connected.
Here’s the circuit diagram of how everything needs to be connected.
The components needed for this project:
The components needed for this project:
- Stepper Motor – NEMA 17
- Stepper Motor – NEMA 17 23mm
- A4988 Stepper Driver
- Servo Motor
- Arduino CNC Shield
- Arduino Uno
- Limit Switch
- DC Power Supply
There few final touches that needs to be done in order to complete this pen plotter. Here I’m installing the pen gripper which is simply attached to the servo motor through the servo horn.
For managing the cables from the pen lifter, I used a dining table mat which material was firm but flexible, so it was perfect for the job.
With this our drawing machine is completed. However, there are few things that we should note here. As the Y-axis rail is unsupported on one side and the 3D printing PLA material itself is not that rigid, when fully extended, the pen lifter was 4mm lower compared to the supported side.
That’s way too much play but I managed to solve that issue by lifting the front side of the machine a little bit. In this way I reduced the difference to around 1mm which was acceptable. if you plan to use these big rails, I would definitely suggest to support the Y-axis rail on the other side as well.
Another issue is the pen holder, because the pens don’t stay in place well in this way. Here I would suggest making the top openings bigger and add some soft material on the sides so that the pens stay in place while being easy for the machine to insert them.
Finally, we can insert a board under the whole machine so that we get a flat surface.
And that’s it, our machine is completed.
For managing the cables from the pen lifter, I used a dining table mat which material was firm but flexible, so it was perfect for the job.
With this our drawing machine is completed. However, there are few things that we should note here. As the Y-axis rail is unsupported on one side and the 3D printing PLA material itself is not that rigid, when fully extended, the pen lifter was 4mm lower compared to the supported side.
That’s way too much play but I managed to solve that issue by lifting the front side of the machine a little bit. In this way I reduced the difference to around 1mm which was acceptable. if you plan to use these big rails, I would definitely suggest to support the Y-axis rail on the other side as well.
Another issue is the pen holder, because the pens don’t stay in place well in this way. Here I would suggest making the top openings bigger and add some soft material on the sides so that the pens stay in place while being easy for the machine to insert them.
Finally, we can insert a board under the whole machine so that we get a flat surface.
And that’s it, our machine is completed.
What’s left to do now is to give life to it or make it a real CNC machine. For that purpose, we need to install a firmware to the Arduino for controlling the motion of the CNC machine and we need a control software through which we will send G-codes and tell the machine what to do.
The most popular choice for DIY CNC machines is the open source GRBL firmware. However, for this pen plotter we need a modified version of it, which can control the servo motor. This modified version called “grbl-servo”(https://github.com/cprezzi/grbl-servo), which alters the default PWM frequency of the spindle control pin (or digital pin number 11) from 1kHz to 50 Hz.
Once we download and install this GRBL firmware into the library folder of our Arduino IDE, we also need to modify its config.h file in order to enable 3 axis homing, instead of its default 2 axis homing.
As for control software, we will use GRBL-Plotter (https://grbl-plotter.de/) which is dedicated for controlling plotters and includes a graphics converter though which we can generate G-code from our images or graphics. This one is also open-source software which can be downloaded from Github https://github.com/svenhb/GRBL-Plotter/ ... g/v1.6.3.2.
Here, the first thing we need to do is connect our Arduino board to the software through the suitable COM port. Once we click the “Kill Alarm” button, on the serial monitor we will get a list of our current GRBL parameters. We need to change some of these parameters to according to our machine.
GRBL parameters
The first thing that we should adjust here is the travel resolution or the steps/mm values. These values indicate how many steps the motor should take in order to move 1mm. This depends on the type of stepper motor that we have, the selected step resolution and motion transmission, in this case the GT2 belt and pulley.
For our machine, a value of 80 steps/mm is needed for the X and Y axis to be accurate. As for the Z-axis I set a value of 40 which is actually not accurate in terms of real motion, but we cannot achieve that anyway with our reciprocating motion.
We should also set the parameter number 23, to 0, which tells where our limit switches are located, set the maximum feed rate, acceleration, maximum travel speed and the parameter number 1 to a value of 255, which keeps active the steppers all the time. However, we should note that with this enabled, especially for the Z-axis stepper, we should adjust the current limit of the A4988 driver to minimum because the shorter NEMA 17 stepper can quickly get hot.
GRBL-Plotter setup
Ok, so let’s take a look at the controller setup now. There are so many options to adjust here that it can be a bit intimidating at the beginning. Here first we need to set the Pen up and down translation to be the Z-axis and set values for the Up and Down position.
In the Tool table tab, we can define the pens color and their position. We should note here that these values are for the G53 or the machine coordinate system. This means they are defined by the hard limit switches the machine have, and the maximum travel that we set in the GRBL parameters earlier.
For defining the position of each pen, I used the offset values, which are 0 for the X and 277 for the Y axis in this case. These values position the gripper in front of the first pen, and then I just had to define the Y value for each pen, which is 21.7mm in the negative direction.
Here we can also adjust the feed rate and the up and down position for each pen individually, in case there are different pens.
Next in the Tool change tap we should select “Perform tool change on Tx M06” which tells the machine to do the tool change when this command appears in the G-code.
The “x” value after the letter T indicates the tool number from the tool table. To perform the tool change we must include a “select” and “remove” scripts, which are executed when the Tx M06 command appear. In these scripts we define the movement of the gripper in order to take or remove the tool.
For selecting a pen, the gripper is first positioned in front of the actual pen in absolute machine coordinates, the one defined in the tool table. Then the servo opens the gripper, it moves up 4 more mm, then move towards the pen in X direction and a little bit in Y direction. Then the gripper closes, lifts the pen up and move back to the same position before executing the script. For removing the pen, the script steps are the same but in reverse order.
Of course, all of these parameters depend on the pens them self, their dimension and the dimension of the holders. The only way to get this process correct is by testing and correcting values.
The most popular choice for DIY CNC machines is the open source GRBL firmware. However, for this pen plotter we need a modified version of it, which can control the servo motor. This modified version called “grbl-servo”(https://github.com/cprezzi/grbl-servo), which alters the default PWM frequency of the spindle control pin (or digital pin number 11) from 1kHz to 50 Hz.
Once we download and install this GRBL firmware into the library folder of our Arduino IDE, we also need to modify its config.h file in order to enable 3 axis homing, instead of its default 2 axis homing.
As for control software, we will use GRBL-Plotter (https://grbl-plotter.de/) which is dedicated for controlling plotters and includes a graphics converter though which we can generate G-code from our images or graphics. This one is also open-source software which can be downloaded from Github https://github.com/svenhb/GRBL-Plotter/ ... g/v1.6.3.2.
Here, the first thing we need to do is connect our Arduino board to the software through the suitable COM port. Once we click the “Kill Alarm” button, on the serial monitor we will get a list of our current GRBL parameters. We need to change some of these parameters to according to our machine.
GRBL parameters
The first thing that we should adjust here is the travel resolution or the steps/mm values. These values indicate how many steps the motor should take in order to move 1mm. This depends on the type of stepper motor that we have, the selected step resolution and motion transmission, in this case the GT2 belt and pulley.
For our machine, a value of 80 steps/mm is needed for the X and Y axis to be accurate. As for the Z-axis I set a value of 40 which is actually not accurate in terms of real motion, but we cannot achieve that anyway with our reciprocating motion.
We should also set the parameter number 23, to 0, which tells where our limit switches are located, set the maximum feed rate, acceleration, maximum travel speed and the parameter number 1 to a value of 255, which keeps active the steppers all the time. However, we should note that with this enabled, especially for the Z-axis stepper, we should adjust the current limit of the A4988 driver to minimum because the shorter NEMA 17 stepper can quickly get hot.
GRBL-Plotter setup
Ok, so let’s take a look at the controller setup now. There are so many options to adjust here that it can be a bit intimidating at the beginning. Here first we need to set the Pen up and down translation to be the Z-axis and set values for the Up and Down position.
In the Tool table tab, we can define the pens color and their position. We should note here that these values are for the G53 or the machine coordinate system. This means they are defined by the hard limit switches the machine have, and the maximum travel that we set in the GRBL parameters earlier.
For defining the position of each pen, I used the offset values, which are 0 for the X and 277 for the Y axis in this case. These values position the gripper in front of the first pen, and then I just had to define the Y value for each pen, which is 21.7mm in the negative direction.
Here we can also adjust the feed rate and the up and down position for each pen individually, in case there are different pens.
Next in the Tool change tap we should select “Perform tool change on Tx M06” which tells the machine to do the tool change when this command appears in the G-code.
The “x” value after the letter T indicates the tool number from the tool table. To perform the tool change we must include a “select” and “remove” scripts, which are executed when the Tx M06 command appear. In these scripts we define the movement of the gripper in order to take or remove the tool.
For selecting a pen, the gripper is first positioned in front of the actual pen in absolute machine coordinates, the one defined in the tool table. Then the servo opens the gripper, it moves up 4 more mm, then move towards the pen in X direction and a little bit in Y direction. Then the gripper closes, lifts the pen up and move back to the same position before executing the script. For removing the pen, the script steps are the same but in reverse order.
Of course, all of these parameters depend on the pens them self, their dimension and the dimension of the holders. The only way to get this process correct is by testing and correcting values.
Finally, let’s take a look how we can generate G-code from images with this GRBL-Plotter software.
Once we load the image, we can click on “Preview with colors from table” so we can see how the image would look like. From the image correction tab then we can play with the Brightness, Contrast, Gama and Saturation values in order to achieve colors similar to the real image or that one that we actually want. We can set the output size in mm, and in the color replacing tap, we can remove the colors that we don’t want to use.
For example, we can remove the apricot color which is the white color in the image. Then we can click on Create G-Code button and the G-code will be generated.
We can also generate G-codes from SVG files, which we can just drag and drop them, and the software will generate the G-code right away.
Before we start the plotting, we should set the 0 position wherever we want in the work area and then click the play button.
The pen plotter will start working and so we can enjoy watching it making magic.
I hope you enjoyed this tutorial and learned something new. Don't miss the next articles!
Once we load the image, we can click on “Preview with colors from table” so we can see how the image would look like. From the image correction tab then we can play with the Brightness, Contrast, Gama and Saturation values in order to achieve colors similar to the real image or that one that we actually want. We can set the output size in mm, and in the color replacing tap, we can remove the colors that we don’t want to use.
For example, we can remove the apricot color which is the white color in the image. Then we can click on Create G-Code button and the G-code will be generated.
We can also generate G-codes from SVG files, which we can just drag and drop them, and the software will generate the G-code right away.
Before we start the plotting, we should set the 0 position wherever we want in the work area and then click the play button.
The pen plotter will start working and so we can enjoy watching it making magic.
I hope you enjoyed this tutorial and learned something new. Don't miss the next articles!