Machsupport Forum

Third party software and hardware support forums. => Modbus => Topic started by: Shilling on March 15, 2012, 03:24:37 AM

Title: Arduino Modbus, Complete, Documented and free
Post by: Shilling on March 15, 2012, 03:24:37 AM
All,
Had a little extra time on my hands so I created a Modbus slave for Mach 3 using an Arduino Uno.  Costs roughly $30 to get and uses completely free software to configure and implement.  Also included is my documentation of all code, settings and building a basic brain for Mach.
Please feel free to use and build upon,
Shilling
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: NV50 on March 27, 2012, 02:02:25 AM
Hello,
Great job and very good documentation

Just a few details when I compile the "Modbus Slave.pde"
Arduino IDE identifies four errors.

"Config_IO" was not Declared In This scope
"Kill_IO" was not Declared In This scope
"Updates_Pin_states" was not Declared In This scope
"UpdatesAN_States" was not Declared In This scope

thanks
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: zafarsalam on March 31, 2012, 08:12:00 AM
Shilling,

Wonderful job. The documentation is very impressive and detailed too.

I am using arduino with modbus slave sketch by Juan Pablo. It only implements funtions 3,4 and 16 of modbus. I am using it mainly for tool change, auxillary keypads and analog inputs for FRO and spindle override. Programming the chip with Uno and putting it on my BOB with serial port. This way it costs me less than $10.

I have yet to try your sketch on my Uno. Have you tried connecting MPG through it?

Zafar
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: mrprecise44 on April 29, 2012, 12:39:32 PM
Hello Tim:

Looks very promising for Modbus. I have a Cubloc PLC, and am connecting it up to my back-up computer for testing. The (3)potentiometers for Feedrate override, Jog %, and Rapid override all work fine with my brains written for the Cubloc; just had to change the address in the setup screen.

Are the digital input pins, (1 thru 12) fixed at present state? They are all 5v/High state, and apparently must be pulled to ground to activate a digital signal input.

If it is (or is not) possible to change the pin mode state, please explain.

I loaded the Modbus program on a Mega 1280, and the standard 328p. Both load fine.

However, trying to load with the latest Arduino ver. 1.0 would not compile. Compile and upload worked fine on Arduino IDE 0021, and 0022. I am sure 0023 works also, as that shows in as the version you used for the screen shot pictures in the manual.

Also, when I ran the blinking LED test, the timer interferred with the Cycle Start screen button in my MSM screen set. It blinked the little white triangle rapidly. When I unchecked the enable box for the timer config, the mad blinking stopped.

The MSM screen set is produced by David Bagby at Calypso Inc., and is an excellent replacement for the standard Mach3 screen. It also has an enormous pdf manual, and a very comprehensive probing screen, with many videos to explain everything it does.

Also, thanks for the superb pdf manual.   








Title: Re: Arduino Modbus, Complete, Documented and free
Post by: mrprecise44 on April 29, 2012, 08:49:08 PM
More info on making input buttons to work:

So far, I am using the pushbutton in pull-down, 0 volts mode. Works fine. It took some time trying different check boxes for the proper function for the brains.

Each button has to be in the Set-up page, under a separate config#'s. The address entered into the Mach3 setup table Address column,for each button is the Arduino pin number you are going to use.

I could not get pins 0, and 1 to work. These are default Rx (pin 0), Tx (pin 1) on the Arduino.

So, my pushbuttons start with pin 2. Pin 13 on my Arduino standard (328p) is internally connected to an LED. I did not use pin 13.

The first part of a brain for each button will look like:  MOD:0 - D0 - P:5 : 1

The MOD:0 is the Register address for the I/O, per Table 4 - Register Map, page 15 of manual. All inputs up to 15 will have this 0.

The D0 is from checking the box for bits, and setting bit number to 0. All of the I/O brains had to be like this.

The P:5, is the Config# in the Modbus setup table in Mach3. The pin address (Arduino pin #) is in the Modbus setup table, and is not entered into the brain checkbox's. This number is unique to each button, since each one has it's own config.

The last number above, : 1, is what the brain looks like when viewed in the Brain viewer. When you push the button, this 1 changes to a 0, zero. It does not show up when you make the brain.

So far, all is working well. I have (3) 10k potentiometers working, and they are actually easier than the buttons. The 328p Arduino has 6 analog inputs, which can be either Analog or Digital.

