Interface reprap firmw with adafruit stepper libr

I’m trying to build something similar to a laser cutter, which needs only 2 axis to move, X and Y.
I’ve been manually driving those axis with an Arduino 2009 using the adafruit motor shield which allows me to handle up to 2 stepper motors.
Now i wanted to transmit information about those motors positioning using g-code so i picked up RepRap software package code (a modified version of it) and removed all the useless stuff (like sensors and the use of Z axis). I’m not yet sure IF it works tho as i didn’t find any program working with serial / usb (only found mach3 which wants an LPT port :S ).

Anyway here’s the code…so if anyone could try it out will be apreciated!

Also if you can suggest me anyother way to CNC with arduino in a different way it would be appreciated:) Or even tips or whatever u’d like to share:)

Here’s the link to my code as it’s too big to fit in this post (9500 char limit). → http://syselkitna.no-ip.org/GCode_Interpreter2.rar

Hi - I've also adapted the RepRap code for an X/Y plotter type machine. I wrote the client app in Processing - it's pretty easy. There are various RepRap clients out there (Replicator, etc.) but I couldn't get them to work and my project needs a customizable client anyway.

If you just want to test your firmware, you can use the serial monitor (or any terminal app) to send single lines of gcode.

Hi Roy, i tried that but unfortunately it didn't work:( Can you share your work? I'm very interested:)

Which part didn't work - using serial monitor to send commands? It should work fine. I forget what the RepRap firmware uses to indicate the end of a cmd. I am using '' - so in sending the gcode below (describes a circle within a square) I would send G01X399.266Y399.273

If you put some print statements in the Arduino code you can see what is getting received and the state of things.

G00      Z0
G00      X0.734375      Y399.273
G01      Z-1
G01      X399.266      Y399.273
G01      X399.266      Y0.746094
G01      X0.734375      Y0.746094
G01      X0.734375      Y399.273
G00      Z0
G00      X345.828      Y234.496
G01      Z-1
G01      X345.287      Y222.486
G01      X343.693      Y210.76
G01      X341.091      Y199.36
G01      X337.524      Y188.326
G01      X333.037      Y177.702
G01      X327.675      Y167.528
G01      X321.481      Y157.847
G01      X314.5      Y148.701
G01      X306.776      Y140.13
G01      X298.353      Y132.177
G01      X289.275      Y124.884
G01      X279.588      Y118.293
G01      X269.334      Y112.445
G01      X258.559      Y107.382
G01      X247.306      Y103.145
G01      X235.62      Y99.7777
G01      X223.546      Y97.3206
G01      X211.126      Y95.8156
G01      X198.406      Y95.3047
G01      X185.687      Y95.8156
G01      X173.268      Y97.3206
G01      X161.193      Y99.7777
G01      X149.508      Y103.145
G01      X138.255      Y107.382
G01      X127.48      Y112.445
G01      X117.227      Y118.293
G01      X107.54      Y124.884
G01      X98.4628      Y132.177
G01      X90.0401      Y140.13
G01      X82.3161      Y148.701
G01      X75.3351      Y157.847
G01      X69.1413      Y167.528
G01      X63.779      Y177.702
G01      X59.2923      Y188.326
G01      X55.7257      Y199.36
G01      X53.1233      Y210.76
G01      X51.5294      Y222.486
G01      X50.9883      Y234.496
G01      X51.5294      Y246.506
G01      X53.1233      Y258.233
G01      X55.7257      Y269.634
G01      X59.2923      Y280.667
G01      X63.779      Y291.292
G01      X69.1413      Y301.466
G01      X75.3351      Y311.147
G01      X82.3161      Y320.293
G01      X90.0401      Y328.864
G01      X98.4628      Y336.817
G01      X107.54      Y344.109
G01      X117.227      Y350.701
G01      X127.48      Y356.549
G01      X138.255      Y361.612
G01      X149.508      Y365.848
G01      X161.193      Y369.215
G01      X173.268      Y371.672
G01      X185.687      Y373.177
G01      X198.406      Y373.688
G01      X211.126      Y373.177
G01      X223.546      Y371.672
G01      X235.62      Y369.215
G01      X247.306      Y365.848
G01      X258.559      Y361.612
G01      X269.334      Y356.549
G01      X279.588      Y350.701
G01      X289.275      Y344.109
G01      X298.353      Y336.817
G01      X306.776      Y328.864
G01      X314.5      Y320.293
G01      X321.481      Y311.147
G01      X327.675      Y301.466
G01      X333.037      Y291.292
G01      X337.524      Y280.667
G01      X341.091      Y269.634
G01      X343.693      Y258.233
G01      X345.287      Y246.506
G01      X345.828      Y234.496
G01      X345.828      Y234.496
G00      Z0
M5
M9
M2

