Processing Code CNC For Arduino Meg2560 or UnoR3
Processing Code CNC For Arduino Meg2560 or UnoR3
KeyEvent;
import javax.swing.JOptionPane;
import processing.serial.*;
// select and modify the appropriate line for your operating system
String[] gcode;
int i = 0;
void openSerialPort()
port.bufferUntil('\n');
}
void selectSerialPort()
JOptionPane.QUESTION_MESSAGE,
null,
Serial.list(),
0);
if (result != null) {
portname = result;
openSerialPort();
void setup()
size(500, 250);
openSerialPort();
void draw()
{
background(0);
fill(255);
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("0: zero machine (set home to the current location)", 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;
void keyPressed()
gcode = null; i = 0;
println("Loading file...");
if (selection == null) {
} else {
gcode = loadStrings(selection.getAbsolutePath());
streaming = true;
stream();
void stream()
if (!streaming) return;
while (true) {
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();