I am sure there are other configurations that will work with this program, but these numbers will get results.

Since an Arduino is about $30, this is a very nice, inexpensive solution for analog and digital I/O. If you need more pushbutton I/O than the small Arduino, the Mega is slightly more money, but has about more than triple the analog and digital I/O.

Hope this is useful.
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: mrprecise44 on May 13, 2012, 11:06:17 AM
This Modbus program does NOT function above the regular Arduino pin numbers. The Mega has 54 I/O pins available, and only the pins 2>12 work in it's present state. I did not test all of the 16 analog pins on the Mega, only the first 6, which work like the standard 328p cpu Arduino. Also, unlike the standard Arduino, that can use the Analog pins for digital I/O, this program will not allow it.

It seems the author, Shilling, does not monitor this forum.
     
If you want to add some potentiometers for Feed rate, etc., and up to 10 digital I/O panel buttons or LED's it will do that. I would not go out and purchase an Arduino for running Modbus on your machine with this program. :(

Cubloc's smallest CPU, www.cubloc.com, will do far more than this for under 40.00, has a free download program "Cubloc Studio" for programming the various functions, on screen debugging your programs, including ladder logic and Basic, which can run simultaneously, with full Modbus implementation.


Title: Re: Arduino Modbus, Complete, Documented and free
Post by: johnblagg on September 18, 2012, 02:49:05 PM
 I found that you have to edit some files in the libraries refering to  "WProgram.h" to Arduino.h in order to get it to compile
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: ivicam on November 17, 2012, 03:18:55 PM
can everyone post some tutorial how to program inputs for FRO and spindle override in brain and modbus seting for arduino modbus.thanks
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: KRAK on January 07, 2013, 12:57:07 PM
To anyone who might be interested, I have created a tutorial of how setup an Arduino as MODBUS slave that covers both the hardware and software configs. I cover a connection with a C-more HMI, but the basics translate while to this.
http://krakllc.wordpress.com/2013/01/04/arduino-modbus-connection-to-a-c-more-hmi/

I, for one, would like to thank Schilling for his efforts. While I could not get his library working, mostly due to the "Wporgram.h" issue. His website was very informative and is a great resource for someone who has little experience working with MODBUS. 

At some point I do plan on revisiting his library with the updated edit to include "Arduino.h"
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: Madart70 on January 21, 2013, 04:46:26 PM
Hi,

For all having some problems with an Arduino  MEGA
In the modbusslave.pde there is line
"#define Digital_IO_Pins  14 "
that line limits the number of inputs to 14 for the MEGA that has to be increased to 64 (64 is the limit of the IO_Config_Register)
further more in the Kill_IO_Register section there is a typo the last line of the AN Digital also does +3 this should be +4

And for safety reasons there should be a section be created like Safety_IO_Register
Here you could state the safety flags some outputs should be OFF other should be ON when COMMS fails

Also the safety bits should be implemented in the Pin_manipulator.

And for those that really wanna go cheap and simple an ATMEGA8 can do but you need to comment out all line that are there for the MEGA only.
It will fit then with a 8Byte margin or so.


Title: Re: Arduino Modbus, Complete, Documented and free
Post by: Tecnic01 on February 06, 2013, 01:08:24 PM
for those who want to know the arduino modbus
http://www.biemmeitalia.net/blog/it/
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: Chaoticone on February 06, 2013, 01:46:30 PM
Thanks!

Brett
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: fdos on February 25, 2013, 05:51:39 PM
Has anyone actually used this?

I happen to have a few Arduinos around the place and sort of got it running.

On both a Mega and a Duemilanove only outputs 12 and 13 seem to work for me.

The author seems to have vanished from the forum?

Wayne...
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: mrprecise44 on February 26, 2013, 03:16:25 PM
I got it working on I/O D2 thru D12, and analog 0 >5, but found it too cryptic, and it doesn't use the typical Arduino modified C language. Also, the author never responded to questions. There are some who managed better than I did, and those various posts are here in the Modbus section.

The Modbus program posted by Zafar Salam in another Modbus post, works with no problems and will allow all the pins on the Mega to function. This version was created by an Arduino programming whiz, JP Mozeta,  and is also found on the SourceForge website. Also, there is some  discussion how to get an MPG working properly.

