Intro: MACH3 4 Input 4 Output Simple Expansion
This is probably the simplest way how to expand your I/O.
I found this cheap very badly described 4 outputs and 4 descrete inputs board on internet.
this system uses 485 comunication so you will need some adapter for usb.
maybe somethink like this:
In this tutorial i am simplyfiing thinks. I assume you know how to work with the mach3 related components. if you need everithing in bigger detail i have one more modbus tutorial for modbus and arduino https://www.instructables.com/id/Modbus-Mach3-to-A... where is all the functionality explaind in bigger detail. and that should answer your questions for what i left out in this tutorial.
Step 1: Basic Setup
The board needs 12-15V you can power it by jack or like me in this case by VCC and GND terminals (black cables).
The white cables are the ones used for comunication (modbus). In my case they are kind of properly labeld at least the + and - lines are identified so that is what you go for on both sides A+ to A+ and B- to B-, althou i have on adapter written D+ and D-. No need to think about it too much. if your setup will not work you just switch between polarities. I read that sometimes the labels are just wrong.
Blue wire in the middle, that is just loop to change state of in this case input3 so we know that we realy read some input.
Board works on address 01 but it probably can be set differently. I will not go into this now, but i found some comments on sellers page so whoever likes and need address change this might help. i didnt tested t so no idea...
Set the address is: 01
00 06 40 00 00 01 5c 1b
on other place i found: XX needs to be substituted
01 06 00 02 00 XX 1b 0a
Set the address is: 02
00 06 40 00 00 02 1c 1a
Step 2: Quick Check
Using modbus testing program i sent 01 05 00 01 01 00 to the port on which the modbus adapter is (com5 in my case) and device on address 01 will replay(look at the image).
This 01 05 00 01 01 00 is used to turn ON relay 1 so you will see the led next to that relay light up. thisway you can test all the relays.
If the first relay is not ON you probably need swich the A+ B- lines.
in next slide are all codes but for example 01 05 00 02 01 00 will turn ON the realy 2.
Step 3: Comunication Codes
On the image are codes i found works for mach3 by testing in the mach3 Test Modbus window.
Step 4: Allow Modbus in Mach3
Turn on your modbus in mach3 otherwise the comunication will not work.
Just tick the modbus i/o and modbus plugin support boxes. (as on the image)
Also restart Mach3 at this point to enable this change.
Step 5: Relays (coils)
This image from mach3 (Test Modbus window) that specific setup will turn ON the third coil.
Also, you need to know your com port and boudrate will be 9600 bps for this board.
so: startC : 3 = third coil
Data window: write 100 (this is what the board is asking for 01 05 00 01 01 00)
select Coils tickbox
and press Write
this will make mach send this value:
01 05 00 01 01 00
to turn the relay OFF
into Data window: write 0
and press Write which sends:
01 05 00 01 00 00
Step 6: Analog Inputs (Discrete Inputs)
Note for reading inputs you need to read them all at once, or I just didnt found any other option. the board just doesnt want to return single input info.
This means the data returned will be 1,2,4,8 and additions of them if more pins are high at the same time.
On the picture you can see how mach3 read all 4 inputs and dispalys them in Data window. (note :The 3rd input is HIGH)
Step 7: So Lets Put This I/O to Work
This is setup for :
- cfg0 for coil1
- cfg1 for reading inputs
- cfg2 for coil 2 (i added it so you can see where is the 2 is set for targeting the second coil)
Step 8: Setting Outputs
Create brain like on the picture.
for now just the first line is important:
for testing purposes:
- first box : (input) if the program is running, this will return 1 or 0
- the second box, is the data which we send to device. the device needs to recieve 01 05 00 01 01 00. so the formula is A*256. A is the 1 or 0 recieved from first box (is program running). and 256 is decimal representation of 0100 in hex.
- the last box(output) on right side is just the cfg#0 modbus output (second image). You would set here cfg#2 for controlling second relay (as we did set cfg#2 in prevoius steps).
Now when you press Start buton in mach the relay goes OFF. when program is not running relay is ON.
you can invert the signal ofcoure, but this is only for demonstration so good enoug.
also you might wana restart your mach3 or press reload the brain buttons sometimes during the brains setup, Otherwise it might not work.
Note: To see in real time what the brain is doing you will go to menu: operator -> brain controll. here is where you need to reload brain after change in code and buton View Brain will show you your setup in action. Also your brain must be enabled. that is tickbox in this Brain control window.
Step 9: Setting Inputs
Because we cannot read the input registers one by one we always use cfg#1 to read the data. but we set the modbus address to use to identyfy portion of data representing given input.
addres 0 will represent input 1
addres 1 will represent input 2
first image is setup for reading input2.
second image is setup for reading input 3.
You might want to tick the Bit only box as then your data will be 1 or 0 not 1.0000 and 0.0000 and you will get nice shyny green/ blue square showing the state of the input.
Step 10: I/O
In this setup you can see:
- seting one output(relay1) based on run stop button.
- and the rest of the lines are settings for all 4 inputs. I didnt bother to atach any functionality to the inputs as you can see they state by displayed information and color of the boxes.
Also you can see the green MOD2 box? Yes that is the input3 grounded as shown on the image of board setup in one of the previous steps(blue wire).
10eu for the board and 1eu for modbus usb converter resulting in 4 additional inputs and 4 outputs.
not bad huh?