2016 - Python Based 3-Axis CNC Plotter
2016 - Python Based 3-Axis CNC Plotter
Abstract—This paper discusses on an open source python signal generators, driver circuitry and the machine setup. The
based three-axis CNC system. Python being one of the easiest availability of certain components is restricted to only a few
languages to understand exempts the user from requiring countries, thus making it difficult to import. Also, abundant
extreme programming skills to amend the code for personal use. software is designed only for specific machine dimensions
This paper features a novel way of directly importing the CAD making it difficult to adopt them for personal usage.
file into the system without the use of any G-code parser. This
system is economical as it utilizes Arduino UNO board as a signal After a thorough study on the above-mentioned limitations,
generator without compromising on the performance of the we propose the following:
system.
1. A more standard method to directly obtain coordinate
Keywords—Arduino; motion controller; CNC learning data from computer-aided design (CAD) models by eliminating
equipment; open source CNC learning tool; open source CNC the usage of G-code parser.
software; Python; rapid prototyping. 2. To develop a system, capable of governing at least
three-axis.
I. INTRODUCTION
3. A hardware which is less expensive and a setup which is
At present there is a rising demand for computer numerical less complex.
control (CNC) applications in small-scale industries,
educational institutions and among the hobbyists. There are 4. A development language which is open source, easy to
several commercial CNC machine manufacturers like M/s understand, requiring basic programming knowledge, thereby
Fanuc Ltd and M/s SINUMERIK which however meet this making it easily amendable for the user.
need, but are not affordable by the above-mentioned user 5. A much more economical way of using the hardware
community. The high cost of the machine can be associated to which is easily available in most countries.
the usage of custom designed embedded controllers and
machine components. In the past one decade, there have been a In today’s times, the above requirements can be well met
few kinds of literature concerning the implementation of low- by developing the CNC system using Python [7] and Arduino
cost CNC system. In [1] the authors use grbl (open-source G- electronics platform for signal generation.
code interpreter for Arduino) to reduce the cost and an open As suggested by the stack overflow survey [8], Python is
source computer-aided manufacturing (CAM) software which emerging as a widely used programming language for
is machine specific. In [2] a real-time operating system reduces beginners and it is developed under an open source initiative
the development period and the cost, and thereby greatly (OSI)-approved open source license. Python, a dynamic object-
decreasing the program complexity in the design. In [3] the oriented programming language can be used for developing
authors discuss about realizing STEP-NC controller using a many kinds of software. As it offers strong support for
low cost microcontroller to control a CNC machine with two integrating with other languages and tools, Python comes with
degrees of freedom. In [4] the authors discusses on reducing extensive standard libraries and can be learned in a very short
the cost by realizing the controller using Arduino based time. Hence choosing Python in order to develop the CNC
embedded system and an offline G-code parser to convert the system is well justified.
code into National Institute of Standards and Technology
(NIST-SAI) canonical code. The various stages of the system design are shown in Fig.
1. The complete paper is organized as follows: section II
There exists a few open source CNC software online [5][6], discusses proposed a methodology and elaborates the
but however, most of these are not easily customizable. The individual system components and its functionality. Section III
source code of this software is very challenging to understand discusses the results in each stage of the plotter. Then in
as they are mainly developed in Java or Visual Basic. The section IV, conclusion and future scope of the work has been
major disadvantage of the current existing open-source discussed.
software is their integration with hardware, which includes
824
data is stored in the array, it is sent to machine’s electronics coils. Full stepping scheme is used for plotting vertical and
system to drive the motors. The following encoding scheme horizontal lines whereas, for inclined lines or curved designs
shown in Table I is adopted to attribute this information along 1/8 micro-stepping scheme is used. Use of both the schemes
with the number of steps. Arduino can handle a maximum data together results in a significant decrease in the total plotting
size of 32-bits. i.e. 0 – 4294967295 integer values. time. Depending on the current rating of the stepper motors and
the maximum switching frequency of the PWM input signal,
TABLE I. ENCODING SCHEME
the MOSFET’S or BJT’s used in building the circuits have to
be chosen accordingly. Each stepper motor will be connected
Actual Data Encoded Data to two H-Bridge circuits i.e. one H-Bridge circuit per coil and
X axis: clockwise direction + step count 1******** is built using power MOSFET-55NF06. Fig. 3 shows the
X axis: anti-clockwise direction + step count 2********
hardware circuit for the motor control. The Z-axis servomotor
Y axis: clockwise direction + step count 3********
Y axis: anti-clockwise direction + step count 4********
is controlled directly from the Arduino using PWM.
Z axis: clockwise direction + step count 5********
Z axis: anti-clockwise direction + step count 6********
where *’s indicate the step count. e.g. 200000036 means X- axis should move 36 steps in the
negative direction.
D. Serial Communication
The data (step count) corresponding to the motion of
individual axis X, Y and Z is encoded and stored in an array.
PySerial library is utilized to establish the serial
communication. The time of execution of a drawing is greatly
dependent on the data transfer rate and also on the decoding
and encoding scheme complexity.
The clock frequency of a computer is around 2.2 to 3.6
GHz, whereas the Arduino UNO maximum clock frequency is
16 MHz. This variation in the clock frequencies can lead to
significant data loss or data misinterpretation thereby distorting
the workpiece. Therefore a proper synchronization needs to be
maintained in order to prevent any data loss. This can be
achieved by using a widely known technique called Fig. 3. Experimental electronic controller for the motors.
Handshaking protocol. By implementing this protocol the
entire unit will be functioning at a maximum clock frequency G. Mechanical system
of 16 MHz.
The three-axis CNC pen plotter draws the objects in the
E. Decoding Scheme: CAD file. The rotary motions of the motors have to be
converted to linear motion, which can be done in many ways.
Once the data is available in the serial register of Arduino it Ball screw mechanism and Rack and pinion mechanism are
reads in and compares the first digit to determine the encoding two methods among them. Rack and pinion mechanism, in
type and then executes the corresponding functionality. The which the table rails are glued with a belt drive as racks and the
next data will be available in Arduino serial register but will small plastic gears as pinions is built as shown in Fig. 4. The
not be read until the current function is executed completely. In pitch of the pinion is equal to the belt pitch. With this setup, an
order to establish a proper serial connection the designer must accuracy of 0.08mm is obtained.
make sure that the serial port parameters are set with the same
values in both the Python terminal and Arduino. These include
Port number, Baud rate, Data bits, Stop bits, Parity type and
Flow control.
F. Signal generation
The three stepper motors being used are having a resolution
of (1.8°) 200 steps per revolution. In order to reduce the cost of
the equipment and to keep it simple, rack and pinion
mechanism is used. Therefore the tool resolution is completely
dependent on the resolution of the stepper motors and pitch of
the gear. In order to increase the number of steps 1/8 micro-
stepping scheme is used. The cost of the equipment is reduced
by designing and building a micro stepping driver circuit based
on the rating of the motors. For this study, micro stepping
driver IC A3967 is used to generate the PWM signals and H- Fig. 4. Rack with belt arrangement.
Bridge circuit to switch the 5 V power supply to the motor
825
One servo motor and three stepper motors are being used to drawn by the pen plotter is shown in Fig. 10. The total time
provide the motion along the X, Y and Z-axes. The servo taken by the plotter to plot this CAD model specified as per
motor attached to a slider crank mechanism shown in Fig. 5 Fig. 7 is about 16.2 s by the proposed scheme. Consider
gives the motion along Z-axis which allows the pen to move another CAD model of alphabet “D” as input to the plotter as
upside down. Two stepper motors on the near end of Fig. 6 shown in Fig. 11. The output of point generator and the plotter
which are connected to rack and pinion give the motion along output are shown in Fig. 12 and Fig. 13 respectively. Here the
the Y-axis and one stepper motor with rack and pinion placed time taken by the plotter is about 69.4 s with the proposed
on the farther end gives the motion along X-axis. Here servo methodology. This is to demonstrate the smooth plotting of
motor is used along with slider crank mechanism to decrease curves.
the load on both X-axis and Y-axis.
A study has been made on the errors in plotting a line,
inclined line and a curve. The error in final plotting is due to
approximation of curves and nonlinearities present in the
mechanical equipment. But these errors are not the same in
every case. Table III represents the approximate errors in the
plotter for various plots.
Fig. 6. Proposed CNC pen plotter having two stepper motors for Y-axis
control, one stepper motor for X-axis control and a servomotor for Z-axis
control.
Fig. 7. CAD model of alphabet T fed as input to the plotter.
826
TABLE III. THEORETICAL VS EXPERIMENTAL ERROR FOR THE PLOTTER
Geometry Theoretical error Experimental error
1.Vertical line 0mm ±0.5mm
2.Horizontal line 0mm ±0.5mm
3.Inclined line ±0.04mm ±0.54mm
4.Every other Curve ±0.08mm ±0.84mm
IV. CONCLUSION
The indigenous CNC plotter can be interfaced with any
mechanical setup by varying the resolution parameter in the
Python code depending on the resolution available with the
hardware. The accuracy in printing obtained using the
Fig. 9. Output T from the coordinate point generator plotted in Python. proposed plotter is 0.8mm. This accuracy can be increased
further by installing a proper mechanical system. As this
system is completely coded in Python, it is very easy to
understand the working of a machine and amend it for personal
use. The whole CNC system can be used as a learning tool for
university students which can be of a help in understanding the
automation involved in manufacturing. This system doesn’t
have any G-code parser. Hence, the understanding of CAD
methods in CAM is easy. The system is made using open
source hardware and software, thus making it available at low
Fig. 10. The output drawn by the pen plotter. cost, which can improve the profits of small scale industries.
This system can be directly implemented on Raspberry pi,
Beagle bone or other high-end embedded platforms. Thereby
completely eliminating the Arduino Board and PC from system
design and making it highly portable. This can significantly
reduce the system cost with a slight increase in setup
complexity.
REFERENCES
[1] S. Pandian and S. R. Pandian, "A low-cost build your-own three axis
CNC mill prototype", International Journal of Mechanical Engineering
Fig. 11. CAD model of alphabet D fed as input to the plotter. and Robotics, ISSN: 2321-5747 vol. 2, no. 1, 2014.
[2] Tao Wang, Qingjian Liu and Liwen Wang, "An RTOS-based embedded
CNC system," 2010 International Conference on Computer,
Mechatronics, Control and Electronic Engineering, pp. 33-36,
Changchun, 2010.
[3] F. Calabrese and G. Celentano, "Design and realization of a STEP-NC
compliant CNC embedded controller," IEEE Conference on Emerging
Technologies and Factory Automation, pp. 1010-1017, Patras, 2007.
[4] A. Khanna, A. Kumar, A. Bhatnagar, R. Tyagi and S. Srivastava, "Low-
cost production CNC system," 7th International Conference on
Intelligent Systems and Control (ISCO), 2013, Coimbatore, Tamil Nadu,
India, pp. 523-5282013.
[5] Free Mechanical Engineering CAD/CAM Software, availabe at
www.freebyte.com/, (accessed April 2016).
[6] Open source Arduino CNC controller softwares, available at
Fig. 12. Output coordinate points generated in Python for D. https://sourceforge.net, (accessed April 2016).
[7] Michael Dawson, Python Programming for the Absolute Beginner,
Course Technology, a part of Cengage Learning, 3rd edition, 2010.
[8] Stack overflow Developer Survey,
www.stackoverflow.com/research/developer-survey-2015, (accessed
April 2016).
[9] dxfgrabber-documentation and installation guide, available at
https://media.readthedocs.org/pdf/dxfgrabber/latest/dxfgrabber.pdf,
(accessed April 2016).
[10] DXFfiles-https://en.wikipedia.org/wiki/AutoCAD_DXF, (accessed
April 2016)
Fig. 13. The output drawn by the plotter.
827