The Arduino Mega is an excellent platform for Modbus and the Mach3, due to it's wealth of code on the Arduino site, and the huge number of I/O, including (4)serial ports, and of course low cost when compared to the commecial PLC's.




Title: Re: Arduino Modbus, Complete, Documented and free
Post by: fdos on February 26, 2013, 03:21:20 PM
I actually prefer the cubloc devices personally as I have several years experience with them as well as many thousands of hours of Mach machines talking to them.

But this did seem interesting as I use Arduino's here for other motion control projects.  I'll see if I can find the other Modbus sketch.

Do you have a link?

Wayne...
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: mrprecise44 on February 27, 2013, 12:26:07 AM
Hello Wayne:

Zafar's post regarding the ModBus program for Arduino is:

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

He also wrote a PDF cookbook showing how to set up two analog inputs.

Personally, I really like the Cubloc stuff. I have a Cubloc board on one of my 4-Axis milling machines. They have a very good range of ModBus capable boards, and the Cubloc Studio program makes it even better. Ladder logic, plus CuBasic is pretty powerful. Cuboc makes their many peripherals virtually "plug and play" with all the various types of I/O. Plus, the manual is very detailed, with lots of examples. Perhaps the real plus for Cubloc is 24v, which is the commercial standard for noise immunity. On the con side, the Cubloc needs 2 connections to the computer, and you are dealing with more than one voltage. The other problem is using their tiny connectors. It took me quite a bit of time getting the crimp tool to make up a good connector. I must have made 30 bad ones before I got one right.

However, the Arduino platform is a low cost alternative, and can do much of the typical I/O, like LED's, pushbutton activation of functions, and Feed rate, Spindle % override; an excellent addition to the Parallel port driven Mach3 setup.

Title: Re: Arduino Modbus, Complete, Documented and free
Post by: fdos on February 27, 2013, 01:35:13 PM
I generally use the CUSB36R, in fact a new one for another project arrived today.

I also have the studyboard which is useful for testing in comfort before the live system is ready.

I still cannot understand why I can't get pins 2 to 10 working as outputs on the Arduino with that code.  13 works even though he's using the on board led for status.   All I tried so far was a led on each pin and toggling the active low checkbox in mach ports and pins for that pin on port 0.  I think it was the pins below 11 did nothing for me.

Wayne..
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: mrprecise44 on February 27, 2013, 02:32:02 PM
Hi Wayne:

The ModBus program that runs on an Arduino does not utilize Ports and Pins in Mach3. It is a totally separate operation.

1. The ModBus program uses registers, beginning with 0 up to I believe 48.
2. These registers are scanned by the Serial ModBus Configuration in Mach3.
3. You verify the register is being read by the "Test" window in the Serial ModBud Config page;
4. When the action is working i.e., seeing the pot value change, or a button push change from a 0 to a 1,
5. You can then write a "Brain" which reads the register, which activates a Mach3 OEM code, i.e. Cycle Start, FeedHold etc.

Zafar posted a PDF file, showing how to setup (2) potentiometers for Feedrate ovr., and Spindle %.

The ModBus program uses the Arduino language format to set pins as input, output, or analog read/write, in void(setup).

Each Arduino pin has a corresponding ModBus "register", in the void(loop).

You need to use the Arduino format to setup the ModBus program. Log onto the Arduino site, and study the examples.

On the Arduino board, pins 0 and 1 are Serial Rx, and Tx. Pins 2 through 12 are digital I/O, and pins A0 through A5 are analog I/O.
The Mega has (4) Serial ports, 15 analog pins, and 42 digital I/O.

Title: Re: Arduino Modbus, Complete, Documented and free
Post by: fdos on February 27, 2013, 02:58:51 PM
But which arduino Modbus RTU are you using?

I looked at Zafars post but cant see what software he's running on the Arduino.

I was refering to the one in this thread.  You can address this one via ports and pins.  Albeit as I appear to have found not fully.

Wayne...
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: fdos on February 27, 2013, 03:47:58 PM
OK I think I have found the sketch now.  I see no library used.
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: fdos on February 27, 2013, 05:01:07 PM
Had a bit more of a dabble.

Just for fun added to

void setup()

   pinMode(13,OUTPUT);  
   pinMode(8,OUTPUT);

and to

void loop()

digitalWrite(13,regs[3]);
digitalWrite(8,regs[4]);

As expected I get access to Arduino pins 8 and 13 via modbus test (registers 3 & 4) and vbscript (Setmodoutput (0 & 1)) etc fine.

