need help programming with Gobetwino

Greetings,

I have adopted two programs that work individually and I want to combine them.

1- A micro-CNC Arduino UNO program from

that allows me to send a Gcode command line to a Shapeoko CNC via Arduino IDE GUI Tools>Serial Monitor such as G91;G01X1000Y0F1;G01X0Y900F1;G01X-1000Y0F1;G01X0Y-900F1;
that moves the CNC bit along a 2D rectangular path.
2- A windows PC resident Gobetwino program from

to read from a file on the PC line by line and send it to the serial port.

Would it be possible to combine these two programs so the micro-CNC would be commanded via a Gobetwino to read a Gcode machine code file (resident on PC) one line at the time thoroughly to do a machining job?

The marginally Clever program for Arduino has the following structures

  • setup
  • loop
  • process command
  • Parse each command

void loop() {
// listen for commands
while(Serial.available() > 0) { // if something is available
char c=Serial.read(); // get it
...........
processCommand()

void processCommand() {
// look for commands that start with 'G'
int cmd=parsenumber('G',-1);
switch(cmd) {
...
cmd=parsenumber('M',-1);
switch(cmd) {
...

float parsenumber(char code,float val) {
char *ptr=buffer;
while(ptr && *ptr && ptr<buffer+sofar) {
if(*ptr==code) {
return atof(ptr+1);
}
ptr=strchr(ptr,' ')+1;
}
return val;
}

and for Gobetwino:

  • setup
  • loop
  • read serial string

void readSerialString (char *strArray,long timeOut) {
// Wait up to timeOut miliseconds for data to arrive at the serial port, then read the data and put it in the char array strArray
long startTime=millis();
int i;

while (!Serial.available()) {
if (millis()-startTime >= timeOut) {
return;
}
}
while (Serial.available() && i < serInLen) {
strArray = Serial.read();

  • i++;*
  • }*
    }
    So when I run the Gobetwino program and I can see the Gcode line on its serial window, Does Arduino also see the same line? So why it doesn't respond? Is it a matter of data format? or should I write it again to the serial port?

For starters, you need to post your entire code, between code tags. What you've posted is a number of snippets, with some "..." strings between them. This makes it very difficult to see what's actually happening.

For example, your Arduino code in loop() is incomplete, bringing up a number of questions.

Do you gather complete G-code statements before parsing them?
Does the loop send anything back on the Serial port to indicate that it is finished parsing the line and sending it out?
Does it wait for any given G-code to complete on the machine?

I'm not familiar with Gobetwino, but you say it runs on the PC, but then you show us code for Gobetwino that is Arduino code. From this, I can only make the assumption that you are trying to incorporate the code to handle data from Gobetwino, within the same program that accepts data from the Serial port. If so, you should probably think about what Gobetwino is actually doing. From the code snippet it looks like it is just gathering data from the Serial port, which is what the other program is doing. So you only need to add any code that Gobetwino needs that is not already incorporated in the program that works with the Serial Monitor.

We'd like to help, but without full code for both programs, we can only make guesses as to what you need to do.

I downloaded Gobetwino and had a look at the docs.

It looks like a fairly simple matter to implement reading a file and sending it to the Arduino. All you really need to do in the Arduino sketch is to have it send the RFLIN command to get the next line. I would suggest using a fixed directory and filename for the file to be sent, and copying any file you want to use into that directory as the same name. You will also want to make sure that the Arduino has completed using the current line before asking for another one.

On the other hand, it's a fairly simple matter to write a program in C# or VB.Net to perform this action, and to send any file you want, without the Arduino having to know what the file name is, and without it having to keep track of the line to be sent.

Thanks lar3ry for your diligence.

I didn't want to copy the codes I am using here as they are more or less copies of other people's works. But if it helps me to continue with this project, I will elaborate on them here:

The first Arduino code is courtesy of dan@marginallycelver.com. The CNC responds to the command line: G91;G01 X1000 Y0 F1;G01 X0 Y900 F1;G01 X-1000 Y0 F1;G01 X0 Y-900 F1; by drawing a rectangle.
As my reply is too big, I have to cut Dan's code here (it will get repeated in my code)

The second Arduino code is the example which comes from Gadgets og teknologi | Dansk Tech Blog - Mikmo that reads the contents of a file on my PC line by line and forces the LED on Arduino UNO to blink depending on the number read from the file. The example can be downloaded from above location.

I have tried to combine the two codes together. As I don't have the basic training in c++ programming, it may be a shameful mingling of data formats. Anyway I will bite the bullet and copy my code here:

I had to remove the parts that are not relevant to shorten my reply, but it still doesn't fit. I added my file as attachment.

I first compile and run this program on Arduino IDE. Then I start the Gobetwino program on my PC that shows the following on its screen:

11/10/2013 9:47:06 PM,Serial port : COM4 opened at 57600 baud
11/10/2013 9:47:10 PM,Commandstring recieved : #S|GCODE|[1]#
11/10/2013 9:47:10 PM,Command parsed OK
11/10/2013 9:47:10 PM,Executing command : GCODE
11/10/2013 9:47:10 PM,Reading line 1 from C:\gobetwino\GcodePractice.txt succeeded.
11/10/2013 9:47:13 PM,Commandstring recieved : G91#S|GCODE|[2]#
11/10/2013 9:47:13 PM,The string recieved : G91#S|GCODE|[2]# is not a well formed command string
11/10/2013 9:47:25 PM,Commandstring recieved : G01X1000Y0F1#S|GCODE|[3]#
11/10/2013 9:47:25 PM,The string recieved : G01X1000Y0F1#S|GCODE|[3]# is not a well formed command string
11/10/2013 9:47:36 PM,Commandstring recieved : G01X0Y900F1#S|GCODE|[4]#
11/10/2013 9:47:36 PM,The string recieved : G01X0Y900F1#S|GCODE|[4]# is not a well formed command string
11/10/2013 9:47:49 PM,Commandstring recieved : G01X-1000Y0F1#S|GCODE|[5]#
11/10/2013 9:47:49 PM,The string recieved : G01X-1000Y0F1#S|GCODE|[5]# is not a well formed command string
11/10/2013 9:48:01 PM,Commandstring recieved : G01X0Y-900F1#S|GCODE|[1]#
11/10/2013 9:48:01 PM,The string recieved : G01X0Y-900F1#S|GCODE|[1]# is not a well formed command string
11/10/2013 9:48:11 PM,Commandstring recieved : #S|GCODE|[2]#
11/10/2013 9:48:11 PM,Command parsed OK
11/10/2013 9:48:11 PM,Executing command : GCODE
11/10/2013 9:48:11 PM,Reading line 2 from C:\gobetwino\GcodePractice.txt succeeded.

_2AxisV1_v3_10312013.ino (9.33 KB)

I think the problem (well, at least the first problem is shown by these two lines...

11/10/2013 9:47:13 PM,Commandstring recieved : G91#S|GCODE|[2]#
11/10/2013 9:47:13 PM,The string recieved : G91#S|GCODE|[2]# is not a well formed command string

This tells us that the Arduino is sending the code to get line 2, but it is being preceded by "G91", which is what you just sent.
This happens in this code:

    while(Serial.available() > 0) { // if something is available        
      char c=Serial.read();  // get it
      if(sofar<MAX_BUF) buffer[sofar++]=c;
      { // store it
        if(sofar>0 && buffer[sofar-1]==';') break;  // entire message received
      }
      Serial.print(c);            
      // we got a message and it ends with a semicolon
      buffer[sofar]=0;  // end the buffer so string functions work right
      processCommand();  // do something with the command
      ready();
    }

The line Serial.print(c) is the culprit. It's sending The first command back to the Gobetwino, one character at a time.
If you remove that line, you should see either a working sketch or another problem. Let us know how it goes.

Greetings and thanks for your suggestion. After removing the sentence:
Serial.print(c);
the gobetwino reflects that Arduino has read the content of my Gcode file (on the PC) line by line:

11/11/2013 9:25:24 PM,Serial port : COM4 opened at 57600 baud
11/11/2013 9:25:28 PM,Commandstring recieved : #S|GCODE|[1]#
11/11/2013 9:25:28 PM,Command parsed OK
11/11/2013 9:25:28 PM,Executing command : GCODE
11/11/2013 9:25:28 PM,Reading line 1 from C:\gobetwino\GcodePractice.txt succeeded.
11/11/2013 9:25:31 PM,Commandstring recieved : #S|GCODE|[2]#
11/11/2013 9:25:31 PM,Command parsed OK
11/11/2013 9:25:31 PM,Executing command : GCODE
11/11/2013 9:25:31 PM,Reading line 2 from C:\gobetwino\GcodePractice.txt succeeded.
11/11/2013 9:25:43 PM,Commandstring recieved : #S|GCODE|[3]#
11/11/2013 9:25:43 PM,Command parsed OK
11/11/2013 9:25:43 PM,Executing command : GCODE
11/11/2013 9:25:43 PM,Reading line 3 from C:\gobetwino\GcodePractice.txt succeeded.
11/11/2013 9:25:54 PM,Commandstring recieved : #S|GCODE|[4]#
11/11/2013 9:25:54 PM,Command parsed OK
11/11/2013 9:25:54 PM,Executing command : GCODE
11/11/2013 9:25:54 PM,Reading line 4 from C:\gobetwino\GcodePractice.txt succeeded.
11/11/2013 9:26:07 PM,Commandstring recieved : #S|GCODE|[5]#
11/11/2013 9:26:07 PM,Command parsed OK
11/11/2013 9:26:07 PM,Executing command : GCODE
11/11/2013 9:26:07 PM,Reading line 5 from C:\gobetwino\GcodePractice.txt succeeded.

Yet, the CNC didn't respond to the code-lines even though two LEDs on Arduino UNO (TX, RX) lights up every time. I hope you still have access to my previously attached file.

The code that works (when I send a line of Gcode from Arduino's Serial Monitor) is:

void loop() {
// listen for serial commands
while(Serial.available() > 0) { // if something is available
char c=Serial.read(); // get it
Serial.print(c); // repeat it back so I know you got the message
if(sofar<MAX_BUF) buffer[sofar++]=c; // store it
if(buffer[sofar-1]==';') break; // entire message received
}

if(sofar>0 && buffer[sofar-1]==';') {
// we got a message and it ends with a semicolon
buffer[sofar]=0; // end the buffer so string functions work right
Serial.print(F("\r\n")); // echo a return character for humans
processCommand(); // do something with the command
ready();
}
}

Thanks again for your time and help.