I'm afraid I'm still a newbie when it comes to Arduinos. I've done some simple example projects so this is my first undertaking without much guidance.
Background for those who don't know what I'm talking about: I've build a CNC gantry to control a plasma cutter. The one thing my current setup cannot do is control the Z-axis which holds the cutting torch. Most people have the same problem so one solution is to spend hundreds of dollars more on a plug-and-play torch height controller (THC). The premise of the THC is to locate (zero) the work piece, then back the torch off a few millimters to pierce, then back towards the part a smudge to cut. More advanced digital models can measure the voltage between the torch and work piece so if the height of the work piece is uneven, the THC can adjust accordingly. Here's a GIF of a THC which is extremely exaggerated:
THC sketches are out there but they're "out there" for me. I just want to start simple then get advanced.
The procedure is simple. My Mach3 (plasma program) is setup with outputs to another breakout boards in my panel. It's capable of 5V discrete I/O which I've already tested between the Arduino. So, once I tell the program to start cutting, Mach3 will output a signal to start the process (int ready_THC), the Arduino will do it's THC readiness motion, and then the Arduino will output another signal to a relay to trigger the plasma machine to start cutting. Then my plasma cutter has an output to say it has struck an arc (the bright light in the GIF) which Mach3 can see to start motion on the gantry.
Down below is my setup and program. It's a mess.
The Z axis plate traverses up and down on the rails. This plate contacts the upper and lower limit switches. The torch holder has a limit switch on the back side (seen in the next picture) which is always high since the holder is forcing down on the switch. Once the torch contacts the work piece, it will lift off the switch which tells the Arduino "I've found the workpiece". Then, I do some programming to compensate the distance it took to lift the switch and extra compensating to find how far the torch tip needs to be for pierce height and then cut height (I know that'll be a trial and error process on how many times I tell the stepper to step).
int dirpin = 2; //stepper direction: HIGH=DOWN, LOW=UP
int steppin = 3;
int z_low_ls = 12; //Lower Z-axis limit switch
int z_high_ls = 13; //Upper Z-axis limit switch
int zero_torch = 6; //Zero torch on workpiece. HIGH: no contact with workpiece. LOW: Zero'd torch on workpiece
int ready_thc = 8; //LOW: no signal to start cutting. HIGH: begin cut process
int s_ready_thc = 0; //Condition
int s_zero_torch = 0; //Condition
int s_z_high_ls = 0; //Condition
int s_z_low_ls = 0; //Condition
//Setup the I/O
void setup()
{
pinMode(dirpin, OUTPUT);
pinMode(steppin, OUTPUT);
pinMode(z_low_ls, INPUT);
pinMode(z_high_ls, INPUT);
pinMode(zero_torch, INPUT);
pinMode(ready_thc, INPUT);
}
//Move the Z-axis down
void move_down()
{
{
digitalWrite(dirpin, HIGH);
digitalWrite(steppin, LOW);
digitalWrite(steppin, HIGH);
delayMicroseconds(200);
}
}
//Move the Z-axis up
void move_up()
{
{
digitalWrite(dirpin, LOW);
digitalWrite(steppin, LOW);
digitalWrite(steppin, HIGH);
delayMicroseconds(200);
}
}
//If Mach3 hasn't sent a "start cut" signal, return the torch to the top "home position"
void home_pos()
{
s_z_high_ls=digitalRead(z_high_ls);
if (s_z_high_ls == HIGH)
{
move_up();
}
}
//Once Mach3 gets "start cut" signal, zero the torch to the workpiece
void zero_workpiece()
{
s_zero_torch=digitalRead(zero_torch);
if (s_zero_torch == HIGH)
{
move_down();
}
}
/*
void pierce_height()
{
for (int i=0; i<4000; i++)
{
digitalWrite(dirpin, LOW);
digitalWrite(steppin, LOW);
digitalWrite(steppin, HIGH);
delayMicroseconds(500);
}
}
*/
//Program loop
void loop()
{
s_ready_thc=digitalRead(ready_thc);
s_z_high_ls=digitalRead(z_high_ls);
s_zero_torch=digitalRead(zero_torch);
if (s_ready_thc == LOW) //If the THC hasn't received a signal from Mach3, go ahead and home by traversing the Z axis to the top until the Z upper limit switch is HIGH
{
home_pos();
}
while (s_ready_thc != LOW); //If the THC has received a signal from Mach3, start the cut process
{
zero_workpiece();
}
}
The furthest I can get is if there isn't a signal from the Mach3 (ready_THC == LOW), go to home_pos. When I push the z_high_ls as if the Z-axis has reached the top, the stepper does stop but continues if I let go (makes sense to me so far). However, when I set the ready_THC, I don't get a response. The stepper continues to turn.
I just want to take this one step at a time. I've tried switches and boolean but I'm having trouble understanding the nature of the programming loop as to why it's not responding.
Nudges in the right direction would be appreciated. I know my buddy is working on the same thing so I'm willing to bet a bunch of amateur Arduinoists with plasma cutters in need of THC's will appreciate the same thing.