Could be useful..   I chose those pins as purely arbitary examples.  Normally I'd probably pick them sequentially.

Title: Re: Arduino Modbus, Complete, Documented and free
Post by: mrprecise44 on February 27, 2013, 05:34:14 PM
Hello Wayne:
Sounds like you have the basics going in the right direction.

John
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: fdos on February 27, 2013, 06:24:30 PM
Yes, it's fairly straightforward now I have the same code you other guys are using!

Seems to be some redundent defintions etc in there, might have a go at tidying it up a bit.



Wayne...
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: Paul_PC on April 06, 2013, 08:52:05 AM
Sorry when i verify, The arduino say "WProgram.h" no such file. :'(

Is it miss some file?

Thank you so much
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: fdos on April 06, 2013, 08:57:39 AM
Change all references of WProgram.h to arduino.h.

 I think that's what I did.  However I found the other sketch we have been talking about to be better.

Title: Re: Arduino Modbus, Complete, Documented and free
Post by: Paul_PC on April 10, 2013, 09:36:05 PM
Change all references of WProgram.h to arduino.h.

 I think that's what I did.  However I found the other sketch we have been talking about to be better.


Thank you very much.It is work now
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: jmaurin on March 10, 2014, 07:29:11 PM
Hi!
I have my Arduino programmed with the library on this thread and setup 4 IO's (pins 2,3,4 and 5) to input. In the test window of Mach3, i can see the change of status while i press or not my buttons on the board....the value of register 0 goes from 003C (notthing pressed) to, for example, 0038 (pin 2 grounded), so i know that my arduino and communication os working.
The problem is that i can't get any brain to work....i can't get my mach3 to undrstand that this modbus input should make "#INPUT1" active. Can anybody help me with this brain?
Tks.
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: mrJmek on March 23, 2014, 04:58:04 PM
Hey HI!

Shilling, thank you for this awesome documentation, it works fine!
I can blink with diode on my Arduino Uno R3, but I have few question about this documentation and CNC.

I'm working on my first CNC machine and I'm newbie in this area, for this moment I have:
- Arduino Uno R3 - http://cdn.makezine.com/make/arduino/Arduino-callouts1.jpg
- 2xL298N driver for stepper motor - http://image.dhgate.com/albu_355579110_00-1.0x0/a35-l298n-stepper-motor-driver-board-robot.jpg
- 2xunipolar stepping motors MITSUMI M42SP-5P (from printers) - http://img441.imageshack.us/img441/1098/minip9251053.jpg
- Power supply for 12/24V;
- future CNC from wood.

Connection between Arduino|drivers|motors looks like on picture in attach.

I had already upload "firmware" for Arduino, but I can't get how to setup Mach3, because for connection one motor it took 4pins on Arduino. In the Config -> Ports and Pins -> Motor Outputs you can specify only 2pins.
Can anyone help with a link for good tutorial or documentation how to setup Mach3+ModBus+Arduino?
Or, maybe, someone can with understanding "How to work with Brain" when you are making CNC?

Thanks everyone for help!
Have a good day!)
Title: Arduino Modbus, Complete, Documented and free
Post by: Fastest1 on March 24, 2014, 09:07:33 AM
Are you trying to use pin 3 for step on 1 motor and direction on another?
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: Daley on June 11, 2014, 04:09:55 PM
For those trying to work through these specific errors when compiling:

WProgram.h - no such file
"Config_IO" was not Declared In This scope
"Kill_IO" was not Declared In This scope
"Updates_Pin_states" was not Declared In This scope
"UpdatesAN_States" was not Declared In This scope

As found elsewhere on the internets, the answers are relatively simple: replace (or as I did, copy) all instances of WProgram.h to Arduino.h - the newer compilers changed this after this thread was created. For the "not declared..." errors, follow Shilling's instructions *explicitly* - don't just go blindly. If you're using a non-Windows OS, you'll need to make sure permissions (or more specifically, ownership) is appropriate for the user that's launching the IDE.



HINT: The answer is in section 3.2, page 11 of his instructions. Chances are you might be opening the wrong file (ask me how I know  :P )

HTH!!!
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: Fuzer on September 02, 2014, 05:58:32 AM
Quote
As found elsewhere on the internets, the answers are relatively simple: replace (or as I did, copy) all instances of WProgram.h to Arduino.h - the newer compilers changed this after this thread was created.