This is what reprap uses as end of command

 //newlines are ends of commands.
      if (c != '\n')

dropped in there a few of those commands you linked but had nothing working :/ probably what i modified in there just doesn't wanna work.

I tried http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1266086738 and with this one i managed to make it work (it uses " ! " ) as end of commands. Tho i liked more the Reprap one as it was able to handle also G2 and G3 commands (curves made clockwise and counterclockwise) while instead that other G code interpreter only works with G1 (and it wants it as G1 not G01 or it will think it's G0). Seems like there's not only one standard g-code damn it. Atm i'm looking for something to send line by line over serial without having to write each line in the serial window. I'll look if i can do something with C :S I think the bad thing of not being able of using G2 and G3 is that you have to do an endless amount of G1 commands (no that you have to write them on your own..ok but it sounds a lot less..."linear" if you understand what i mean).

Anyother suggestion or way to go trough in your opinion Roypardi?

I guess it depends on how you plan to ouput your gcode. There seem like lots of variations. RepRap (apparently) uses this: http://objects.reprap.org/wiki/RepRapGCodes

but I am using the 3rd gen firmware right now and it doesn't conform to that standard. I plan to switch over eventually. I'm no expert on this stuff but what I plan to do is use that standard above and then preprocess the source gcode in the client to insure that it comforms rather than tinkering with the firmware. That said, I still prefer an explicit char to designate the end of a cmd rather than line endings. Maybe I'll get over that...

I'm checking that Processing thing you posted about, looks very interesting! With the script at the previous link i posted i managed to make my steppers but after some tought and comparisons i think that script is very unclean still. I'm still trying to get reprap one to work damn it:) What are you using to drive your steppers? Adafruit shield or something else?

I’m not using steppers in this project - it’s a very old 36" HP plotter that I am reviving- this thing is massive! It has 24v motors w/ quad encoders and I’m controlling them through 2 Gamoto boards (http://www.gamatronix.com/product_info.php/manufacturers_id/10/products_id/28). I am using the step/direction capability of the Gamoto firmware so interfacing with RepRap was trivial.

Processing is pretty easy to get up with - loads of example code for serial <-> to Arduino. You can just concatenate a line feed after each string you send. If you haven’t done much serial stuff with Arduino, maybe take a pitstop from the RepRap stuff and do some test sketches.

Here’s my Processing serial code - there are a few dependencies that will need to get stripped out. You would need to call ‘checkSerialInput()’ from the Processing draw() function.

import processing.serial.*;
 
Serial sPort;       
boolean serialActive = false;
String dataIn;


void openSerialConnection() {
  sPort = new Serial(this, Serial.list()[0], 115200);
  serialActive = true;
}

void closeSerialConnection() {
  if (serialActive == true) {
    sPort.stop();  // close serial
  }
}

void sendCommand(String s) {
 if (serialActive == false) return;
  int ln = s.length();
  for (int i = 0; i < ln; i++) {
    sPort.write(s.charAt(i));
  }
}

String checkSerialInput() {

  String tmpString = "-1";
  if (serialActive == false) return tmpString;

  while (sPort.available() > 0) {
    char c = sPort.readChar();

    if (c == '*') {
      logEvent(dataIn);
      tmpString = dataIn;
      dataIn = "";
      return tmpString;
    } 
    else  if (c == '

) {

if (plottoState == PRINTING) {
       tmpString = “P”;
       return tmpString;
     }
   }
   else  if (c == ‘@’) {
     tmpString = “R”;
   }

else {
     dataIn += c;
   }
 }
 return tmpString;
}

Yep i'm now checking it:) I might have to write my own g-code interpreter in the end darn:P