Hello Guest it is July 15, 2024, 11:11:47 PM

Author Topic: Write a Integer to Arduino using the M6Start  (Read 9754 times)

0 Members and 1 Guest are viewing this topic.

Write a Integer to Arduino using the M6Start
« on: March 23, 2022, 01:34:55 AM »
Hi There,

I have built an arduino-based tool changer for a conventional 2-axis turning lathe machine. It works by receiving a input of 1 to 12 through either the serial monitor or a bluetooth device.

I would like to be able to use this with Mach 3. If I have a tool change in the G-Codes ex. M6 T0101 it should send "1" to the arduino and run the code to do the change.

I have read that this can be done by building a brain in mach 3 using modbus.

Is there anyone who rather has a M6Start Macro that might just do this?

Or anyone that could point me in the right direction?

Thank you

Offline TPS

*
  •  2,508 2,508
Re: Write a Integer to Arduino using the M6Start
« Reply #1 on: March 23, 2022, 06:54:14 AM »
brains will not be the way you are looking for. if your Arduino wil accept ModBus you can find a lot about modbus
here on the forum. also a complete sample for modbus arduino communication is in the modbus aeria.

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

for a simple serial output you can use VBScript.

from the manual:

SendSerial
Sub SendSerial(Data As String)
This function send the String Data to the serial port specified in the Config-
>GeneralConfig serial port configuration. This provides transmit-only capability, at any
supported BAUD rate.
Arguments:
String message to be sent to configured serial device
Return Value:
None
Example:
‘ Send “Hello, world!” to serial device
SendSerial(“Hello, world!” & chr(10) & char(13))
See also:
« Last Edit: March 23, 2022, 06:57:32 AM by TPS »
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: Write a Integer to Arduino using the M6Start
« Reply #2 on: March 23, 2022, 11:10:06 AM »
Thank you so much! I'm going try this and see how it goes.
Re: Write a Integer to Arduino using the M6Start
« Reply #3 on: March 23, 2022, 11:56:30 AM »
SendSerial(“Hello, world!” & chr(10) & char(13))

I see the above would work. Except for in the place of Hello World I would need a variable
This variable should be the data that was entered into the command line (If that is what it's named?)
or from the G-codes whenever it encounters the M6 code for a toolchange.

I'm not sure how to code this?

the sequence should be something like:

Sub Main()

        Dim Tool_Change As String

        'for the first tool:
        'how do you grab the data from the g-code after m6 or from the command line??

    If the command line value = M6 T0101 Then

        ReadLine(Tool_Change) 'Or here the function for whatever is used for the command line??
       
        SendSerial("1") 'send the number 1 to the arduino

    end if

        'for the second tool:

    If the command line value = M6 T0202 Then

        ReadLine(Tool_Change) 'Or here the function for whatever is used for the command line??
       
        SendSerial("2") 'send the number 2 to the arduino

    end if

         'for the third tool:

   If the command line value = M6 T0303 Then

        ReadLine(Tool_Change) 'Or here the function for whatever is used for the command line??
       
        SendSerial("3") 'send the number 3 to the arduino

    end if
       
and so on for the rest of the tools or maybe later on an array for all 12 tools, just as simple as possible as the arduino already does everything it just needs that number from the serial.

    End Sub

« Last Edit: March 23, 2022, 12:00:18 PM by TheSuperior »

Offline TPS

*
  •  2,508 2,508
Re: Write a Integer to Arduino using the M6Start
« Reply #4 on: March 23, 2022, 01:28:40 PM »
i think a good start would be to studdy some manuals:

https://www.machsupport.com/wp-content/uploads/2013/02/Mach3_V3.x_Macro_Prog_Ref.pdf
https://www.machsupport.com/wp-content/uploads/2013/02/VBScript_Commands.pdf

a simple search in the forum for M6Start macro will bring up a lot of sample script's and a lot of
samples to copy and paste.
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.

Offline BR549

*
  •  6,965 6,965
Re: Write a Integer to Arduino using the M6Start
« Reply #5 on: March 23, 2022, 06:51:29 PM »
TPS gave you some GOOD advice. Everything you need to know to do what you want to do is in that manual. The key words are current tool and selected tool then send serial (;-)

(;-) TP
Re: Write a Integer to Arduino using the M6Start
« Reply #6 on: March 24, 2022, 11:04:50 AM »
Thank you TPS. Will see how far I get.