How did you do that? Did you just type #include <Arduino.h>  or you did something different? Would you mind to upload the correct sketch? I am newbie at arduino and mach3. Thanks in advance.

Constantine
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: mrich0908 on September 06, 2014, 10:38:26 PM
A little bit of reading and google gets you where you need to be .
You open each \file in the library you moved there and copy cut paste at the begging Wprogram.h to Ardunio.h
Open others code in notepad or wordpad to get a better look at how there written. When you save the file i note pad change the bottom drop down from TXT to ALL FILES then dot and file extension (Examaple Googlefu.h or Googlefu.tap)
link ----
http://forum.arduino.cc/index.php?PHPSESSID=d3n4glod3ktah18r8tambatfo3&topic=97455.0
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: dude1 on September 06, 2014, 11:30:49 PM
use notepad++ to do changes it makes it easier.
you look in the files to do with modbus its at the top of all the different files as mrich0908 says change Wprogram.h to Arduino.h, also all the .H and .CPP files need to be changed and put in the correct place as well.
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: mrich0908 on September 07, 2014, 12:13:28 AM
use notepad++ to do changes it makes it easier.
you look in the files to do with modbus its at the top of all the different files as mrich0908 says change Wprogram.h to Arduino.h, also all the .H and .CPP files need to be changed and put in the correct place as well.

Your 100% correct. There are 4 files .  I never used Notepade++ . I keep reading about it . Whats the advantage over regular notepad? I haven't written a piece of code ever I just dabble changing others but really dont understand the whole arguments and variables thing.
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: dude1 on September 07, 2014, 12:27:04 AM
you can change notepad++ to different coding types and it opens a file how it is if you used a proper coding program for what ever language its in, like how it looks in the arduino ide,
also it save in the language that the code is in, no changeing from say Arduino .pde to .txt back to .pde
it just makes life easer for doing simple changes, works with .Lua to.
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: dude1 on September 07, 2014, 12:35:51 AM
to get modus working with the newer ide there are some miner changes that need done in the add-ons for it .H and .CPP files I cant rember what they are I did fix it last year and had it working but that computer was win 8 and I managed to get the win 8 lock virus, anything that was not accessed through the hard drive I got off but the arduino stuff and m3 was so I cant get in to get it off so i cant be off any-more help sorry
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: mrich0908 on September 07, 2014, 01:29:57 AM
Is that virus M$ sent out or ... I really dislike 8 and I understand it has a quite a bit improvement over previous years but I just dont like what they did with the GUI . I feel like Im using my phone when I log on 8 .
Im defiantly going to download Notepad++ thanks .
Im going through the tutorial now probably 65-70% through. I havent had problems on 7 but my G0704 is on an XP . I was getting to know modbus before I put it on my machine.
I have a Parallax P8X32A propeller quickstart board with a FT232RL chip. Think I could use that chip in modbus ? I would probably need custom code huh?
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: dude1 on September 07, 2014, 02:00:01 AM
it was the one you get an email send money to account what ever or you computer wont work ever again I replied f you plus a lot more words.

the changes you need to do are in the arduino forum some where it really simple what needs done it just a couple of words that need changed
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: dude1 on September 07, 2014, 02:41:00 AM
you are lucky I found what I did just had a play.
you need to have the CRC16.Cpp, .H plus Modbus_Slave.CPP, .H also ModbusSlave.H, .CPP in the Arduino - hardware - arduino - cores - arduino folder.

in the arduino libraries folder you have ModBusSlave and Pin_Manipulator in one folder just call it ModBusSlave

just change all Wprogram.h to Arduino.h in all folders
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: mrich0908 on September 07, 2014, 11:22:11 AM
you are lucky I found what I did just had a play.
you need to have the CRC16.Cpp, .H plus Modbus_Slave.CPP, .H also ModbusSlave.H, .CPP in the Arduino - hardware - arduino - cores - arduino folder.

in the arduino libraries folder you have ModBusSlave and Pin_Manipulator in one folder just call it ModBusSlave

just change all Wprogram.h to Arduino.h in all folders

