0% found this document useful (0 votes)
136 views11 pages

Modbus Mach3 To Arduinono Additional Hardware Brai

This document describes how to connect an Arduino directly to Mach3 without any additional hardware using a UART connection to read the state of an input pin on the Arduino. The setup involves uploading code to the Arduino that will respond to Modbus read requests from Mach3 by returning a value of 0 or 1 depending on the state of the input pin, allowing Mach3 to monitor the pin. Configuration in both Mach3 and a Modbus tester application is demonstrated to establish basic two-way communication between the CNC controller and microcontroller.

Uploaded by

Ricardo Morales
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
136 views11 pages

Modbus Mach3 To Arduinono Additional Hardware Brai

This document describes how to connect an Arduino directly to Mach3 without any additional hardware using a UART connection to read the state of an input pin on the Arduino. The setup involves uploading code to the Arduino that will respond to Modbus read requests from Mach3 by returning a value of 0 or 1 depending on the state of the input pin, allowing Mach3 to monitor the pin. Configuration in both Mach3 and a Modbus tester application is demonstrated to establish basic two-way communication between the CNC controller and microcontroller.

Uploaded by

Ricardo Morales
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

instructables

Modbus Mach3 to Arduino(no Additional Hardware) + Brain Setup

by VladoM

I will describe here how to connect arduino directly to In this case the standard Usb cable connecting pc
mach3 without any additional hardware. and arduino will do.

This will not use any modbus library it is just proof of But you can buy USB to rs485 adapter and connect
working. You will end up with ability of mach3 to read to rx tx lines and it should be basicaly the same think.
input pin on arduino. But if this will work for you then
adding full modbus library for proper comunications On the image is the whole setup. Arduino connected
shouldnt be any problem. to PC + one led but you dont need the LED (it is just
indicator so i know what information should be send
Small think about modbus back from arduino) and cable so you can ground a pin
on arduino. Led should have resistor in series, i just
Modbus is software protocol not hardware, so you coudnt be bothered and the led suvived.
can use it not only ower rs232 or rs485 but also let
say uart usart. Doesnt matter the amount of On left side of image is the USB to rs485 adapter
connections the hardware protocol uses, basicaly it (you dont need that). i just wanted to add it in case
boils down to one comunication line for half duplpex you wanted to know what the one i have looks like.
and two for full duplex. and it works fine. i was trying it with some rs485
hardware.
The comunication of mach3 with arduino will be done
using uart. so rx tx lines.

Modbus Mach3 to Arduino(no Additional Hardware) + Brain Setup: Page 1


Step 1: Owerview of Concept

I did my test with arduino mini pro.

This was the inspiration for my test and the code is from this page:
http://www.machsupport.com/forum/index.php/topic,2...

First software for arduino:

The whole think is very simle, arduino recives int his case any 8 bites and replies with

01 04 02 00 00 78 f0

or

01 04 02 00 01 b9 30

In real comunication these packets are modbus reply for "01 04 00 00 00 01 31 ca" question. which is read input
register question.

So we will send request from mach3 to read input register and arduino replyes with data containing 1 or 0. So
thisway we can read state of inputpin on arduino.

quick look at the modbus package:

let say thisone: 01 04 02 00 00 78 f0

01 is addres of slave device


04 is information that we are going to read input register
02 00 00 lets simplyfy this for the data information. ( but basicaly it is N*8bits of data in this case so
2 bit containing 00 00)
78 f0 is just checksum

so mach3 will read from thees returned packets

01 04 02 00 00 78 f0 returned ingormation is 0

and from 01 04 02 00 01 b9 30 returned ingormation is 1

Modbus Mach3 to Arduino(no Additional Hardware) + Brain Setup: Page 2


Step 2: The Arduino Site Step 1

We will need some Modbus tester : Attached image is from the tester it will automaticaly
KMtronic_ModBus_Tester show you port on which is arduino connected if you
have more ports connect and disconnect arduino you
http://info.kmtronic.com/kmtronic-modbus-relays.ht... will see which port dissapear and then appeard in the
list again.
We upload the code at the bottom of this page to the
arduino. set comminication speed for 9600 as this is what we

use at the mmnt in the serial comunication in arduino //just an led information if input for which we test is
program. high or low

and to comunicate with arduino you need to click if ( digitalRead(pin) == 0 ){


Open. this will connect you to device and allow for
sending and recieving information. When the Port is digitalWrite(pinLED, HIGH);
open no other program can communicate to arduino
you will need to CLOSE it first. } else {

This code is basicaly copy form the page i used as digitalWrite(pinLED, LOW);
inspiration. i just added the LED. because i needed
small help with testing. and changed pins. }

