I have removed all things I could find related to pin 19, as well as most of the temperature control and direction control, so now the only thing that has anything to do with Pin 19 is the extruder speed… I have also made it do a digitalWrite(EXTRUDER_MOTOR_SPEED_PIN,HIGH); instead of using "M108 S255" or something similar to change the PWM, because it does not turn on after the extruder_speed has been changed, which is strange…
When I "speak" to the unit through the Arduino Serial monitor (or any Terminal) i can turn the laser on and off, and also when I run "simple programs" it seems to work such as making a series of lines, (for some reason, it skips the last line ?)
But as soon as I send it some more "complicated Code" it does not turn the laser off any more, or does so at odd places..
Can the program sending G-code to the rig be at fault?, Its a very basic processing app that's being held together by willpower… (is there any way I can attach code as an object instead of pasting it, Otherwise the posts get very long… or in a zip file ? )
Also, some images.:)
The Rig :

The first (and smallest thing we made)

test patterns, Blue = Laser Off, red = Laser On


import processing.serial.*;
Serial myPort;
String serialLine = "";
String c = "";
boolean started = false;
boolean finished = false;
boolean commandComplete = true;
int commandCount = 0;
int ypos = 20;
String temperature = "?";
String gcode[] = {
};
int gcodeIndex = 0;
void setup()
{
size(500, 600);
println(Serial.list());
myPort = new Serial(this, Serial.list()[1], 38400);
gcode = loadStrings("test.gcode");
background(20, 20, 20);
}
void draw()
{
PFont font;
font = loadFont("ArialMT-48.vlw");
textFont(font, 16);
ypos =20 + gcodeIndex*20;
if(ypos>500)
{
background(20, 20, 20);
ypos = 20;
}
fill(250, 250, 250);
String code = "[" +gcodeIndex +"] : "+ c;
text(code,10,ypos);
while (myPort.available() > 0)
{
int inByte = myPort.read();
if (inByte == '\n')
{
println("Got: " + serialLine);
if (match(serialLine, "^start") != null)
started = true;
if (match(serialLine, "^ok") != null)
{
commandComplete = true;
fill(0, 240, 10);
text("ok",400,ypos);
if (gcodeIndex == gcode.length)
println("Job's done!");
}
serialLine = "";
}
else if (inByte > 0)
{
serialLine += (char)inByte;
}
}
if (started)
{
if (commandComplete)
{
String cmd = getNextCommand();
commandComplete = false;
if (gcodeIndex == gcode.length)
{
finished = true;
fill(0, 240, 10);
ypos+=50;
text("DONE",10,ypos);
}
if (cmd != null)
{
println("Sent: " +cmd);
myPort.write(cmd);
}
}
}
if (started && finished)
{
println("Job's done!");
started = false;
finished = false;
}
}
String getNextCommand()
{
if (gcodeIndex < gcode.length)
{
c = gcode[gcodeIndex];
gcodeIndex++;
if (match(c, "^[A-Z]{1}") == null)
c = getNextCommand();
return c;
}
else
return null;
}