I want to use my arduino for executing some g-code. I found the g code-interpreter firmware called Grbl, but I need a stand alone version. I would like to have a software based interpreter that produces the code I could use in my arduino sketch. An other solution would be storing the G code on an other arduino and sending it to a second one, which has th Grbl firmware on board.
I don't understand your question. I never work with grbl, but I think that it is a "stand alone version". Can you explain more what you're thinking to do?
Grbl is a complete firmware that handles serial inputs in form of g code and sends it directly to stepper motors. I need to do some other tasks and i guess its not easy to alter this firmware in that way, because its implemented to run without any further tasks. Therefore i thought, there maybe is another sketch or snippet which imcludes the alteady converted g code so that the arduino does not have to do that. I am using just one template, therefire i have no need to hav a realtime-conversion of a new g-code and it maybe would be easier and more lightweight doing it that way...
luisilva:
Hi Hahi.
I don't understand your question. I never work with grbl, but I think that it is a "stand alone version". Can you explain more what you're thinking to do?
Can you give more detail of what you want your Arduino to do?
I've never understood why people choose to interpret G-Code on an Arduino rather than on a PC.
In either case data has to come from a file (on a PC or on an SD Card) because the Arduino doesn't have enough SRAM to store a whole G-Code sequence. The file might as well be just a set of numbers for the movements of the stepper motors that have already been figured out on the PC which has far more computing power. Also if the interpretation of the G-Code is separated from the control of the motors it doesn't use up valuable CPU time on the Arduino. And, equally, it doesn't matter how long it takes to convert the G-Code to numbers because there are no tool-movements anxiously waiting for the next movement data.
Thats exactly what i meant. But how do i get a file in a form of a set of numbers for the stepper-movements?
Maybe its not a real arduino problem in general to convert the g code nto stepper-numbers, but in a way it is, because i maybe need to communicate with some kind of arduino-specific stepper library. So do you know a pc software to convert my g code to a arduino-compatible and stepper-readable file?
Robin2:
Can you give more detail of what you want your Arduino to do?
I've never understood why people choose to interpret G-Code on an Arduino rather than on a PC.
In either case data has to come from a file (on a PC or on an SD Card) because the Arduino doesn't have enough SRAM to store a whole G-Code sequence. The file might as well be just a set of numbers for the movements of the stepper motors that have already been figured out on the PC which has far more computing power. Also if the interpretation of the G-Code is separated from the control of the motors it doesn't use up valuable CPU time on the Arduino. And, equally, it doesn't matter how long it takes to convert the G-Code to numbers because there are no tool-movements anxiously waiting for the next movement data.
Hahi:
So do you know a pc software to convert my g code to a arduino-compatible and stepper-readable file?
I'm afraid I don't. But it's not very difficult, at least for the more common GCodes.
I can't immediately remember how a G-Code line is specified but suppose it tells the tooltip to move 200mm on the X axis and 147mm on the Y axis.
What do your stepper motors have to do to make that happen. Suppose the X stepper needs 1400 steps for 200mm and the Y stepper needs 882 steps for 147 mm. (all numbers just chosen at random for illustration).
I think you will see that there has to be a simple and fixed relationship between the G-Code numbers and the stepper numbers.
It should be fairly straightforward to write a PC program that would work through a text file containing G-Code and pick out the different commands. Then you could have a small function for each command that would convert its data into the appropriate stepper numbers. The PC program would store the numbers in another file. When it comes time to use the numbers the PC will have a short program that just sends data from the numbers file as requested by the Arduino.
I am slowly (when the humour takes me) doing a project like this myself. My intention is to send to the Arduino the following data for each move
The total number of microseconds for the move (which will take account of desired tool speed)
The number of microseconds between each step for the X axis motor
And for the Y axis motor
And for the Z axis motor
While the Arduino is executing the move the PC can send the data for next move.
I have used Grbl and was actually quite impressed with the sort of things it needs to take in to account. It's not actually as simple as calculating steps and issuing the necessary signals to the stepper drivers, you may need to adjust timing of coordinated moves (i.e. more than one stepper in motion) for getting smooth curves, for handling acceleration/decelaration correctly, for awareness of the preferred cutting direction of the tool, for minimising backlash effects, etc. ...
I'm not saying don't do it - I'm just trying to say that the devil is sometimes in the detail .....
Perhaps one reason for the G-code interpretation on Arduino is that you can just supply a tool with code on an SD card, without the need for a PC or whatever.
RogerRowland:
Perhaps one reason for the G-code interpretation on Arduino is that you can just supply a tool with code on an SD card, without the need for a PC or whatever.
I don't see this as an argument for intepreting the G-Code on the Arduino. The output of G-Code interpreted on a PC could also be put on an SD Card for an Arduino.
The process I'm thinking of is the same as if you modified GRBL so that instead of driving the motors directly it saves the step information to an SD Card.
Robin2:
I don't see this as an argument for intepreting the G-Code on the Arduino. The output of G-Code interpreted on a PC could also be put on an SD Card for an Arduino.
Well I see where you're coming from, but one argument would be that the processed G-code would have to deliver the step info specific to the particular hardware (motors, drivers, etc.) so all the info about the number of steps per revolution, the pitch of the lead screws, the maximum stepper rates etc. would all be encapsulated in that processed file so it wouldn't be as portable as the original G-code.
That's why the configuration data is stored by Grbl on the Arduino, so that stays with the hardware and it can accept G-code generated from anything.
Gcode in the 3D printer (or CNC etc) masks the interal workings of the device (turns/mm stuff, postive end stop), yes.
However most slicers need to know much of the printer anyhow in order to generate a good Gcode. F.eks. "retract head slightly and the filament when moving to another section" Here the slicer generates several lines of Gcode to do something that should be internal. Also the slicer needs to know which dialect of Gcode the printer can cope with. (In fact I know of at least two equally used modes of comments - one where the line starting with # is a comment and one where enclosing text in round brackts is a comment. So much for Gcode standard....)
On the other hand when spooling a print of an SD card, you can adjust some running parameters (like the speed) on the fly, as these are below the Gcode layer. Well, may be that could be done with a lower-level software, too.
I notice that programs like Mach3 which control the steppers directly also take Gcode as the input from some other program.
But the biggest motivator is probably TRADITION. "because that is how we always have done it".
Ok, i just want to describe more exactly why i do Not want to use a PC for my Project. I want to Build a machine which does some 3-dimensional cnc-tasks. The special situation is that it must run without a pc because it should be very simple and portable. At the moment I can't describe it more detailed. The hardware would consist of three stepper-axis with the proper stepper drivers. There are no special encoder signals which must be interpreted in real-time and the whole package of numbers could come from a single file, which maybe would be relatively big so that it would be a good idea to load it from a sd card or an external flash chip. This file must be processed in a way that the movements compensate the acceleration of the steppers etc., like e.g. Mach3 does. I didn't find a way to dump the output of Mach3 into a file, because that would be a quite clever solution for my idea. Therefore I am searching for another alternative way. Any ideas maybe somebody knows how to export/dump the Mach3 signal?
I don't know Mach 3 and I'm not sure where in the chain of things you might capture the Mach 3 output and it may be quite impractical. In theory, however, it sounds like a good idea.
One thing you must bear in mind is that Mach 3 (and Slic3r as someone else mentioned) needs to know a lot about your hardware. The arrangement of steps and accelerations is very unlikely to be portable from one CNC machine to another even though the same G Code can be used to produce the correct movements on any machine.
I understand why you want your Arduino device to run independently of a PC. However a PC will need to be used to produce the G Code from CAD drawings in the first place. Therefore, at the preliminary stages it is also available for other purposes. You could, of course have several SD Cards each of which has the code (in whatever format) for producing a particular product.
There is a big element of "which came first, the hen or the egg?" about your project at this early stage - and that is not a criticism. But it does mean that you will have to make decisions about some part of it before you can make progress on other parts.
Maybe it would be wisest to make a project that is fully GRBL compatible. You have not told us what you want to do that would require modifying GRBL. Maybe what you want could be achieved by modifying the G Code?
Thank you so far. Of course a pc is needed to produce the g code. I use a cad program for the design and a cam program to produce the g code. So far so good. But now things go different than the standard: normally I would open th g code in mach3, which has the correct profile for my cnc machine. When I Hit the start-button, mach3 sends the commands to the motors. Now I want to use an arduino for sending this commands to the cnc motor drivers instead of Mach3 . as I mentioned, it would be bread to get a dump-file from the mach3 output, but there is no export-functionality ore something, and I don't kow how to get the commands into a file. That's the reason why I ask for such a possibility. So I see two different approaches: either there is a way to get this dump file- if anybody has an idea how to do that- or maybe there is an other milling software which is able to create such a file?
You could record the output from Mach3 using an arduino writing the inputs to an SD file. However that would be rather like an audio recording and would produce big files and take a long time.
The problem is recording the pulses. If you were somehow to time the pulses then you would only have to save the pulse duration.
I can't see any practical way of doing what you want apart from the traditional way. There are reasons why everybody does it like they do.
The arduino IDE compiles C code, and that is what you should learn.
I'm aware of some "Graphical" "G" languages for a PC which you should read as though they are a flow chart for what you'll want your Arduino C code to do. I think that you'll be looking at lots of examples and the reference section here as it is time to learn a programming language.
I think GRBL uses most of the MCU memory so adding a SD card read routine will probably not fit in the memory (not to mention the other problems you may have).
Can you just have another arduino with SD card and a button(s) and knock up a simple program to read a file and send it over serial to the GRBL arduino (obeying xon/xoff handshaking).
A nano/pro mini would probably be more than enough and after adding an SD card and a couple of buttons would take up no more space than an UNO.
Yes, i also thought about that solution, but there is one other issue speaking against this solution: the final goal of my project leads in a commercial product, and Grbl is not licensed for that at the moment, if I am right?
Hahi:
the final goal of my project leads in a commercial product, and Grbl is not licensed for that at the moment, if I am right?
GRBL(tm) is free software distributed under the terms of the MIT License
reproduced below. GRBL may be used for any purpose, including commercial
purposes, at absolutely no cost. No paperwork, no royalties, no GNU-like
"copyleft" restrictions, either. Just download it and use it