Show Posts
Pages: [1] 2 3 ... 5
1  Using Arduino / Programming Questions / Re: G-code - what am I doing wrong here on: October 29, 2013, 01:00:40 pm
thanks for all help folks.

Problem was probably running out of memory. Defined a small array and now it works.

Ill move away from string.class later if needed.

regards
2  Using Arduino / Programming Questions / Re: G-code - what am I doing wrong here on: October 28, 2013, 05:15:33 pm
I'm pretty sure the problem is that you have not defined a size for
Code:
String curgkode[]="";
String param[]="";

and later when you initialize those arrays the data overwrites all sorts of other stuff. Before you correct anything try printing the value of "lengde" immediately after it is created and again after the arrays are intitalized - the value will have disappeared.

You need to allocate enough space for the two arrays so that they can fit the biggest gkode. For example

Code:
String curgkode[50]="";
String param[50]="";

I noticed that you had little or no debugging "Serial.println()" stuff in your code. It's pretty hard to figure things out without it.

...R

I thought arrayname[] was a way to define arrays with unknown number of elements.(?)
Perhaps it wont work in Arduino?
There may be an indication of overwriting data as You suggest due to the outputs of param array.
The lines of g-code, to my knowledge, contains seldom codes/parameters of high numbers so I'll try to define
arrays with limited numbers of elements and see how that will work out.
thanks.
regards
3  Using Arduino / Programming Questions / Re: G-code - what am I doing wrong here on: October 28, 2013, 05:10:30 pm
The OP, janeik, wants to go from a typical Gcode command line to two arrays, one that contains the command character and a corresponding array that contains the value. janeik still needs to make that a numric array, as the string values probably are of little use. The challnge is that this comes from a SD card so the Serial.parseFloat isnt possible - with it it's so easy.

I haven't played with the SD library, so I dont know if it has inherited the parseFloat via the Stream class....

Thanks, Your right in your description of what I try to achieve. smiley
regards
4  Using Arduino / Programming Questions / Re: G-code - what am I doing wrong here on: October 28, 2013, 05:06:41 pm
I can't figure out what you are trying to do and the code you have posted has no setup() section so I can't get it to work.

...R

