Hello Guest it is April 16, 2024, 11:49:10 PM

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

0 Members and 1 Guest are viewing this topic.

Arduino - Mach 3 - Gcode M6 T0101
« on: March 25, 2022, 10:01:41 AM »
Hi there,

I have read the posts I could find on the forums concerning arduino and mach 3 and connecting this using modbus.

http://www.machsupport.com/forum/index.php/topic,22982.0.html

This post from Zafar has been really helpful in connecting arduino as a slave to mach3 and using it with 2 x potentiometers for FRO and Spindle override

I want to do something similar with an Automatic Tool Changer.

the only thing I need is it should send an integer value between 1 to 12 to the arduino every time it encounters the M6 Gcode and based on what tool was selected.

ex. M6 T0101 - should send "1" to the arduino.

I have no idea how to modify the code to do this. Is there anyone who has done this before??
Re: Arduino - Mach 3 - Gcode M6 T0101
« Reply #1 on: March 25, 2022, 10:10:10 AM »
Hi,
You'll have to add new fields to the modbus configuration in setup serial modbus control menu. Perhaps use a userdro to hold the new tool number and then use this dro in the brains. This all can be handled in the M6Start macro and a brain. Also the arduino sketch needs some additions to handle the new registers.

Zafar
« Last Edit: March 25, 2022, 10:15:00 AM by zafarsalam »
Re: Arduino - Mach 3 - Gcode M6 T0101
« Reply #2 on: March 25, 2022, 10:18:46 AM »
Hi Zafar,

Thank you for the quick reply.

The new fields that I add assume needs to be Output holding?

I have never made a userDRO before, I will watch a couple of youtube videos that might enlighten me.

I know how to make a brain based on your tutorial but have no idea what functions to use for this?

the m6start macro I could do. How do I change the arduino sketch to receive the inputs and can this still be done using the USB or do i need a RS232 to USB converter and use serial 1,2 or 3 on the arduino? I am completely lost.
Re: Arduino - Mach 3 - Gcode M6 T0101
« Reply #3 on: March 25, 2022, 10:29:39 AM »
Also, I am doing this on Mach3 turn and not in mill. This is a 12 tool - tool changer turret I built.
Re: Arduino - Mach 3 - Gcode M6 T0101
« Reply #4 on: March 25, 2022, 10:42:58 AM »
In the M6Start macro you can use the vbcript function GetSelectedTool() and save it in a userdro.
setuserdro(2001)=getselectedtool()

In the arduino sketch 40 regs are already assigned while we are using just two of them regs[0] and regs[1] for reading analog inputs on pins A0 and A1. These regs are passed on to Mach3 brain as input-holding.

Now you'll have to define new config as output-holding and assign an address of 10 and number of registers 1. In the brain you add the new rung with userdro as the input and the modbus output register as the terminal.

The value of userdro(2001) will reflect in the arduino as regs[10].

I hope you got some hold of this confusing technique.

Zafar

Hi Zafar,

Thank you for the quick reply.

The new fields that I add assume needs to be Output holding?

I have never made a userDRO before, I will watch a couple of youtube videos that might enlighten me.

I know how to make a brain based on your tutorial but have no idea what functions to use for this?

the m6start macro I could do. How do I change the arduino sketch to receive the inputs and can this still be done using the USB or do i need a RS232 to USB converter and use serial 1,2 or 3 on the arduino? I am completely lost.
« Last Edit: March 25, 2022, 10:44:40 AM by zafarsalam »
Re: Arduino - Mach 3 - Gcode M6 T0101
« Reply #5 on: March 25, 2022, 11:22:09 AM »
So to clarify just check my images if this is correct?

and then in the sketch:

enum {       
        MB_REG0,
        MB_REG1,
        MB_REG10,
        // line below is for holding registers.    'vinny'
        MB_REGS   = 40    /* total number of registers on slave */
};

I added MB_REG10, ? is that correct?

I'm struggling with the brain where you say modbus output register as the terminal:
enter the modbus adres to use. what number should i enter here?
the CFG# would be number 2 then?
and macro modbus emulation?

Re: Arduino - Mach 3 - Gcode M6 T0101
« Reply #6 on: March 25, 2022, 01:59:39 PM »
So I have watched a couple of videos. Creating the DRO was fairly easy

In the M6start macro this line: SetUserDRO(2001) = GetSelectedTool()
does not want to compile and i receive a type mismatch error.

I have no idea what to do further in the arduino Sketch?
Re: Arduino - Mach 3 - Gcode M6 T0101
« Reply #7 on: March 25, 2022, 02:29:41 PM »
So this is what I have so far and seems to compile fine:

'Variables

Dim OldTool      As Integer
Dim NewTool      As Integer


'*************************************************************
'                     Main Sub
'*************************************************************


Sub Main()   


   
  'Define variables

  OldTool = GetCurrentTool()
  NewTool = GetSelectedTool()

   
  Message("Tool Change Initiated Old Tool #" & OldTool &" New Tool #" & NewTool)


  'If tools are the same then exit
 
  If NewTool = OldTool Then       
    Message("New Tool and Old Tool are Same - No Action Requested")
    Exit Sub
  End If
 
  SetUserDRO(2001) = GetSelectedTool()

  Message("**********  Tool Change Start ********************")

   'Move The Toolchanger away from the Spindle - I stiill need to save the old positions and continue machining operation from there
   
   Code "G0 Z200"

End Sub
= tool
Re: Arduino - Mach 3 - Gcode M6 T0101
« Reply #8 on: March 25, 2022, 03:44:07 PM »
So this is what I have now:


  'Define some constants
 
    MyDRO = 2001   
   
  'Set MyDRO to GetSelectedTool()

   SetUserDRO(MyDRO, GetSelectedTool())
   
   'SetUserDRO(MyDRO, "2") 'this was just to test if it works correctly when I run the script
   
   'Get current value of MyDRO
   MyDROVal = GetUserDRO(MyDRO)
   
  'Define variables

  Message("Tool Change Started. Tool: " & MyDROVal & " selected")

   'Move The Toolchanger away from the Spindle - I still need to pause then save the old positions and continue machining operation from there
   
   Code "G0 Z200"
   
It compiles fine and it sets my UserDRO to the number I select when testing it through the VB script editor. But If I run G-codes with toolchanges it does not change the userDRO value, neither does it change if I just type M6 T0202 in the command line? What did I do wrong?
Re: Arduino - Mach 3 - Gcode M6 T0101
« Reply #9 on: March 25, 2022, 03:58:33 PM »
I had to uncheck the box "ignore tool change" in the general config and check the box "Auto toolchanger"
Now the macro is working fine along with userDRO of 2001. How will I test the brain I made to see if it is working the way it should?
Now it seems it is just the arduino sketch left to modify? So how do I do this and how do I add my toolchanger code to it? without either one interfering with the other?