Worked perfectly thanks for the tip.
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: mrich0908 on September 07, 2014, 06:52:40 PM
So ive been messing with all day .
Im not understanding something or....
I went though the manual . I got the system working . Last step hook up pin 13 to a led. Turn spindle on see led blink on 13. That works, cool.
If I go into modbus switch to any other pin but 12 or 13 the led wont flash.
I take that this happening isnt good. Any ideas?
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: dude1 on September 07, 2014, 07:01:57 PM
it will be a setting you have wrong I had the same thing it in the instructions just start again I found what I did wrong in the end but it just a setting what hopefully will be out
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: mrich0908 on September 07, 2014, 09:17:27 PM
it will be a setting you have wrong I had the same thing it in the instructions just start again I found what I did wrong in the end but it just a setting what hopefully will be out
Your right it was a setting in the sketch.
 Im trying to wrap my mind around the whole Analog inputs  being either 1 or 0 or changing them to digital I/O by setting them to 1 or 0 .
I need a GUI with drop downs. If I could write could I so would.
Im getting it though. Now I have to understand how to write the brains properly then I could throw it all out the window because Mach4 will be out. : )
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: mrich0908 on September 07, 2014, 09:31:05 PM
O BTW heres the original posters web site if any one is looking for him.
http://replicantfx.com/
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: dude1 on September 07, 2014, 10:18:10 PM
that's why I stopped playing with modbus I did not think it was a good idea to learn how to use it twice
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: mrich0908 on September 08, 2014, 02:26:50 PM
Does any one have examples of brains and modbus using shillings system ?
I keep reading this manual and cant understand what bit goes where why and when. I understand the very basics . I can make a led bink off the of the spindle any where on the board.
Ive been trying to get my spindle rpm to increase using a 10k pot. Not happening. Im not sure why.
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: mrich0908 on September 08, 2014, 03:14:16 PM
If some one could explain the PDF regarding the operations on pages 21-23 in detail I would really appreciate it.
I would like to know what each bit corresponds with and each function so I know why to select those things. Im so confused.
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: mrich0908 on September 08, 2014, 05:40:52 PM
If some one could explain the PDF regarding the operations on pages 21-23 in detail I would really appreciate it.
I would like to know what each bit corresponds with and each function so I know why to select those things. Im so confused.

I happend to find some one who fixed the simple problems betwen arduino software 1.0 and 1.1 . Along with that its says they implemented RS-485......
https://github.com/devlware/ModBusSlave
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: mrich0908 on September 10, 2014, 01:27:41 PM
So after sitting here for days playing with this .
Ive learned allot.
This system works 100% as is.
To get pin 10 analog input off lets say A0 . Your port address (1024)  would be a variable as described in the manual. Modbus address would be 30. That refers to pin 10 . If you wanted a different pin ,looking the register map on PG16 45 would be input analog pin a15 and so on .
When configured in Mach 3 the cfg must match what line being used . Input for an input there's no corresponding bit to match.  If you had of chosen bit 1 it would have flash high low high low so on .
The first example given in the manual was spindle flash. If you want to change pins on your ardunio.  You would choose the proper register where the pin was in the port adress section 0 (0-15) , 1 (16-31) ,2 (32-45), 3 (46-63)or 4 (A0-A15) NOW THESE ARE DIGITAL I/O only. Under Modbus address choose your pin. So if I wanted pin 33 that was digital I would choose register two  in port address and pin 33 under modbuss address .
All this has to correspond with the sketch uploaded to your arduino. make sure you turn your inputs on and off as described in the manual.
I use the Arduino Mega and noticed a few things that had to be changed in the sketch. There what level of importance is im unsure of. The first set of input output registries says 01233 , it should say 01234. Pin total says 14 for a uno mine should say 63. Match your Baud to your pc to mach . Besides that your good to go.
Ive looked over a few Modbus sketches and really like this one.
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: ahmed01280 on March 07, 2015, 12:04:09 PM
how can i program step pin and dir pin in brain editor and arduino
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: alhaddar on March 22, 2015, 01:59:49 AM
Hi
Please help fix this error
 