Sri, Ive added it now. (Serial.begin.....

regards
5  Using Arduino / Programming Questions / Re: G-code - what am I doing wrong here on: October 28, 2013, 03:19:02 pm
hey folks.
Would appreciate some help, pointing out why I dont get result I want.
Below is the attached code.
regards
Code:
String gkode= "G1 X45.676 Y97.404 F3600.000 E40.83666"; // inneholder eksempel textlinje lest fra .gcode fil
// String gkode= "; M104 S200 ;set temperature"; // test for kommentarer
// String gkode="";
String curgkode[]="";
String param[]="";
int i=0;
int j=0;
int k=0;
int lengde;
int teller;

void setup()
{
  Serial.begin(9600);
}


void loop()
{
//  vent til programstart bryter er på
//  åpne slicer filen på SD-lageret i lese-modus
//  while not(EOF)
//  les linje fra tekstfil
//  parse tekstlinjen

   delay(3000);
    j=0;
    i=0;
    gkode.trim();
    lengde=gkode.length();
    gkode.toUpperCase();
    
    for (int i=0; i<lengde;i++)
    {
     curgkode[i]="";
    }
  
   for (i=0; i<lengde;i++)
    {
     param[i]="";
    }
   i=0;
  
    for (i = 0; i<lengde;i++)
    {        
/*            //  Serial.println(char(gkode.charAt(i)));
              if (gkode.charAt(i)==';') // ikke utfør kommentarer
             {
               i=lengde;          
             }
*/
              // look for letters)
              if ((int(gkode.charAt(i))>64 && int(gkode.charAt(i))<91))
                  {
                   curgkode[j]+=String(gkode.charAt(i));
                  }

             // look for numbers 0-9 . and + or - sign
             if((int(gkode.charAt(i))>44 && int(gkode.charAt(i))<58))
                  {
//                    Serial.println(gkode.charAt(i));
                    
                    param[j]=param[j]+String(gkode.charAt(i));
                    param[j].trim();
                    Serial.print(j);
                    Serial.print(" = ");
                    Serial.println(param[j]);
                    Serial.println(gkode.charAt(i));
                  }
                
              if ((int(gkode.charAt(i))>64 && int(gkode.charAt(i))<91))
                  {
                   j=j+1;
                  }

              
   } // end for i
  
/*                 Everything seemes to work until I try to print elements in the param array and
                 prints this:
                             1Y
                             45.676F
                             97.404E
                             3600.000
*/

                //  Serial.println(curgkode[m]);
                  Serial.println(String(param[0]));
                  Serial.println(String(param[1]));
                  Serial.println(String(param[2]));
                  Serial.println(String(param[3]));
                  Serial.println(String(param[4]));
                

//  sett parametre gitt i G-type instruksjoner
//    setparam();
}  // end of loop
6  Using Arduino / Programming Questions / Re: G-code - what am I doing wrong here on: October 27, 2013, 05:18:53 pm
I am working on a system where my PC converts the GCode to a series of numbers representing the microseconds at which each motor should step plus the total time for the movement. That way the Arduino has little to do apart from figure out how many usecs have passed.

...R

Im not yet sure if to use servoes or steppers. Ill have to try running steppers with controller and accellib first to get some experiences.
I have a feeling the controller Ive bought (big easy) isnt fast enough and if uC Mega 2560 is fast enough to control steppers in full 16 microsteps for x,y (and z  axes).
So You solely rely on timing to move steppers around? No counting steps? (wonder if 1/16 ustepping and 1.8deg/step rotation is enough  accuracy, moving steppers around).
Wish You luck with your project.
regards
7  Using Arduino / Programming Questions / Re: G-code - what am I doing wrong here on: October 27, 2013, 02:32:46 pm
Thanks G you didnt tell I was reinventing the wheel smiley.

I don't know if you have any use for your project apart from educating yourself ... but if you want to drive stepper motors with GCode there are several pieces of Arduino software such as Grbl and Sprinter.

However my question arose because I can't understand why the authors of those programs interpret GCode on the Arduino rather than on a PC - especially as the GCode is generated on a PC in the first place.

...R

hi smiley
Thanks. Im aware of the Norwegian made Grbl which is the bottom of many nc/reprap firmwares. Its mainly for my curosity and trying to look into whats really happening below the surface.
Yes, its for driving steppermotor's , hopefully  in a homemade cnc.
What I dont understand is why Norwegians did develope the structure of the Arduino and then SELLING IT AWAY smiley
(I asume they didnt give it away free).
regards
8  Using Arduino / Programming Questions / Re: G-code - what am I doing wrong here on: October 27, 2013, 02:21:57 pm
Case is, the program stores the 5 g-codes from the gkode sentence correctly in array. (G,X,Y,F,E)
However, the 2nd if statement, commented, regarding parameter array store theese values: (X,Y,F,E,SPACE) , where I should expect the parameters (numbers/minus sign/period)
The 2nd if statement regarding parameter array also messes up my curgkode array too.

I think Ive stearing at this too long, getting blinded.

Slightly modified code:

Code:
  delay(3000);
    j=0;
    i=0;
    gkode.trim();
    lengde=gkode.length();
    gkode.toUpperCase();
    
    for (int i=0; i<lengde;i++)
    {
     curgkode[i]="";
    }
  
   for (i=0; i<lengde;i++)
    {
     parameter[i]="";
    }
  
  
    for (i = 0; i<lengde;i++)
    {        
            //  Serial.println(i);
            //  Serial.println(char(gkode.charAt(i)));
              if (gkode.charAt(i)==';') // ikke utfør kommentarer
             {
               i=lengde;          
             }
 //  Serial.println(int(gkode.charAt(i)));
 
  
              if ((int(gkode.charAt(i))>64 && int(gkode.charAt(i))<91))
                  {
                   curgkode[j]+=gkode.charAt(i);
                  }


 /*             if((int(gkode.charAt(i))>44 && int(gkode.charAt(i))<58))
                  {
                    parameter[j]+=gkode.charAt(i);  
                    
                  }
 */                
              if ((int(gkode.charAt(i))>64 && int(gkode.charAt(i))<91))
                  {
                   j=j+1;
                  }

              
   } // end for i
  
  
 
             for (int m=0; m<j;m++)
                  {
                  Serial.print("curgkode ");
                  Serial.print(m);
                  Serial.print(" = ");
                  Serial.println(curgkode[m]);
                  Serial.println(parameter[m]);
9  Using Arduino / Programming Questions / Re: G-code - what am I doing wrong here on: October 27, 2013, 12:55:11 pm
Quote
1) read a line (block) of g-code
Nothing in that requirement indicates that a String is necessary. Big boys use strings - NULL terminated arrays of chars.

Quote
2) Find all gcodes ( G,X,Y,Z,M) and store them in an array named curgekode[j]
curgekode[j] is not an array. It is an element of the array curgekode. strtok() would parse the data quite easily, if the data was a string.

