Machsupport Forum

Third party software and hardware support forums. => Modbus => Topic started by: BenBouwer on January 31, 2018, 01:09:33 AM

Title: Arduino Uno that works with Modbus
Post by: BenBouwer on January 31, 2018, 01:09:33 AM
Modbus Arduino slave for Mach3 by Ben Bouwer
  The purpose of this scetch is to link the Arduino digital and analog pins to Mach3 using the Modbus Protocol.
    To keep things simple I used a register for each pin in the arduino.
    Each register can be a Digital input, Digital output, Analog input or PWM output register
    Choose what you want each Arduino Pin to be (Digital input, Digital output, Analog input, PWM output or MPG input):
   
See attached Arduino Scetch

Unzip it

Place it in a folder within the Arduino folder the same name as the file

Arduino/Mach3_Modbus_Slave_Version_6_Point_5/Mach3_Modbus_Slave_Version_6_Point_5.ino

Title: Re: Arduino Uno that works with Modbus
Post by: TOTALLYRC on January 31, 2018, 07:14:06 AM
Nice to see more Arduino stuff. If I get a chance I will try this out on my lathe since I want to add 2 pots.
Title: Re: Arduino Uno that works with Modbus
Post by: BenBouwer on February 01, 2018, 12:41:10 AM
Find attached pictures of:

Brain Setup
Brain View Register 18
Brain View Register 19
ModBus Configuration

Brain View Register 20 and 22 will be similar to Brain View Register 18
Brain View Register 21 and 23 will be similar to Brain View Register 19

You must write your own Brains for the rest of the Registers
Title: Re: Arduino Uno that works with Modbus
Post by: BenBouwer on February 01, 2018, 12:46:58 AM
Please be carefull.
The program was not tested on a real machine!
Modbus must not be used for critical inputs or outputs.
See Mach3 manual.
Title: Re: Arduino Uno that works with Modbus
Post by: duongfx on February 10, 2018, 05:13:35 AM
 I will try this,thank to Ben
But i do not see ModbusRtu.h include
Title: Re: Arduino Uno that works with Modbus
Post by: BenBouwer on February 12, 2018, 06:58:14 AM
You must downdoad it form https://github.com/smarmengol/Modbus-Master-Slave-for-Arduino

Download it as a Zip file.

Install it using the menus in the Arduino IDE: Sketch, Include Library, Add.ZIP Library

Also download the other Libraries from the Arduino Site or from Git Hub and install them.

#include <ModbusRtu.h>                                          // Ensure that the ModbusRtu library is included (under libraries)
#include <Wire.h>                                                    // Ensure that the Wire library is included (under libraries)
#include <LiquidCrystal_I2C.h>                               // Ensure that the LiquidCrystal_I2C library is included (under libraries)
#include <Encoder.h>                                              // Ensure that the Encoder library is included (under libraries)
Title: Re: Arduino Uno that works with Modbus
Post by: mkydj on March 21, 2018, 04:36:26 AM
Hi Ben,the project is very interesting, which arduino is better?
Do not know well brain mach3, have file brn of the project?
Title: Re: Arduino Uno that works with Modbus
Post by: BenBouwer on April 23, 2018, 07:06:47 AM
I do not have the Brain file for the project. You can do it yourself using the info above.
Title: Re: Arduino Uno that works with Modbus
Post by: kris90 on April 20, 2019, 03:01:07 PM

Hi, I'm using this Sketch to interface it to Mach4, it works but I need to configure some Pin as Input for "Read coils (0x01)" or "Read input Discreats (0x02)" but they don't work. What changes should I make?
I apologize for my English but I am Italian. Thank you
Title: Re: Arduino Uno that works with Modbus
Post by: BenBouwer on April 24, 2019, 01:50:03 AM
Hi
I have no way of helping you.
I am not a profesional programer.
I hope you find a way to make it work fully for you.
Ben