int pin = 4; if ( Serial.available() == 8 ) { // read ModBus


command from Mach3
int pinLED = 5;
// in this example we only read, don't check anything
int in_buffer[8]; // receiving buffer
for (int i=0; i < 8; i++) in_buffer[ i ] = Serial.read(); //
int reply_1[] ={0x01, 0x04, 0x02, 0x00, 0x01, 0x78, Read Input PIN and reply with 0 or 1
0xF0};
// Reply is inverted because PIN default state is HIGH
int reply_0[] ={0x01, 0x04, 0x02, 0x00, 0x00, 0xB9, and we connect to GND
0x30};
if ( digitalRead(pin) == 0 ) {
void setup() {
for (int i=0; i < 7; i++) Serial.write(reply_1[ i ]);
Serial.begin(9600); // Init serial communication
}else{
pinMode(pin, INPUT); // Set pin to input
for (int i=0; i < 7; i++) Serial.write(reply_0[ i] );
pinMode(pinLED, OUTPUT); // Set pin to input
}
digitalWrite(pin, HIGH); // Turn on pullup resistor
}
}
}
void loop() {

Modbus Mach3 to Arduino(no Additional Hardware) + Brain Setup: Page 3


Step 3: The Arduino Side Step 2

Now we send request command to arduino 01 04 00 00 00 01 this is what mach3 will do.

We could send any 8 bytes to arduino as you can see from program , it is just to properly answer so arduino
doesnt care for question in this case.

also note that we send this : 01 04 00 00 00 01. tha last 2 bytes which is checksum will be automaticaly added by
the Mddbus tester program.

On the image is possible to see that i sent twice the 01 04 00 00 00 01 command to arduino.

first in red rectangle:

when D4 pin is not connected to anything (is sitting at 5v)

0-TX 01 04 00 00 00 01 31 ca is what arduino recieved

and replied with the 1-Rx....... returning 0 in the data

then the green rectangle

when i connected D4 to ground, my LED is on now

and reply is 3-RX...... returning 1 in data

if this works for you, then the arduino side is done. as we can see arduino replying to questions sent from the
tester.

the last two images are the arduino setup when set to reply 0 and then set to reply 1.

Modbus Mach3 to Arduino(no Additional Hardware) + Brain Setup: Page 4


Step 4: Mach3 Side 1

First in your modbus tester press CLOSE button. Otherwise Mach3 will be unable to communicate with arduino (it
will not be able comunicate on already OPEN COM port).

go to mach3 top menu-> config -> ports and pins

tick both options as seen on image.

you will need restart Mach3 for this change to be applied.

Modbus Mach3 to Arduino(no Additional Hardware) + Brain Setup: Page 5


Step 5: Mach3 Side 2

In Mach 3 go to top menu->setup serial modbus error


controll and in popup window press test modbus.
Now you can basicaly set rest of the data as on the
Mach3 will not add automaticaly any choice for Port image
Num.: but this will be the same port you have seen in
the modbus tester application so if it was showing when you press Read button: in the big data window
Com5 write in Port Num.: 5. on the right it should show 0000.

set comunication speed for 9600baud then when you coonect on arduino D4 to ground and
pres Read button in mach3 again it should display
As usualy you need to pres OPEN to allow for 0001.
communication on the com port.
now you have succesfully established comunication
if there will be something wrong Status: message will with mach.
show you. otherwise there should be written : No

Step 6: If Any Trouble

I am using a software called free-serial-analyser. arduino replyes.

this will show you what is sent or recieved on given you can see arduino replying by 0 and then 1. that is
comport. what you should see if you done the test in previous
step.
look at the images to see how i set the viewer.
if you are missing some data you can quickly here
The last image shows you the window where you can identyfiy if mach is sending something or if arduino is
check the communication. replying.

you can see what data are sent from mach and what

Modbus Mach3 to Arduino(no Additional Hardware) + Brain Setup: Page 6


Modbus Mach3 to Arduino(no Additional Hardware) + Brain Setup: Page 7
Step 7: Real Use of the Comunication

Set the proper com port (i am bit messy on the arduino to read the input register.
images sometimes i have 4 sometimes 5 but if you
dont unplug and plug in other devices the port will be if all is set correctly and you pressed apply button the
the same) on which your arduino is connected and fill arduino rx tx led should be constantly blinking as
the data as per image. mach is sennding the requests in 50ms intervals
(refresh column)
this config will set CFG #0 be sending request to

Modbus Mach3 to Arduino(no Additional Hardware) + Brain Setup: Page 8


Step 8: Setup Brain 1

Go to top menu->operator-->brain editor. "input functionality"

it will asks you for the bain name so give it some. in the window press modbus and do the setup as per
then it will open the editor. image.

on my image it is all filed in already but: you are just setting for the fact that you are using
modbus plugin and and the CFG #0 which we set in
you will press + previous step.

and winndow add input will popup. where we add the

Step 9: Setup Brain 2

now select the first added rectangle and press + again

it will give you different window so just press ok for no operation

Modbus Mach3 to Arduino(no Additional Hardware) + Brain Setup: Page 9


Step 10: Setup Brain 3

Now select the second added rectangle and press the upside down T this will add the functionality what should
happend when the signal recieved is 1.

simple way is to just add button press and start cycle.

and now when 1 is recieved from arduino it will start your program.

not yet but it will..

you can save your brain now.

Step 11: Setup Brain 4

Go to the top menu ->brain control

select your brain and press enabled and hit ok.

not sure but you might need restart the mach3

then come back here again select your brain and press view brain.

Modbus Mach3 to Arduino(no Additional Hardware) + Brain Setup: Page 10


Step 12: Setup Brain 5

You should be able to see the response of the brain when D4 on ardino is connected to ground or not.

TADAAAA functional mach3 comunication which acts as remote Cycle Start button.

hope you liked it.

Modbus Mach3 to Arduino(no Additional Hardware) + Brain Setup: Page 11

You might also like