100Views10Replies

Author Options:

Load and print file lines in processing? Answered

I want to make a cnc/3D printer using arduino, and right now my main obstacle (besides slow shipping on the remaining motor drivers) is how to get G-code to the arduino.  I have a way to get the Gcode in a .txt file, but I need to separate every line, then send it over serial every ~2 seconds.  Is this possible with processing, and if so, how do I do it. 

Note: it needs to send each line separately, and so the arduino reads it as X# Y#, not just ## ##  not sure if there's a difference, but if there is, it must be picked up that way.  Also, I have GloviePIE, (a keboard emulator), if that helps in any way.   

Thanks

Comments

The forums are retiring in 2021 and are now closed for new topics and comments.
0
steveastrouk
steveastrouk

8 years ago

The Arduino can read multiple parameters off one line, with no problem at all. Just use scanf.

0
jduffy54
jduffy54

Answer 8 years ago

A) whats scanf?
B) I wrote code that can ONLY read one line at a time.
C) I don't think the arduino has enough memory to store several thousand points, which it would have to for any 3-D object.

0
steveastrouk
steveastrouk

Answer 8 years ago

A. ) Look it up. B.) You can send X-Y pairs on one line, its less confusing, and safer to parse. C.) True, but not relevant to your question. You want to send a complete G code on one line, just like real CNC machines do. Here's an example

(Sample Program G01EX2:)
(Workpiece Size: X4, Y3, Z1)
(Tool: Tool #3, 3/8" Slot Drill)
(Tool Start Position: X0, Y0, Z1)

N2 G90 G80 G40 G54 G20 G17 G50 G94 G64 (safety block)
N5 G90 G20 (Block #5, absolute in inches)
N10 M06 T3 G43 H3 (Tool change to Tool #3)
N15 M03 S1250 (Spindle on CW at 1250 rpm)
N20 G00 X1.0 Y1.0 (Rapid over to X1,Y1)
N25 Z0.1 (Rapid down to Z0.1)

Lets parse this line.

N30 G01 Z-0.125 F5 (Feed down to Z–0.125 at 5 ipm)
  ^ useful, but not needed. Ignore.
         ^ A G, this is a Gcode, not an Mcode.
            ^A number: Remember it
              ^ Another number. Remember that.
                 ^An argument
                                ^Another argument.
                                      ^A comment: ignore rest of line.


If you read up on Scanf, you can get all the bits of a typical line into your arduino in a couple of lines of code

0
jduffy54
jduffy54

Answer 8 years ago

I have a compleatley unusual setup of hardware, so my software has to match it. I checked, and no one else uses the same setup, at least as far as I could find. I already have it set to recieve one line at a time (XYZ coordinate), not separate lines for each dimension. (it separates at each X, Y, and Z), but the problem comes in that the arduino doesn't differentiate between multiple Xs Ys and Zs, so when I send more than one line, it messes up.
I have a G-code program, slic3r, so I know what G-code looks like, and what it does. I don't care about tools, blocks, speeds, etc. right now, JUST feeding XYZ coordinates.

If you don't have an answer to the question that was asked, don't answer it.

0
steveastrouk
steveastrouk

Answer 8 years ago

Then you need to make a data buffer. Look up "buffering" and look for coding a FIFO buffer. Then you can store multiple lines

0
steveastrouk
steveastrouk

Answer 8 years ago

...Also, when a line is being processed, you can use software serial handshaking to stop the transmission of data from the source. When the line is finished, or the buffer is empty, then the arduino tells the source its ready for more data.

0
jduffy54
jduffy54

Answer 8 years ago

Thanks, Ill try the handshaking thing. Does that work kind of like I2C?

0
steveastrouk
steveastrouk

Answer 8 years ago

RS232 has five lines for the purposes of this discussion,
Ground
Transmit,
Receive
RTS (READY to send)
CTS (CLEAR to send)

CTS is ME saying I WANT information.
RTS is YOU saying you HAVE information.

Algorithm
Repeat.
    Repeat
      Read character.
     Save character to buffer
    until character = CR or buffer full.

   If buffer full   clear CTS
   REPEAT
     {process stuff}
   UNTIL buffer either not full or empty set CTS

Until EOF

0
jduffy54
jduffy54

Answer 8 years ago

Actually, I was looking up handshaking when I found exactly what I needed for what I was originally going to do, and I just finished writing and testing the code for that. Thanks for your help, though.

0
steveastrouk
steveastrouk

Answer 8 years ago

...or you can use hardware handshaking, which is more reliable, then you use the "RTS" and "CTS" signals on the serial port. Set CTS when you need data, clear it when you have enough - the other end will stop sending until RTS goes low again.