Quote
3) Find all parameters and store them in an array named parameter[j]
Same comments.

hm, there might be no delimitters in the g-code sentence

The sentence may be written i.e. like this: G1X45.676 Y97.404F3600.000E40.83666
regards
10  Using Arduino / Programming Questions / Re: G-code - what am I doing wrong here on: October 27, 2013, 12:47:22 pm
Out of personal curiosity, why are you doing this GCode stuff on an Arduino rather than a PC - where it would be trivial?

...R

Thanks G you didnt tell I was reinventing the wheel smiley.
Im doing this cause Im curios and happens to own an Arduino M 2560

best regards
11  Using Arduino / Programming Questions / Re: G-code - what am I doing wrong here on: October 27, 2013, 10:04:14 am
Quote
1) read a line (block) of g-code
Nothing in that requirement indicates that a String is necessary. Big boys use strings - NULL terminated arrays of chars.

Quote
2) Find all gcodes ( G,X,Y,Z,M) and store them in an array named curgekode[j]
curgekode[j] is not an array. It is an element of the array curgekode. strtok() would parse the data quite easily, if the data was a string.

Quote
3) Find all parameters and store them in an array named parameter[j]
Same comments.

ad 1 : Do I understand You right saying  suggesting I should work with array of chars instead of string object?
ad 2: Ah, too long since last working with array's. I suppose the strtok() works in Arduino.

regards and thanks
12  Using Arduino / Programming Questions / Re: G-code - what am I doing wrong here on: October 27, 2013, 09:31:10 am
hi Paul and Mark, thanks for reply

heres the definitions

int j=1; // number of commands in a g-kode line;
int k=0;
int lengde;
int teller;
int comlengde;
String kommando="";
String gkode= "G1 X45.676 Y97.404 F3600.000 E40.83666"; // inneholder eksempel textlinje lest fra .gcode fil
// String gkode= "; M104 S200 ;set temperature"; // test for kommentarer
// String gkode="";
String curgkode[]="";
String parameter[]="";
int paramlengde=0;

and program :
Code:
void loop()
{
//  vent til programstart bryter er på
//  åpne slicer filen på SD-lageret i lese-modus
//  while not(EOF)
//  les linje fra tekstfil

//  parse tekstlinjen

  
    
//    parser(gkode);
   delay(3000);
   // int j=1;
    j=0;
    int i=0;
    gkode.trim();
    lengde=gkode.length();
    gkode.toUpperCase();
    for (int i=0; i<lengde;i++)
    {
     curgkode[i]="";
    }
  
   for (int i=0; i<lengde;i++)
    {
     parameter[i]="";
    }
  
  
    for (int m = 0; m<lengde;m++)
    {        
            //  Serial.println(i);
            //  Serial.println(char(gkode.charAt(i)));
              if (gkode.charAt(m)==';') // ikke utfør kommentarer
             {
               i=lengde;          
             }
 //  Serial.println(int(gkode.charAt(i)));
 
  
              if ((int(gkode.charAt(i))>64 && int(gkode.charAt(i))<91))
                  {
                   curgkode[j]=curgkode[j]+(gkode.charAt(i));
                   j=j+1;
                  }

 
              if((int(gkode.charAt(i))>44 && int(gkode.charAt(i))<58))
                  {
                    parameter[j]=parameter[j]+gkode.charAt(i);  
                    
                  }
 Serial.println(j);
              
   } // end for i

What I want to do is
1) read a line (block) of g-code
2) Find all gcodes ( G,X,Y,Z,M) and store them in an array named curgkode[j]
3) Find all parameters, belonging to each gcode, and store them in an array named parameter[j]
by reading  teststring, gkode,  one character at a time until end of line

