Hello Guest it is March 29, 2024, 09:31:02 AM

Author Topic: Arduino - Mach 3 - Gcode M6 T0101  (Read 4445 times)

0 Members and 1 Guest are viewing this topic.

Re: Arduino - Mach 3 - Gcode M6 T0101
« Reply #20 on: March 27, 2022, 03:14:10 AM »
Do you think the code inside of the setup will matter? the Delay() ? As those will only run with the initial startup? Also what is the reason for the program not to have the Delay() functions? how does this affect Mach3 exactly?

Furthermore if I figured out how to rewrite everything using timers? What else should I do in order to integrate this with your code?
Re: Arduino - Mach 3 - Gcode M6 T0101
« Reply #21 on: March 27, 2022, 03:27:40 AM »
During a delay the modbus communication will stop. Since you don’t need to send any signals to mach3 during the stepper movement so it is safe to use it.
Re: Arduino - Mach 3 - Gcode M6 T0101
« Reply #22 on: March 27, 2022, 07:19:54 AM »
So it only stops during the Delay() ? In that case it would not matter would it? As the arduino would wait for the serial Input? after that the Arduino executes the move completely independent of Mach3 and then continues again? I have added code in the m6tstart macro to move the tool changer away from the job, so the Arduino won't need to signal mach3 when it is done either as this will take some time to execute? after the change is done it can just run through the loop again and wait for the next command or tool change? Or am I completely wrong here? I feel I'm getting just so close yet so far. You have really been a great help, Thank you. I'm not sure what my next step is?
Re: Arduino - Mach 3 - Gcode M6 T0101
« Reply #23 on: March 27, 2022, 10:46:16 AM »
In the Arduino sketch you can do an if statement in the main loop. You can read the value of a register from Mach3 modbus or the state of a pin which can be connected to an output pin from Mach.

In the tool change macro you can either turn an output on and off to signal the arduino to start the tool change sequence. Or change the value of a user DRO which can be read in brains and then to modbus. Then you can do a while statement in the tool change macro which waits for the input from Arduino to finish the tool change macro.
Re: Arduino - Mach 3 - Gcode M6 T0101
« Reply #24 on: March 27, 2022, 02:27:47 PM »
I finally managed to rewrite the entire code without a single delay in it. Oky, let me see if I can follow, although I'd like to read the value of a register from Mach3 modbus? From value 1 to 12?  So then change the value in the user DRO which can be read in brains and then to modbus? Still I have no idea how to start writing that or incorporating it?

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: Arduino - Mach 3 - Gcode M6 T0101
« Reply #25 on: March 28, 2022, 12:05:15 PM »
might be interesting:

https://www.machsupport.com/forum/index.php?topic=1658.0

but the question is why using a arduino to control the ATC. IHMO there can be nothing on a ATC
what Mach3 can not control itselve via a VB Script.
« Last Edit: March 28, 2022, 12:07:16 PM by TPS »
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: Arduino - Mach 3 - Gcode M6 T0101
« Reply #26 on: March 28, 2022, 12:45:06 PM »
Thank you TPS. This seems as though it could be useful.
Re: Arduino - Mach 3 - Gcode M6 T0101
« Reply #27 on: March 28, 2022, 01:49:45 PM »
In the Arduino sketch you can do an if statement in the main loop. You can read the value of a register from Mach3 modbus or the state of a pin which can be connected to an output pin from Mach.

In the tool change macro you can either turn an output on and off to signal the arduino to start the tool change sequence. Or change the value of a user DRO which can be read in brains and then to modbus. Then you can do a while statement in the tool change macro which waits for the input from Arduino to finish the tool change macro.

So I'm trying to figure out how to do this,
in the m6start macro should i use sendserial() ?

Please help with what the if statement needs to contain?
In the sketch:

if (txenpin > 1) { // pin 0 & pin 1 are reserved for RX/TX
                Txenpin = txenpin; /* set global variable */
                pinMode(Txenpin, OUTPUT);
                digitalWrite(Txenpin, LOW);
        }

Do I have change these pins to use 18 and 19?

unsigned int Txenpin = 0;        /* Enable transmission pin, used on RS485 networks */

Then here is the code I use to capture the serial input. How do I modify this to capture what modbus sends or will it work as is?

void ReceiveData() {

  while (Serial.available()) {
    BlinkPattern(); 
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    }
  }

  if (readString.length() >0) {
    //Serial.println(readString);  //so you can see the captured string
    //int n;
    char carray[6]; //converting string to number
    readString.toCharArray(carray, sizeof(carray));
    Input = atoi(carray);
   
    readString="";
  }
 
}
Re: Arduino - Mach 3 - Gcode M6 T0101
« Reply #28 on: March 28, 2022, 02:12:37 PM »
another thing, as I'm using Arduino mega with a CNC shield mounted at the top. Won't this interfere ?

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: Arduino - Mach 3 - Gcode M6 T0101
« Reply #29 on: March 29, 2022, 02:18:02 AM »
the code of the posted example:

https://www.machsupport.com/forum/index.php?action=dlattach;topic=1658.0;attach=1174

will send a small string via SendFifo() witch is an undocumented Mach3 VB script function.
this string will contain: 

StartSign (Hex 1E) + toolnumber + CR (Hex 0D)

witch "gives" the Adrduino a minimum chance to check the received data for validity.
than it will wait for a response (Hex B6) to know that Arduino has "understand" the order.

sorry but can not "assist" on Arduino side.
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.