In file included from ModBusSlave.ino:5:0:
C:\Users\hq01\Desktop\arduino-1.6.0-windows\arduino-1.6.0\libraries\ModBusSlave/Modbus_Slave.h:19:7: error: redefinition of 'class ModBusSlave'
 class ModBusSlave
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: battwell on March 29, 2015, 05:15:24 PM
great thread.(and thank you shilling)  i made the changes mentioned and got my mega working within an hour or so!
now i just have to do the hard bit- sending/receiving these registers to old i/o cards on my machine via the arduino on  a seperate com port.
stupid things have 192600 baud rate and an xor checksum ..... wish me luck!
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: nso on October 05, 2015, 12:22:48 AM
hi everyone
i have a problem,  i have tried to upload arduino uno i got an error message. so what shall i do to handle it?
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: dude1 on October 05, 2015, 01:25:36 AM
update the usb driver`s also the modbus was written for a earlier version of arduino

have a look here it may help https://learn.adafruit.com/lesson-0-getting-started/installing-arduino-windows
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: nso on October 05, 2015, 02:00:40 PM
thanks for your quick replay ,after that i am sure about usb port and arduino  version because i have done it  whit zafar s sketch  (analog input) and that is worked great ....then when i tried whit shilling sketch that error happened.
sorry ,i know my English is awful
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: dude1 on October 05, 2015, 03:38:19 PM
there will be a need to change some bit`s of the code I cant rember what to long ago and ask on the arduino form
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: nso on October 05, 2015, 11:18:11 PM
no problem,anyway thank you.
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: giantpt on October 16, 2015, 06:34:15 PM
Hi there...
I tried to compile the modbus code but I'm getting an error... missing the WProgram.h
Any suggestions about this?

Thanks

Kind regards
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: dude1 on October 16, 2015, 08:06:18 PM
look here http://forum.arduino.cc/index.php?topic=147680.0
the WProgram.h is from v1 of arduino it got changed to Arduino.h
Title: Arduino Modbus, Complete, Documented and free
Post by: giantpt on October 17, 2015, 05:44:32 AM
Thank you for your help...
Now I have some inputs working with leds, some blinking, some fixed but I noticed that just some arduino mega ports from the main row (2 to 12) are working as outputs and none of the extra ports are working (22 to 53).

Can some one explain to me which ports are usable as output / inputs and how to enable the extra ports of the arduino mega?

Is it possible to connect more than one arduino mega to the system? Is there a limit of arduino or ports on the system?

Just one more question, how can I setup a rotary encoder on the mega and mach3 to work as a MPG?

I would like to build a console to my milling machine with as many functions as possible (buttons, leds, switches, etc...)

Thank you in advance

Regards
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: dude1 on October 17, 2015, 05:53:45 AM
Thank you for your help...
Now I have some inputs working with leds, some blinking, some fixed but I noticed that just some arduino mega ports from the main row (2 to 12) are working as outputs and none of the extra ports are working (22 to 53). look at the pinmaping https://www.arduino.cc/en/Hacking/PinMapping2560

Title: Re: Arduino Modbus, Complete, Documented and free
Post by: giantpt on October 17, 2015, 07:50:06 AM
Well, found how to increase the number of ports on the Mega to be used... it is on the Arduino code, the default value of ports is 14, we just have to change this number to the desired number, in my case I have activated all of the digital ports with the number of 54

Now, on the Modbus configurator how can we call the analog ports? as we cannot write "Axx", it allows just numbers
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: giantpt on October 20, 2015, 04:15:08 AM
Hi guys, I found a lot of things by my self but I still need help on how to connect more than one arduino to the system.

someone knows how to do it?

thanks
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: CNC3D on December 04, 2015, 07:49:06 AM
Hai, recently started with CNC Mach3 etc.  So I registered and stumbled upon Modbus, sounds cool. I've read the topic and i think i can answer your question, although 2 months late.

On one arduino compile and upload the 'standard' firmware ModBusSlave.pde
For  another arduino make a copy of ModBusSlave.pde and rename it to ModBusSlave2.pde (of course in its one arduino directory with the same name)
Open ModBusSlave2.pde and change the line

    #define Slave_Address 0x01   //Address of MODBus Slave

to #define Slave_Address 0x02   //Address of MODBus Slave

save and compile and upload.

I have yet to try it myself. but this is what I can think of to make it work.
In mach3 you also have to use slave 2 (obvious).

Regards
Frank





Title: Re: Arduino Modbus, Complete, Documented and free
Post by: Tweakie.CNC on December 04, 2015, 07:55:39 AM
Hi Frank,

Welcome to the forum.

Excellent explanation.

