Professional Documents
Culture Documents
New Final Project Report of CNC Plotter
New Final Project Report of CNC Plotter
By:
AATISH KUMAR SINGH. L 433EE15001
AKSHAY KUMAR. R 433EE15007
ARCHANA. N 433EE15009
CHANDAN. B 433EE15012
RAKSHITH GOWDA. CK 433EE15045
ROOPESH. NP 433EE15048
P.V.P POLYTECHNIC
(Recognized by AICTE New Delhi, AIDED and Affilliated by G.O.K)
1
“PORTABLE TWO AXIS CNC PRINTER”
CERTIFICATE
This is to certify that this project entitled “PORTABLE TWO AXIS CNC PRINTER”
which is being submitted by ROOPESH.NP Reg no 433EE15048 a student of P.V.P
Polytechnic in partial fulfillment for the award of Diploma VI semester, ELECTRICAL &
ELECTRONICS ENGG During the year 2017-18 is record of students own work carried out
under my/our guidance. It is certified that all corection/suggestion indicate for internal
assessment have been incorporate in the report and one copy of it being deposited to the
polytechnic library.
The project report has been approved as it satisfies the academic requirements in respect
of project work prescribe for the said Diploma.
It is further understood that this certificate the undersigned do not endorse or approve any
statements made, opimion expressed or conclusion draw there in but approve the project only for
the purpose for which it is submitted.
Examiner’s signature
1.
2.
Dept. of E&EE
2
“PORTABLE TWO AXIS CNC PRINTER”
ACKNOWLEDGEMENT
With deep sense of gratitude and regards, we thank our honorable principal
Sri.G.P.MANJUNATH for taking extensive care while implementing our project.
Project Team
3
“PORTABLE TWO AXIS CNC PRINTER”
CANDIDATE’S DECLARATION
Date:
Place:
Signature of candidate
4
“PORTABLE TWO AXIS CNC PRINTER”
Table of Contents
Page. No
Chapter 1
ABSTRACT
INTRODUCTION
Problem statement
Objective of project
Existing system
Justification of the Project
Scope of the Project
Specification of the report
Features of the Project
Organisation of report
Chapter 2
Purposed System
Block diagram
Components
Working
Chapter 3
Fundamentals of Robotic System
DC Stepper motor
DC Servo motor
5
“PORTABLE TWO AXIS CNC PRINTER”
Chapter 4
Hardware Module
Arduino Uno board
Stepper motor
Stepper motor
H-Bridge
Motor drive shield L293D
Chapter 5
Software module
Arduino IDE
Inkscape
G-CTRL
Chapter 6
Methodology of Robotic System
Algorithm
Test Plan
Test Result
Chapter 7
Conclusion
References
Appendix
6
“PORTABLE TWO AXIS CNC PRINTER”
CHAPTER 1
ABSTRACT
The invention of the XY-plotters is to recording or plotting 2dimensonal data on a
rectangular co-ordinated system. This study emphasizes the Fabrication of a XY-plotter by using
mechanisms from scanner and Microcontroller system (Arduino) to control the moment of XY-
axis .modeling and analysis on XY-plotter is carried out through the computer link with the
Arduino software.it is executed through the algorithms and g code and java programming.
Keywords: plotters, Arduino, g-code.
INTRODUCTION
In the present study, the XY plotter is designed to recording and plotting 2 dimensional
data on a rectangular coordinate system. The material selection of the mechanism was made
considering the cost and wide range of application such as servo motor. Servo motor can be
differentiated through the cost, peak torque capability, speed range to compromise the standard
and application of the system. Discuss the dynamic of a dual drive servo mechanism and
develops a n XY gantry model consisting of a 2 motors for y control with another motor sliding
the gantry in x direction. The design uses 2 parallel rails for y motion with a bar spanning across
the rails which holds the end effectors of the system.in the other hand, the accuracy of plotting is
the issue e to be concerned on the fabrication of XY plotter. Few papers have been devoted to
plotters in the term of their adjustment methods on the accuracy and moment of plotter. The XY
plotter system is a more simplified system comparing to the CNC system since CNC system is
running on 3 axis direction and the programming is more complicated never the less, the coding
for the CNC system which is the g code.
7
“PORTABLE TWO AXIS CNC PRINTER”
PROBLEM STATEMENT
Problem chosen is to implementation of “PORTABLE TWO AXIS CNC PRINTER
“using microcontrollers, STEPPER MOTOR and SERVO MOTOR with MOTOR DRIVER
SHIELD.
OBJECTIVE OF PROJECT
The main objective of our project is to secured portable two axis cnc printer.as we see
nowadays cnc machines maintance is the major issue in the country.
The number of modern machines is increasing day by day. And machines produced are required
experienced worker. Or if we leave unexpernced person there won’t be having proper safety, and
also the machine owned by the owners are facing many problem, day by day. By observing all
this improper maintance and inexperienced person working with machines, our aim is to provide
proper safety and maintance free machine for the future we can achieve greater development in
the industry of CNC machines. By this implementation in industry can be relaxed by this
“PORTABLE TWO AXIS CNC PRINTER” her we provide the specific format of image (JPG),
contexts and software to be used by the person using and reduce maintance.
8
“PORTABLE TWO AXIS CNC PRINTER”
EXISTING SYSTEM
Cnc machines are very much essential in our day to day life in the production of the
industry. This is basic need for leading the nation to achieve the goals. The existing system of
cnc machines are:
9
“PORTABLE TWO AXIS CNC PRINTER”
ORGANIZATION OF REPORT
10
“PORTABLE TWO AXIS CNC PRINTER”
CHAPTER 2
METHODOLOGY OF A PROJECT CARRIED OUT ROUND PLATFORM
A portable two axis cnc printer is a mechanical and electronic device that multiplies cnc
operated safe machines in the industry. Cnc machines are powered by Electric motor that moves
the cartridge to the required position.
BLOCK DIAGRAM
For a CNC plotting machine to operate, 3 axes are required (x-axis, y-axis and z-axis.
The x-axis and y-axis work in unison to create a 2D image on a plain paper. These x and y axis
are placed 90 degrees to each other such that any point on the plain surface is defined by a
given value of x and y. The z-axis is used lift and lowers the pen onto the plain paper.
Depending on the image to be drawn, the computer will generate the appropriate coordinates
and send them to the microcontroller through the USB port. The microcontroller interprets
these coordinates and then controls the positions of the motors to create the image. Here we
have used Arduino as the Microcontroller to build this CNC Machine.
11
“PORTABLE TWO AXIS CNC PRINTER”
COMPONENTS REQUIRED:
12
“PORTABLE TWO AXIS CNC PRINTER”
CHAPTER 3
FUNDAMENTALS OF CNC PRINTER SYSTEM
STEPPER MOTOR
A. Efficiency:
Cnc printer machine provides maximum space for the motor to run freely.
B. cost efficiency:
This project system improves the viability of commercial and residual development of the
industry.
13
“PORTABLE TWO AXIS CNC PRINTER”
SERVO MOTOR
14
“PORTABLE TWO AXIS CNC PRINTER”
CHAPTER 4
HARDWARE MODULE
ARDUINO BOARD
The Arduino board controller was advanced, viable, quick and better accomplishment
of force framework control and administration utilizing installed segments. It containing the
oscillatory circuit, reset, equipment segments and so on. The MCU is essential thought of the
PWM for controlling DC Motor.
The output devices are used a LCD display which is connected on digital output of board.
This LCD screen is used to display real time value of PWM and information for individual in-
wheel DC Motors or otherwise voltage across each motor terminal.
A serial data communication method is used while the data transfer has intense to
passing MCU to external devices such as L293D DC Motor driver, LCD output device. In
Arduino controller board, the digital outputs provided through the pin no’s are (5), (6), (10) and
(11) are selected to transmit the PWM signal to DC Motor driver device
15
“PORTABLE TWO AXIS CNC PRINTER”
circuitry built various board called Arduino shield. This Arduino board is having preloaded
software called boot loader program does allow us to make simpler programming language and
store programs in a chip. In this board it also supports USB access a smaller microcontroller
ATMEL16U2 so we don’t need a separate circuit provide for USB support.
It also has something called ICSE (in circuit serial programmer) for an external piece of
hardware that used to programme a microcontroller to download software which actually in an
assembly language.
16
“PORTABLE TWO AXIS CNC PRINTER”
(vii) Peripherals: - The Arduino Uno external connections are used in this project as follows,
they are
It has 32 working registers, 20 general purpose I/O lines, 3 timer/counters work with
compare modes, both external and internal interrupts, serial programmable USART, a byte-
oriented 2-wire serial interface, SPI serial port, 6-channel 10-bit ADC, programmable watchdog
timer along with internal oscillator, and five power saving modes. The device can operate as low
as 1.8-5.5 volts.
17
“PORTABLE TWO AXIS CNC PRINTER”
The USART module is introduced for serial method of communication between master
control unit and Computer. It is response is always through I/O Port D. This module can be used
with the built-in serial monitor to communicate with an Arduino board to display the digital
output. This unit is designed to send and receive the signal to/from correspond component. Since
the parallel data communication has more speed than serial but it required multipin.
This is a highly flexible communication device, it can also be used in Master SPI mode.
The Power Reduction USART bit, PRUSART0, must be disabled by making register location in
to logical zero. A diagram of the USART is shown in Figure 5.4. I/O Registers and I/O pins
accessible by CPU are shown. Three main parts of the USART are a) Clock Generator, b)
Transmitter and c) Receiver. Control Registers are shared with all units. Synchronization logic
for external clock input is used by the baud rate generator, and synchronous slave operation for
Clock Generation.
18
“PORTABLE TWO AXIS CNC PRINTER”
STEPPER MOTOR:
19
“PORTABLE TWO AXIS CNC PRINTER”
SERVO MOTOR
We are using a 12v DC geared motor in order to provide the robot movement and for the
rotation of cartridge (pen). A geared DC motor has a gear assembly to the motor in order to
control its speed & it is counted.
A servo motor is an electrical device which can push or rotate an object with great
precision. If you want to rotate and object at some specific angles or distance, then you use servo
motor. It is just made up of simple motor which run through servo mechanism. If motor is used is
DC powered then it is called DC servo motor, and if it is AC powered motor then it is called AC
servo motor.
Servo motor works on PWM (Pulse width modulation) principle means its angle of
rotation is controlled by the duration of applied pulse to its Control PIN. Basically servo motor is
made up of DC motor which is controlled by a variable resistor (potentiometer) and some gears.
High speed force of DC motor is converted into torque by Gears.
Servo motors are available at different shapes and sizes. A servo motor will have mainly
there wires, one is for positive voltage another is for ground and last one is for position setting.
The RED wire is connected to power, Black wire is connected to ground and YELLOW wire is
connected to signal.
20
“PORTABLE TWO AXIS CNC PRINTER”
H-Bridge
How do we make a motor turn?
You take a battery; hook the positive side to one side of your DC motor. Then you connect the
negative side of the battery to the other motor lead. The motor spins forward. If you swap the
battery leads the motor spins in reverse.
Ok, that's basic. Now let’s say you want a Micro Controller Unit (MCU) to control the motor,
how would you do it?
If you connect this circuit to a small hobby motor you can control the motor with a
processor (MCU, etc.) Applying a logical one, (+12 Volts in our example) to point A causes the
motor to turn forward. Applying a logical zero, (ground) causes the motor to stop turning (to
coast and stop).
21
“PORTABLE TWO AXIS CNC PRINTER”
motors to run forwards and backwards. H-bridges are available as integrated circuits or can be
built from discrete components.
The key fact to note is that there are, in theory, four switching elements within the bridge.
These four elements are often called, high side left, high side right, low side right, and low side
left (when traversing in clockwise order).
The "high side drivers" are the relays that control the positive voltage to the motor. This
is called sourcing current. He "low side drivers" are the relays that control the negative voltage to
sink current to the motor. "Sinking current" is the term for connecting the circuit to the negative
side of the power supply, which is usually ground.
The switches are turned on in pairs, either high left and lower right, or lower left and high right,
but never both switches on the same "side" of the bridge. If both switches on one side of a bridge
are turned on it creates a short circuit between the battery plus and battery minus terminals. This
phenomenon is called shoot through in the Switch-Mode Power Supply (SMPS) literature. If the
bridge is sufficiently powerful it will absorb that load and your batteries will simply drain
quickly. Usually however the switches in question melt.
To power the motor, you turn on two switches that are diagonally opposed. In the picture
to the right, imagine that the high side left and low side right switches are turned on.
22
“PORTABLE TWO AXIS CNC PRINTER”
23
“PORTABLE TWO AXIS CNC PRINTER”
24
“PORTABLE TWO AXIS CNC PRINTER”
PIN FUNCTION
FEATURES
25
“PORTABLE TWO AXIS CNC PRINTER”
74HC595
The 74HC595 consists of an 8−bit shift register and a storage register with three−state
parallel outputs. It converts serial input into parallel output so that you can save IO ports of an
MCU. The 74HC595 is widely used to indicate multipath LEDs and drive multi-bit segment
displays. "Three-state" refers to the fact that you can set the output pins as either high, low or
"high impedance." With data latching, the instant output will not be affected during the shifting;
with data output, you can cascade 74HC595s more easily.
PIN FUNCTION
26
“PORTABLE TWO AXIS CNC PRINTER”
No Name Function
8-bit parallel data output pins, able to control 8 LEDs or 8 pins
1 Q0-Q7
of 7-segment display directly.
4 SHcp
i.e. data in Q1 moves to Q2, and so forth. While
on the falling edge, the data in shift register
remain unchanged.
FEATURES
8-Bit Serial-In, Parallel-Out Shift
Wide Operating Voltage Range of 2 V to 6 V
High-Current 3-State Outputs Can Drive Up To 15 LSTTL Loads
Low Power Consumption, 80-µA Max ICC
Typical tpd = 13 ns
Low Input Current of 1
Shift Register Has Direct Clear
27
“PORTABLE TWO AXIS CNC PRINTER”
PERSONAL COMPUTER
Personnel computers are very important for programming the Arduino board through
serial communication. Boot loader with Arduino controller will simplify the uploading process
of sketches to the flash memory. If we see that any other microcontrollers need an external
programmer. But here in this case on chip flash memory and boot loader of Arduino board
straight forward make use of a PC as a programmer. Presently Arduino boards are
communicating with computers or programmed via USB with the help of adapter chips. When
used with traditional microcontroller tools instead of the Arduino IDE, standard AVR in-system
programming (ISP) programming is used.
28
“PORTABLE TWO AXIS CNC PRINTER”
CHAPTER 5
SOFTWARE MODULE
INTRODUCTION
A programming dialect is used to pass on the rules to CPU or microcontroller and obliges
CPU to perform a specific work. To create a framework for an undertaking, the basic thing is to
pick a programming expression. In this endeavor, to make an undertaking which executed by
CPU through programming area. By then, the venture heading of each bit of the structure is
finished by application. The programming lingo can be segregated into two novel levels which is
the low level and high state programming expression.
The machine correspondence and low-level processing develop are under the
characterizations of low level programming expression. The machine tongue is the primary
programming expression that can be fathomed by microcontroller it contains numbers (0's and
1's) for form or read the framework rule. Fortunately, there is a compiler that can be used to
make an elucidation of others programming correspondence into machine level. The charge of
low level processing build is particularly fundamental accordingly programming design needs to
use extra time and put more effort in completing a befuddled task. Consequently, both of these
correspondences are not reasonable for this endeavour even the low-level figuring build may
give a short program execution time yet the time customer is not a fundamental issue for this
endeavour. Besides, ATMEGA328P has an adequately unfathomable memory space to store the
framework.
High state writing computer programs is more straightforward to grasp by programming
engineer differentiated and low-level programming correspondence as it is more sorted out,
utilizations from the gear. Other than that, the irregular state programming composing involves
variables, shows, calculating or Boolean expression, limits and others while the low-level
programming composing just oversees register and memory address. Along these lines, the
programming expression that starts from high state programming expression is the primary
choice for some product engineer as the microcontroller ending up being all the more
confounding, code progression using gathering gets the chance to be great and requires a
considerable measure of data. Then again, there is a limitation for high state programming
correspondence where it requires an all the more competent compiler to make an understanding
of the framework into machine correspondence.
29
“PORTABLE TWO AXIS CNC PRINTER”
SOFTWARE COMPONENTS
C and C++ languages using special rules to organize code supports by the Arduino IDE.
Arduino integrated development environment (IDE) is an application written in the programming
language Java.
ARDUINO IDE
Arduino programs can be written in any language with a compiler that produces machine
code. Atmel provides an integrated development environment for microcontrollers, i.e. AVR
Studio and the newer Atmel Studio.
SOFTWARE PROGRAMMING
The Arduino board can be programmed with the Arduino integrated development
environment (IDE) by Selecting the "Arduino/Genuine Uno" from the Tools. The ATmega328p
on the Uno built with a boot loader that allows you to upload new code to it therefore it doesn't
require external hardware programmer. It communicates using the original STK500 protocol. It
also has something called ICSP (in circuit serial programmer) for an external piece of hardware
that used to program a microcontroller to download software which actually in an assembly
language by selecting Arduino ISP or similar.
30
“PORTABLE TWO AXIS CNC PRINTER”
In this board it also supports USB programmer to access a smaller microcontroller The
ATmega16U2 firmware so we don't need a separate circuit provide for USB Support. After
compiling and linking with the GNU tool chain, also included
With the IDE distribution, an IDE employs the program argued is used to convert the
executable code into a text file. It’s in hexadecimal code that is loaded into the Arduino board by
a loader in the board's firmware.
31
“PORTABLE TWO AXIS CNC PRINTER”
INKSCAPE
Inkscape is a free and open-source vector graphics editor; it can be used to create or edit
vector graphics such as illustrations, diagrams, line arts, charts, logos and complex paintings.
Inkscape's primary vector graphics format is Scalable Vector Graphics (SVG), however many
other formats can be imported and exported
One of the main priorities of the Inkscape project is interface consistency and usability.
This includes efforts to follow the human interface guidelines, universal keyboard accessibility,
and convenient on-canvas editing. Inkscape has achieved significant progress in usability since
the project started.
The number of floating dialog boxes has been reduced, with their functions available using
keyboard shortcuts or in the docked toolbars in the editing window. The tool bar controls at the
top of the window always display the controls relevant to the current tool.
Inkscape provides mouse over tooltips and status bar hints for all buttons, controls, commands,
keys, and on-canvas handles. The status bar hint messages are dynamic: A given object can
display up to four hints while editing it with just one tool.
PLATFORM SUPPORT
The latest version of Inkscape is available for Ubuntu, Open SUSE, Microsoft
Windows and macOS platforms. Both 32-bit and 64-bit versions are available for Windows PCs.
Inkscape is packaged for all major Linux distributions (including Debian, Ubuntu,
Fedora, Open SUSE
32
“PORTABLE TWO AXIS CNC PRINTER”
GCTRL
Gctrl is a GUI (Graphical User Interface) program for use with GRBL. Gctrl is code that
is meant to run on the software called "Processing". Gctrl provides control options for jogging
and sending gcode.
G-code which has many variants is the common name for the most widely
used numerical control (NC) programming language. It is used mainly in computer-aided
manufacturing to control automated machine tools.
G-code is a language in which people tell computerized machine tools how to make
something. The "how" is defined by g-code instructions provided to a machine controller
(industrial computer) that tells the motors where to move, how fast to move, and what path to
follow. The most common situation is that, within a machine tool, a cutting tool is moved
according to these instructions through a tool path and cuts away material to leave only the
finished work piece. The same concept also extends to noncutting tools such as forming or
burnishing tools, photo plotting, additive methods such as 3D printing, and measuring
instruments.
Specific codes
G-codes, also called preparatory codes, are any word in a CNC program that begins with
the letter G. Generally it is a code telling the machine tool what type of action to perform, such
as:
33
“PORTABLE TWO AXIS CNC PRINTER”
34
“PORTABLE TWO AXIS CNC PRINTER”
CHAPTER 6
METHODLOGY OF THE PROJECT
ALGORITHM FOR WIFI CONTROLLED MILITARY ROBOT
Step 1 : we dump the code to microcontroller.
Step 2 : DC Stepper & servo Motor turns on and start running.
Step 3 : we process the image and convert it into g-code form.
Step 4 : we open Gctrl processor and select the port and the image to process.
Step 5 : stepper and servo motor starts running in both X&Y axis.
Step6 : stepper motor and servo motor turns off.
TEST PLAN
command should be initialized
The image should be converted into G-code form.
In gctrl the port selection and G-code produced by the inkscape should be given to
controller.
The 12v, 1A DC supply should be given to the driver supply.
The DC stepper motor ran smoothly in both XY-axis of the limited shaft.
The cartridge (pen) which is inserted to the holder must run up and down freely.
The commanded Gcode image must be drawn on the board suspended on the Y-Axis of
the motor board.
TEST RESULTS
Command successfully got initialized.
The image in inkscape got converted to g-code easily.
The gctrl code and port selection of the Arduino got selected initially.
The G converted code was send to the MCU initially.
Motor successfully turn ON as soon as process begins.
The cartridge (pen) ran smoothly on the suspended paper.
The image which was given has been drawn as per the given command.
35
“PORTABLE TWO AXIS CNC PRINTER”
CHAPTER 7
CONCLUSION
In this study, it was attempted to develop XY plotter that accurately synchronize with the
Arduino software system for better response for the moment of XY axis. Difference IDE and
different languages have been tried and used to complete this project to meet the objectives. With
a lot of new technologies been developing now days, this project serve to provide a good
platform for future development for XY plotter system and even other system. This capstone
project is the perfect way to demonstrate our understanding and the application of mechanical
electrical egg knowledge in to solving every day’s problem for the benefit for mankind.
36
“PORTABLE TWO AXIS CNC PRINTER”
REFERENCES
https://www.youtube.com/watch?v=opZ9RgmOIpc
https://github.com/martymcguire/inksc...
https://playground.arduino.cc/Main/AdafruitMotorShield
37
“PORTABLE TWO AXIS CNC PRINTER”
ARDUINO
APPENDIX
CODE:
#include <Servo.h>
#include <AFMotor.h>
// Should be right for DVD steppers, but is not too important here
const int stepsPerRevolution = 48;
// Initialize steppers for X- and Y-axis using this Arduino pins for the L293D H-bridge
AF_Stepper myStepperY(stepsPerRevolution,1);
AF_Stepper myStepperX(stepsPerRevolution,2);
38
“PORTABLE TWO AXIS CNC PRINTER”
// Needs to interpret
// G1 for moving
// G4 P300 (wait 150ms)
// M300 S30 (pen down)
// M300 S50 (pen up)
// Discard anything with a (
// Discard any other command!
/**********************
* void setup() - Initialisations
***********************/
void setup() {
// Setup
Serial.begin( 9600 );
penServo.attach(penServoPin);
penServo.write(penZUp);
39
“PORTABLE TWO AXIS CNC PRINTER”
delay(100);
// Decrease if necessary
myStepperX.setSpeed(600);
myStepperY.setSpeed(600);
// Notifications!!!
Serial.println("Mini CNC Plotter alive and kicking!");
Serial.print("X range is from ");
Serial.print(Xmin);
Serial.print(" to ");
Serial.print(Xmax);
Serial.println(" mm.");
Serial.print("Y range is from ");
Serial.print(Ymin);
Serial.print(" to ");
Serial.print(Ymax);
Serial.println(" mm.");
}
/**********************
* void loop() - Main loop
***********************/
void loop()
{
delay(100);
char line[ LINE_BUFFER_LENGTH ];
char c;
int lineIndex;
bool lineIsComment, lineSemiColon;
lineIndex = 0;
lineSemiColon = false;
lineIsComment = false;
while (1) {
40
“PORTABLE TWO AXIS CNC PRINTER”
41
“PORTABLE TWO AXIS CNC PRINTER”
}
else {
line[ lineIndex++ ] = c;
}
}
}
}
}
}
newPos.x = 0.0;
newPos.y = 0.0;
// Needs to interpret
// G1 for moving
// G4 P300 (wait 150ms)
// G1 X60 Y30
// G1 X30 Y50
// M300 S30 (pen down)
// M300 S50 (pen up)
// Discard anything with a (
// Discard any other command!
42
“PORTABLE TWO AXIS CNC PRINTER”
43
“PORTABLE TWO AXIS CNC PRINTER”
break;
}
case 114: // M114 - Repport position
Serial.print( "Absolute position : X = " );
Serial.print( actuatorPos.x );
Serial.print( " - Y = " );
Serial.println( actuatorPos.y );
break;
default:
Serial.print( "Command not recognized : M");
Serial.println( buffer );
}
}
}
/*********************************
* Draw a line from (x0;y0) to (x1;y1).
* int (x1;y1) : Starting coordinates
* int (x2;y2) : Ending coordinates
**********************************/
void drawLine(float x1, float y1) {
if (verbose)
{
Serial.print("fx1, fy1: ");
Serial.print(x1);
Serial.print(",");
Serial.print(y1);
Serial.println("");
}
44
“PORTABLE TWO AXIS CNC PRINTER”
if (verbose)
{
Serial.print("Xpos, Ypos: ");
Serial.print(Xpos);
Serial.print(",");
Serial.print(Ypos);
Serial.println("");
}
if (verbose)
{
Serial.print("x1, y1: ");
Serial.print(x1);
Serial.print(",");
Serial.print(y1);
Serial.println("");
}
long i;
long over = 0;
45
“PORTABLE TWO AXIS CNC PRINTER”
over+=dy;
if (over>=dx) {
over-=dx;
myStepperY.onestep(sy,STEP);
}
delay(StepDelay);
}
}
else {
for (i=0; i<dy; ++i) {
myStepperY.onestep(sy,STEP);
over+=dx;
if (over>=dy) {
over-=dy;
myStepperX.onestep(sx,STEP);
}
delay(StepDelay);
}
}
if (verbose)
{
Serial.print("dx, dy:");
Serial.print(dx);
Serial.print(",");
Serial.print(dy);
Serial.println("");
}
if (verbose)
{
Serial.print("Going to (");
Serial.print(x0);
Serial.print(",");
Serial.print(y0);
Serial.println(")");
}
46
“PORTABLE TWO AXIS CNC PRINTER”
// Raises pen
void penUp() {
penServo.write(penZUp);
delay(penDelay);
Zpos=Zmax;
digitalWrite(15, LOW);
digitalWrite(16, HIGH);
if (verbose) {
Serial.println("Pen up!");
}
}
// Lowers pen
void penDown() {
penServo.write(penZDown);
delay(penDelay);
Zpos=Zmin;
digitalWrite(15, HIGH);
digitalWrite(16, LOW);
if (verbose) {
Serial.println("Pen down.");
}
}
47
“PORTABLE TWO AXIS CNC PRINTER”
G-CODE
APENDEX
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;
import processing.serial.*;
// select and modify the appropriate line for your operating system
// leave as null to use interactive port (press 'p' in the program)
String portname = null;
//String portname = Serial.list()[0]; // Mac OS X
//String portname = "/dev/ttyUSB0"; // Linux
//String portname = "COM6"; // Windows
void openSerialPort()
{
if (portname == null) return;
if (port != null) port.stop();
port.bufferUntil('\n');
}
void selectSerialPort()
{
String result = (String) JOptionPane.showInputDialog(frame,
"Select the serial port that corresponds to your Arduino board.",
"Select serial port",
JOptionPane.QUESTION_MESSAGE,
null,
Serial.list(),
0);
if (result != null) {
48
“PORTABLE TWO AXIS CNC PRINTER”
portname = result;
openSerialPort();
}
}
void setup()
{
size(600, 400);
openSerialPort();
}
void draw()
{
background(155);
fill(0);
int y = 24, dy = 12;
text("INSTRUCTIONS", 12, y); y += dy;
text("p: select serial port", 12, y); y += dy;
text("1: set speed to 0.001 inches (1 mil) per jog", 12, y); y += dy;
text("2: set speed to 0.010 inches (10 mil) per jog", 12, y); y += dy;
text("3: set speed to 0.100 inches (100 mil) per jog", 12, y); y += dy;
text("arrow keys: jog in x-y plane", 12, y); y += dy;
text("page up & page down: jog in z axis", 12, y); y += dy;
text("$: display grbl settings", 12, y); y+= dy;
text("h: go home", 12, y); y += dy;
text("0: zero machine (set home to the current location)", 12, y); y += dy;
text("g: stream a g-code file", 12, y); y += dy;
text("x: stop streaming g-code (this is NOT immediate)", 12, y); y += dy;
y = height - dy;
text("current jog speed: " + speed + " inches per step", 12, y); y -= dy;
text("current serial port: " + portname, 12, y); y -= dy;
}
void keyPressed()
{
if (key == '1') speed = 0.001;
if (key == '2') speed = 0.01;
if (key == '3') speed = 0.1;
if (!streaming) {
if (keyCode == LEFT) port.write("G91\nG20\nG00 X-" + speed + " Y0.000 Z0.000\n");
if (keyCode == RIGHT) port.write("G91\nG20\nG00 X" + speed + " Y0.000 Z0.000\n");
if (keyCode == UP) port.write("G91\nG20\nG00 X0.000 Y" + speed + " Z0.000\n");
49
“PORTABLE TWO AXIS CNC PRINTER”
void stream()
{
if (!streaming) return;
while (true) {
50
“PORTABLE TWO AXIS CNC PRINTER”
if (i == gcode.length) {
streaming = false;
return;
}
if (gcode[i].trim().length() == 0) i++;
else break;
}
println(gcode[i]);
port.write(gcode[i] + '\n');
i++;
}
void serialEvent(Serial p)
{
String s = p.readStringUntil('\n');
println(s.trim());
if (s.trim().startsWith("ok")) stream();
if (s.trim().startsWith("error")) stream(); // XXX: really?
}
51
“PORTABLE TWO AXIS CNC PRINTER”
52