gnea / grbl

An open source, embedded, high performance g-code-parser and CNC milling controller written in optimized C that will run on a straight Arduino
https://github.com/gnea/grbl/wiki
Other
4.03k stars 1.6k forks source link

SAVE G-CODE FILE #993

Open arlimbad222 opened 3 years ago

arlimbad222 commented 3 years ago

Hey forks

I am making one horizontal milling & want to run only 25 line of gcode per cycle is there any way to save gcode file on board & run that file with cycle start button push and stop with stop button push. currently i am using one old laptop to send only 25 line of gcode . and there is no editing riquired just 25 line gcode for life time .

thankyou for help.

SimonJohnCastle commented 3 years ago

Its a trivial exercise to store a small GCODE in an Arduino Nano and have it sent out on rest or button press. Or get one of those cheap offline controllers and use that, if your HW supports it already.

Unfortunately you dont say what you are using.

arlimbad222 commented 3 years ago

Hey @SimonJohnCastle

I am using Arduino Uno with grbl 1.1f currently using ugs to send gcode but if it possible to store some gcode on Arduino Uno and send them by simple physical button . I don't have much experience on coding so I am here for some help.

harryberlin commented 3 years ago

Candle has custom buttons for cuttom gcodes

arlimbad222 commented 3 years ago

Hey @harryberlin

What is candle brother I don't know about that think I only use grbl and not an coding guy basically am mechanical engineer can you please explain me breef what is candle ?

SimonJohnCastle commented 3 years ago

Candle is PC SW for sending GCODE to GRBL, so not what you want.

You can get a Nano clone very inexpensively or use another Uno if you have one, easy to programm, just plug in and go. If you are new to Arduino programming, its very easy and there are many examples, all you would have to do is send the GCODE over the serial port as strings. To make things easy so you dont have to worry about the responces from GRBL you can put delays between each line to allow time for the machine to perform its task. Not the best but probably good enough for what you want.

Connect GND, 5V and cross the Rx/Tx lines between the 2 Arduinos

arlimbad222 commented 3 years ago

Hey @SimonJohnCastle

First sorry I can't understand that things because I am mechanical guy . Suppose I have one Uno with grbl 1.1 & second Uno blank which code I have to give second uno I don't have any experience on coding if it easy can you please make one for me .

SimonJohnCastle commented 3 years ago

Get the Arduino IDE from https://www.arduino.cc/en/software

The Arduino 'C' code is very simple, all you need is something like below, and upload it to your second Arduino, you can upload this and test it directly on your Uno from your PC. If you open the Tools/Serial_Monitor you should see the output from the executing code, see image you need to select the speed 115200 which should match GRBL as they need to talk at the same bit speed (If all this is new to you)

` void setup() { Serial.begin(115200); // delay(10000); // Long 10 Second Delay to allow GRBL to BOOT and get ready Serial.println("G90"); delay(100); Serial.println("G1 X10 Y10"); delay(100); Serial.println("G1 X100"); delay(1000); // Wait 1 Second for movment to complete Serial.println("G1 X-100"); // ADD all your GCODE }

void loop() { } `

SendGcode

The above code will simply execute each time the Arduino resets, Press reset and see it run again in the open monitor.

As a minimum you need to connect the GND of both Arduinos together and the TX pin of the second one to the RX pin of GRBL one, The second also needs 5V which you may be able to get from the GRBL one os a second supply

arlimbad222 commented 3 years ago

Thankyou so much @SimonJohnCastle

Now I understand is there any way to add push button to start , hold and stop cycle for machine safety.

SimonJohnCastle commented 3 years ago

yes its very easy to add a button, once you see how easy it is you can learn on your own. Look at the examples You can test all this without connecting it to GRBL, just imagine the Serial Monitor is GRBL and as you press buttons/ reset etc this would then be what GRBL receives. Your main danger is sending GCODE too fast which would be lost as this approach doesnt check when GRBL is ready for the next GCODE

arlimbad222 commented 3 years ago

Thanks again @SimonJohnCastle

I'll buy electronics tomorrow then test it if I need any help I'll drop here 🙏

harryberlin commented 3 years ago

check this https://github.com/mathertel/OneButton don't use delay, because you can initiate stop event every time.

arlimbad222 commented 3 years ago

hello @harryberlin @SimonJohnCastle