Tweakie.
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: aluplastvz on January 09, 2016, 11:53:35 AM
I have a problem with this code when you activate the Modbus command and went M6T ???
Mach3 bag, "blocks"
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: learncnc on January 18, 2016, 12:45:12 AM
Hi...everyone
Can provide many mach3 Brains and Arduino Modbus complete example.
Provide Arduino LCD Displays for mach3 portable example.

thanks.
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: XavierMod on February 22, 2016, 04:02:59 PM
Hi!

I am using the Shilling library to read 10 switches and following some corrections in this post it works very well.
The problem I have is when spindle starts, comunication  is broken, perhaps there is some interference.
To solve this problem now I use the "open" button in "modbus test" window, then Mach and arduino Uno reconnect.
I would like to know how to execute this "open" function from a macro.

Also I'm thinking abou to use TCP modbus in order to avoid this problem.
I think tcp modbus allows temporary interruptions, doesn't?

Thanks in advance
Xavier
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: Tweakie.CNC on February 23, 2016, 02:06:21 AM
Quote
The problem I have is when spindle starts, comunication  is broken, perhaps there is some interference.

I think the electrical noise issue with the spindle should be resolved first.

Tweakie.
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: XavierMod on February 23, 2016, 02:33:10 PM
Yes Tweakie, you are all right, but not ever is possible to remove all noise in circuits, specially in a 10meter usb cable.
The solution I have tested is to reopen the modbus port, but it is not practical using menu.

The Shilling library puts pin 13 up when "Kill time" is reached,
This pin 13 could be wiredd directly to an Mach input.
I would like try reopen modbus port in macropump reading this input.
The problem is I can't find any way to do that, perhaps a plugin is needed.

Xavier
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: dude1 on February 23, 2016, 05:58:19 PM
well a 10 meter USB cable is well not good change over to a Ethernet board
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: borbori on March 29, 2016, 02:28:39 PM
Hi,

Great job, Thanks fellas,
So is it possible to have axis output (STEP/DIR) on arduino mega output ? for example port 0 pin 24 for X DIR and port 0 pin 25 for STEP ? so we can have a modbus breakout ?

Thanks
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: ahooper on June 18, 2016, 12:38:23 AM
Awesome job! Just thought i would let you know I got this installed on a Teensy 3.2 and have used the USB for the interface. The goal is to use this as a pendant.
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: battwell on September 30, 2016, 06:42:10 AM
i have all this working with uccnc as well as mach3 now.
great stuff!
https://www.youtube.com/watch?v=7-T4hNrYVa4
Title: input arduino
Post by: cnckunder on October 19, 2016, 03:15:31 PM
hello i am new.
I got de modbus with arduino working.
There is one big problem.
When i use a input it needs 80 ma current to pull down to 0 volt.
I tride a mega and also a uno both new.
What am i  doing wrong??? please help
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: nokialkatel on January 14, 2017, 06:05:16 PM
hi! I need help from experts!

How to setup dro info on lcd connected to arduino modbus slave from link and library in 1.post???

Ihave included wire.h and liquidcristali2c.h for lcd in arduino code.
From now I ned help for how to send data from mach3 -->>>brain-->>serial modbus plugin--->>>arduino modbus slave ?????
many users have this done but no documentation on arduino code, no info about serial plugin configs,
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: Sergtool81 on January 06, 2018, 04:46:28 AM

Hello. I ask you for help. I have a board arduino uno. I'm trying to flash it in the instructions, but it does not work.Gives an error message:

 -Arduino: 1.6.3 (Windows XP), Board: "Arduino Uno"
Build options changed, rebuilding all
CRC16.cpp:16:22: fatal error: WProgram.h: No such file or directory
 #include "WProgram.h"
compilation terminated.
Error compiling.
  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

Tell me please what am I doing wrong? ???
Sorry for my English. Thank you in advance
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: Ashur on June 05, 2019, 02:38:43 PM
I have been trying to make Shilling's code work for arduino due without success; the sketch uploaded successfully and the serial led's blinking, but no input/outputs responses between master slave.  On Uno the code works fine.  Has anyone tried to use arduino due with this code?  What could make it not working for due?
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: ZASto on June 05, 2019, 03:10:02 PM
CRC16.cpp:16:22: fatal error: WProgram.h: No such file or directory

Bolded should be changed with Arduino.h if you use newer version of compiler.
Title: Re: Arduino Modbus, Complete, Documented and free
Post by: TheSuperior on March 24, 2022, 01:06:43 PM
Has there been any further developments on this?