The if test of  ';' is to get rid of comments fields

thank You
regards
13  Using Arduino / Programming Questions / G-code - what am I doing wrong here on: October 27, 2013, 07:31:01 am
hi trying to place codes and parameters, but the if statements seemes not to work

this is the line to split into code and parameter: String gkode= "G1 X45.676 Y97.404 F3600.000 E40.83666";

heres the code:
Code:
   delay(3000);
   // int j=1;
    j=0;
    int i=0;
    gkode.trim();
    lengde=gkode.length();
    gkode.toUpperCase();
    for (int i=0; i<lengde;i++)
    {
     curgkode[i]="";
    }
   
   for (int i=0; i<lengde;i++)
    {
     parameter[i]="";
    }
   
   
    for (int m = 0; m<lengde;m++)
    {         
            //  Serial.println(i);
            //  Serial.println(char(gkode.charAt(i)));
              if (gkode.charAt(m)==';') // ikke utfør kommentarer
             {
               i=lengde;           
             }
 //  Serial.println(int(gkode.charAt(i)));
 
 
              if ((int(gkode.charAt(i))>64 && int(gkode.charAt(i))<91))
                  {
                   curgkode[j]=curgkode[j]+(gkode.charAt(i));
                   j=j+1;
                  }

 
              if((int(gkode.charAt(i))>44 && int(gkode.charAt(i))<58))
                  {
                    parameter[j]=parameter[j]+gkode.charAt(i); 
                   
                  }
 Serial.println(j);
             
   } // end for i
14  Using Arduino / Motors, Mechanics, and Power / Re: Auto Pilot for Tiny Yacht on: October 25, 2013, 06:43:59 pm
I've now connected up the bits. For test purposes I've fitted a Global EM406A GPS on a Sparkfun shield with through connections.  To digital I/O pin 9 I've connected a standard RC Servo. To digital I/O pin 3 I've connected the "SET" switch.

I've run the GPS test program and can see streams of data fly up the screen on my computer monitor.
I've run the Servo test program "Sweep" and the servo rotates back and fwd 180º

Pictures:




I've used digital pin 3 for the "Set" input. The spare un-connected wires in the picture are from Pins 2 and 4 and will be for +1º  -1º if added.


H E L P !

hi
You generally wont let inputs float, as it will when switch is open. You may get random levels at uC  input..
A pullup/pulldown may solve this.
Using switch may produce short voltage peaks (bouncing). Solve this either by software or hardware method.

What You might want next in program is to look for the sentence(s) that contains the informations you want to use.

Ship Ohoi

regards
15  Using Arduino / Project Guidance / Re: Pulling a rope up and down with small weight on: October 25, 2013, 06:04:04 pm
Hi makers and wizzards!

I'm looking to pull a rope up and down with a motor;
after failing with a servo (and learning alot about servos along the way) I was wondering what you guys think the best aproach might be; the installation would be on day and night and will go up/down about 100 times/day and should not take more than 5 seconds to pull about 2 meters of rope so that's a speed of about 40cm/sec or 30,76rpm at the motor;

the tricky part is to let the motor stop everytime at the exact same locations; are there any high-speed stepper motors you guys recommend? or use a continues servo (but how to do flawless sensoring if the rope is up or down?)


Eternal thanks for your help!

If its important to keep track of position, use a servo. You'll get more power but its a bit more costly than ie stepper.
High speed steppers? Perhaps turn off microstepping or use a stepper with higher angle pr. step? Or a gear?
An endstop switch to tell where to stop and reverse if you use stepper or brushless motor?
If weight is of concern, use pulley/tackle?
regards
Pages: [1] 2 3 ... 5