I've got the idea to convert a lathe to cnc. I guess I have several questions about the programming capabilities of a arduino.
is it really all in c/c++? I've seen some, with some sort of java.
Can programs be interrupted like? On cnc stuff there are E-stop buttons, to use when something bad is about to happen or has already happened. I don't know if the arduino has the ability to be running a program, then E-stop all the sudden? or maybe even pause for a second then resume?
Can the program be made to be something like Mach 3 or LinuxCnC?
What kind of skill level, in what programming language would it take to make a basic version of Mach 3 or Linux cnc? I'm talking something that will show current positions (live?) what line of code it's processing, some kind of line of code list... maybe a clickable e-stop button, pause, and start or can those somehow be linked to a keyboard?
An Uno can run Grbl g code interpreter. Grbl can handle 3 steppers, limit switches and various control signals (E Stop is a physical switch that immediately stops the machine) on a Grbl shield A Mega 2560 can take a Ramps board (among others) that is somewhat the same as the Grbl shield but more capable (5 steppers, heater drivers). The 2560 can run Marlin if you want machine control with G code.
There is a ready-made Arduino CNC program called GRBL that probably does all that you want.
Or you could write your own program. But if you are a beginner there would be a steep and long learning curve - allow yourself 6 or 12 months if you have a great deal of spare time. More if you don't.
I wrote my own CNC system. A large part of the capability is in a Python program on my PC. The Arduino is just used to make the stepper motors move. And my program is nowhere near as comprehensive as Mach3 or LinuxCNC - but I have no need for all that stuff.
And I suspect that GRBL is not as comprehensive either - an Arduino does not have the computing resources of a PC. But many people seem to be happy with GRBL and Arduinos are the basis for many 3D printers.
Arduinos are programmed using the C++ language. The Arduino IDE is written in Java.
Arduinos have interrupt capabilities.
If you do feel like taking on the job of writing your own program I suggest you start with the basics of Arduino programming by studying the examples that come with the Arduino IDE. And there are dozens of on-line tutorials. You may be interested in Planning and Implementing a Program although it was not written for a complete beginner.
The Arduino IDE is in java. Arduino code itself is in C++.
The ardiono programming environment doesn't really have interrupts in the sense that you want. I mean - it does have them - but they aren't for the job that you want.
Instead, the programming environment has a single function named loop(), which gets called several thousand times a second. This function has the job of deciding "ok, what do I need to do right now", and doing it. Things that take time are prigrammed up by storing some state in a variable and having loop look at that state, checking the current time and other inputs, and deciding what to do.
Thus:
boolean emergency_stop = false;
void loop() {
if(emergency_stop) {
return; /// do nothing
}
else if(digitalRead(stopButton)==LOW) {
shut_down_everything(); // this function needs to be written
emergency_stop = true;
return;
}
// otherwise, proceed with the normal operations
}
This type of pattern will halt everything if the stop button is pressed and stay halted until the board is reset, provided that the "proceed with normal operations" doesn't "block" by using blocking I/O functions or using delay().