The Grbl source code is freely available, and it would presumably be possible to strip out the G-code interpretation and port to a PC application (as @Robin2 has been suggesting) - in fact, following this discussion, I'm now wondering about doing exactly that!
I've been considering adding a sensor input to the business end of my putative 3-axis machine (I doesn't mill yet, just draws in 2D, but that's part of the development path). So, in my case, it also makes sense to remove the clutter from the Arduino (yes, Robin2, I'm starting to be converted now :D).
As software engineering is my main job, and has been for the last 37 years, I'm much more inclined to hack things that way rather than get to grips with memory limits, interrupts, timing etc. when pushing the Arduino to do too much. Another project for the list beckons .......
For anyone that may be interested I made a start at writing a JRuby program to convert GCode to numbers for an Arduino but haven't touched it for a year. The code is attached as well as a test GCode file that I seem to have created using Slic3r.
The JRuby code isn't finished but it may give some ideas. I haven't tested it right now so I'm just guessing that I left in a runnable condition. It does run.
I can't immediately remember exactly what was the basis I used for the Arduino numbers - but it was something like the total number of counts for a move and the numbers of counts between each stepper move for 4? steppers.
Assuming you have JRuby on your PC my program should work with jruby Gcode1.rb ShortBoxTest.code and it will produce an output text file called ShortBoxTest.acode The program was written on a Ubuntu PC but it should work on any operating system.
It should be fairly easy to convert the JRuby code to Python.
I know I'm bringing up a dead thread but I am working on something with similar requirements. I have 4 steppers that control platforms rotation, each platform is a concentric ring inside of one another so that all 4 of them can be rotated back and forth independently of one another. The rings need to spin slowly in a coordinated sequence that I create and put on a performance of seemingly random but choreographed moves.
Using an arduino running teacup firmware and a serial terminal I send a text file of my desired moves to the arduino and that controls the motors via microstep drivers. The text file simply contains lines of code that look like:
"
G1 X10 Y10
G1 Z10 E10
G1 X5 Y5 Z5 E5
and so on...
"
Using cnc method as opposed to accelstepper commands has proven to be incredibly useful when applying it to my needs.
My problem is that this requires a computer running a serial terminal to send the gcode and that is not really practical for the final needs of my project, which is desired to be plug and play and capable of repeating the script indefinitely every time it reaches the end of the commands shown above.
Is there any way I can store the gcode on the arduino and run it from there so that it wont require a computer?
Sure. Use the Progmem feature. This allows you to store an array in the 32K Flash/Programstore. Only hassle is that you need to write it as part of your program as one long prog_uchar Motion[] PROGMEM = {"G1 X10 Y10;G1 Z10 E10;G1 X5 Y5 Z5 E5; .... (here I've used the ";" as the newlinecharacter.
You can split your program into several files, so one file only holds this progmem defenition.
At this time it may occur to you that you are using 10 bytes to store two ints. So I would throw away all the Gcode interpretation and just store the XYZE values in a list of ints. Yes, the Gcode allows for floats, but you can just scale it up by (say) 10 and then only store it in inst which are tenths of millimitere. (int limits you to +/- 32000). Or you can define your own "language" and really compress/save bytes.
Then you can go sophisticated and transfer from serial port to EEprom (which though only holds 1K) so you do not need to reprogarm. Or go the whole hog and implement you falshprogramming - but that is far beyond my skills, too
ColinPoly:
Is there any way I can store the gcode on the arduino and run it from there so that it wont require a computer?
I assume you want to continue using teacup if possible?
Perhaps it has the ability to read data from an SD card attached to the Arduino?
Have you used Google to search for info about teacup - you are unlikely to get much info on this Forum. I think teacup is used for 3D printing so the RepRap forum may have useful info.
Of course if you are happy to abandon teacup and write your own code we will try to help.
Msquare:
Wow okay great I clearly have a lot of research to do before I just start asking questions all willy nilly but a few just to narrow the scope a little i wanted to mention a few things.
First is that while I am somewhat of a perfectionist and would love to go hard and make this an elegant solution on the code aspect, I am not a coder and I just want something simple and reliable and I need to write it as fast as possible. I need to be finished in about a week (Sept 5) and its not flexible. That said, I probably will go with your first suggestion because it sounds easy for what I need.
The Teacup firmware as is now takes up 17K so the remainder can go to this file(s). How do I incorporate that new file I make into teacup? How do I tell it to repeat at the end of steps? This was actually referred to before I finished my post..
To Robin2's post:
I have finally worked out the details of the speed and timing of the motors within the teacup firmware, and while I still am using a serial program, just having the motors do what I want and at the noise level I want right now is kind of pushing me to stay with teacup. The fact that the movements are so easiy called upon also makes it desireable. I will hit up the reprap forums, thank you for the tip.
I've spent some time developing on teacup and other printer firmwares.
Teacup does not seem to support SD card, as that would be an easy way to inject G-code commands.
The next easiest is to inject characters in the main () function (file mendel.c). Currently it looks like this:
// if queue is full, no point in reading chars- host will just have to wait
if ((serial_rxchars() != 0) && (queue_full() == 0)) {
uint8_t c = serial_popchar();
gcode_parse_char(c);
}
if you add something like the following psuedocode :
if queue is not full
c = get next char from my buffer at next_ptr
gcode_parse_char (c)
next_ptr ++
if next_ptr end of my buffer
set next_ptr to 0
endif
endif
it will repeatedly run the built-in G-code commands.
You can store a "script" of G-code commands as a simple progmem array something like
ColinPoly:
is kind of pushing me to stay with teacup.
Since teacup has built-in code to take data from the serial port it may be possible to modify it so it could get that data from an SD card. The large SD Card data buffer may be a problem. If it worked other teacup users might appreciate your efforts.
SD Cards can be used without the FAT file system (and its large data buffer) but then you are into a very non-standard system.
Robin2:
Since teacup has built-in code to take data from the serial port it may be possible to modify it so it could get that data from an SD card. The large SD Card data buffer may be a problem. If it worked other teacup users might appreciate your efforts.
SD Cards can be used without the FAT file system (and its large data buffer) but then you are into a very non-standard system.
Hani,
I read some of the quotes here, I think , most software mentioned here are for the Reprap 3D printer which has a specific hardwares ( eg. Mainly Arduino MEGA 2560 +RAMPS 1.4+ A4988 stepper motor driver etc..), however, if you put your own stepper motor drivers directly built around Arduino controller, you may need to redirect the pins reference in the libraries written for the original reprap and reassign them to the pins where your stepper motor driver are in.Unfortunately ... I don't know where are they located.. Do a favor to let me know if you find please....! But I think this hint.. Will put you on the way when asking for assistance to build your own printer... Cheers. And good luck.
I have the same problem. I want to make a robot controlled by Arduino which has X and Y axes and executes a certain G-code but without being connected to a PC. Some solution for this problem? Is there a possibility to save the G-code / instructions from GBRL to an SD card or somewhere and Arduino execute it? Thank you!
bogdan90:
Is there a possibility to save the G-code / instructions from GBRL to an SD card or somewhere and Arduino execute it? Thank you!
Is there a possibility that you could study how GRBL works before asking a question? And if you are going to add your question to an existing Thread you should read ALL of the Thread very carefully before doing so.
GRBL does not produce GCode instructions, it consumes them. And it can take them from a SDCard. And GRBL is what an Arduino uses to execute GCode.