I manage all electronic today and test the code but when i give a code to mega with grbl it gives lots of errors (25,24,1,2,) i think i want code that waits for ok response and then give second line of gcode to arduino mega with grbl & i am not good at coding side so please give me some advice i attach my ino file please see & give me advice

have a good day thank you all for help M3M5.txt

SimonJohnCastle commented 3 years ago

My original idea for you, was to use a delay between each G-Code to allow the machine to move before the next command is sent. This way you dont have to worry about the OK. Start simple by just having one or two movements in your button press, to prove the concept. (does it work at all ?) i.e. does Grbl get out of lock when you reset and perform the first move when you press the button. Then add in the extra G-Code with appropriate delays As your G-Code is a simple repeating sequence, where the movements are basically coming to a 'STOP' in any case, you can afford to delay say after the Y3, Y-25 before the X movement, so just put a long enough delay there, for each sequence of moves

arlimbad222 commented 3 years ago

HELLO @SimonJohnCastle

oh i just forgot to use delay between command line i will check this as soon as possible & update here .

thanks for quick responce.

SimonJohnCastle commented 3 years ago

you need something like an 11 second delay after the G01 Y22 F125 i.e. delay(11000); would be interesting to know what the machine is doing ?

arlimbad222 commented 3 years ago

hi @SimonJohnCastle

i am using one old horizontal milling machine to make 26 tooth on cast iron ring i attach some photos .

i am using X as a rotary axis & Y as a linear axis . not using ball screw or any cnc stuff just put 2 stepper motor and boom its working .

IMG_20210211_173433 IMG_20210211_173423 IMG_20210211_173443

SimonJohnCastle commented 3 years ago

Nice, now I understand the GCODE

arlimbad222 commented 3 years ago

Hi @SimonJohnCastle

Sorry for same question but I have 3 products like this & I am to lazy to find each code delay time I think there is some code that read ok message from grbl then put a second line of gcode if you have any idea how to do that please share I don't have any kind of coding experience.

Thankyou again and again .

SimonJohnCastle commented 3 years ago

In principle its not too difficult, assuming you dont get into error conditions and want to make it fault tolerant. The basic idea is to read from the serial port, either into an array or String and then look for the OK. You keep doing this until the OK arrives and then move on to sending the next GCODE, Look up Serial see readString etc String see lastIndexOf I cant give you a working example of the top of my head, but its not too difficult.

Oh and put a FOR loop round your code, rather than repeating it all

The delay times are not critical, so long as they are longer than you need, and I guess 1 or 2 seconds here or there is not too impotent for you, its a matter of where you want to invest your time, learning to programm it properly may be a good investment for you

harryberlin commented 3 years ago

G4 should be command for waiting

SimonJohnCastle commented 3 years ago

This does what you need, Tested as shown, type ok and press send Adjust it as needed for your button handling

Code attached gcode.txt

OK

arlimbad222 commented 3 years ago

Hi @SimonJohnCastle

Thankyou for your efforts I will test code by tomorrow I am little busy today sorry for that I'll get back here when done something practical test .

Thankyou again and again brother .

arlimbad222 commented 3 years ago

hi @SimonJohnCastle

I test the code but there is little problem when i want to send some real time command like (0x91 & 0x94) by button 2 . it finish that button 1 task then button 2 is working sorry for lots of question but seriously I don't have any coding skills i just copy and pest your code .

have a nice day my friend . M3M5.txt

SimonJohnCastle commented 3 years ago

your string is wrong it should be "\x91" which means a single character of value hex 91. Second I dont think GRBL responds with ok to real time commands so just use print or println like before, I dont know off my head if GRBL needs the linefeed for real time cmds, possibly not, I think it just looks in the stream for it

If your expecting to press button2 while its milling then its wont work, this is getting out of scope of what you said you initially needed, and needs more complex programming, where this is not really the place for discussion

what you have could be rearranged by the click scheduling a job in the main loop and the wait calling the tick to check for further button activity, but where will it stop

This may solve your problem but Im not familiar with the button library and have not tested it. its getting a bit reentrant

while(Serial.available() < 2) button2.tick();

does the whole thing work correctly if you put the FOR loop in to send it 26 times ? as you removed it in your uploaded code ?

arjunrayudu commented 10 months ago

EXLENT SOLUTION GREAT MR. SimonJohnCastle