Process control based on free resources … posted by on December 21, 2011

The solution to all evil…

Proview, Arduino and other free software/hardware resources builds interesting concepts for future control systems. The range stretches from simple sequences in small machines to complex factory wide or even global processes.

The star in this niche is a system called   While the name may not be familiar to most people, the system has proved itself in the Swedish steel manufacturing business for more than two decades. It is actively developed and maintained and has a very interesting and active forum.

Arduino is a project aiming for easy prototyping of smaller  electronic systems. It is widely used in hobby projects and is spread to all corners of the world, There are many free software projects that runs on Arduino boards. There are industrial protocols implemented, for example ModbusTCP.

My project is to provide an I/O module based on Arduino but designed to work in industrial environment with noise, dust etc. This module will be usable together with Proview.

I will post my progress here….


The tests I have carried out so far is with an Arduino Ethernet card

I have (today) extended the functionality of the “Mudbus” project  to include Modbus Functions 15 and 16 (write to multiple coil and multiple registers). So far it is not tested properly and I have had no reviewer looking at it yet… I put the Git repo here  so have a look…

My plan is to include function code 2 (read discrete inputs) and then we will see… Dee Wykoff, who has written the Mudbus lib has been very positive so far. We’ll see if my dirty hacks will reach his QA levels in the future… His code is quite neat…

I will try to focus on price reduction later on when I at least have a card that works. The ethernet chip is of course one of the candidates but I haven’t though much about it. I’m willing to help though.

SGS Thomson’s old VNQ810-E is probably still a good 24V high side driver although there are newer replacements but VNQ810-E is quite cheap… I have only checked prices in couple of places so far though…

I will use Muratas NFM61R filter on basically every input and output. I have used them in the old days when I made my first designs compatible with the CE mark… They are double inductor and cap in between and they can handle 2A… so you can use them on almost everything in a PLC. Maybe there are more compact ones today, I have to check. the NFM60R is smaller but rated 25VDC which is not enough… be careful when you use filter components and read everything you can find on the subject…

I used to always do 4 layer PCB designs with separate layers for gnd and the 5V… for my first prototype I think I will use two layers only…
For 24V signal inputs I use Murata filter and then a voltage divider and a Zener + cap and then a Schmit trigger 74HC14 or something…and then into the shift register that I shift in to the Arduino…

My thought is that I will use an enclosure that is DIN rail mounted, but skip the modularity the Wago and Beckhoff way. They spend a lot of money on the connectors and modular plastic enclosures. My thought is make a series of boxes from 8/8 up to to 32/32 but without any possibility to expand a box. After all, you can just buy one more if you need more signals.
The 6 analog inputs of the Arduino can be used with proper buffering and signal conditioning but they are only 10bit… enough for some measurements but not for any high accuracy stuff…

For more demanding tasks I’m convinced that a dedicated AD/DA converter should be used in a separate box without any digital signals.

PWM outputs can be nice but not on the same board as any high resolution ad converters…
Oops it’ late….

———— If you want  my versions of Mudbus – here is how to get it ————–

You can visit my clone of Mudbus here

To get the project to your computer you need to install git.

If you are on a debian/ubuntu machine:
sudo apt-get install git git-gui gitk git-doc

If you are on windows
take the Git-1.7.9-preview20120201.exe or whatever is latest and install it… easy.

From the command line in linux

git clone mudbus

in windows right-click on a folder and take “git bash”
There will be a commandline interface comming up
git clone mudbus

Please let me know if there are any problems…

—————— Progress report 12 February 2012 ——————-

I have a running version of Mudbus that supports most things needed for use with Proview… but it needs more testing. Run it if you want but not on any important applications yet.

Blue ones are working in the original Mudbus library but it didn’t support multiple requests in one ip message.

Read coils (FC 1) 0x
Read input discretes (FC 2) 1x
Read multiple registers (FC 3) 4x
Read input registers (FC 4) 3x
Write coil (FC 5) 0x
Write single register (FC 6) 4x
Force multiple coils (FC 15) 0x
Write multiple registers (FC 16) 4x

Red means warning… actually I should red-mark all of it since code in all FCs has been modified.

I added FC2 FC4 FC15 and FC16 and support for multiple requests in one ip message.

What is next?

We have to make more testing. I need to write test applications in Proview and for Arduino to stress the protocol.

And I need to clean out a number of ugly Q&D hacks. The code from Dee was quite neat from the beginning and I have messed it up…


 This is the “normal” way that I thought it would always be…

But then a message like this came up. It includes three requests!

Now in the latest version I also respond all requests in one message.

Wireshark shows no errors or any strange messages any longer…

These are the areas that this version is using:
Mb.C[0-63] bool
Digital outputs address range 0x

Mb.I[0-63] bool
Digital inputs address range 1x

Mb.IR[0-15] signed int
Input registers (for AD converters, counters etc) address range 3x

Mb.R[0-15] signed int
Holding registers (for DA converters, frequency outputs etc) address range 4x

——————— Update 13 February 2012 —————————————–

Did som cadding today. Schematics is not ready yet, LEDs are missing and the power suppy is not there yet.

Analog channels is also missing but it will be a jumper for 4-20mA and 0-10V without it…

——————— Update 15 February 2012 —————————————–

I have decided to threw away some of the schematics and go for the VN808 octal driver instead. It is more expensive per output but saves space on the board. There will also be opto couplers… get rid of some of the filter components that way and I’ll try to protect the processors as much as I can.

The basic concept is still the same with shift registers… I’ll be back with news during this week…


——————— Update 18 February 2012 —————————————–

I thought of using the Infineon ISOFACE components for this project… I just regret spending a day reading data-sheets.

Technically the ISOFACE is what I need but the business side is below any standard I have seen before…

No one stock these devices except and they seem to have lost confidence in Infineon too…

They give strange price indications, marking the devices as “obsolete” and “end of life”.

I’ll be back…


——————— Update 19 February 2012 ———————
Still much to add…. opto on the clock and data signals and power…
Now it is time for Gokart racing with my daughter…


——————— Update 20 February 2012 —————————————–
Changed to 74HC595 and added some magnetic digital isolators to protect the Arduino from noise…
The input circuit shift register has some nice parity bits and the output circuit I plan to feed it back into the arduino so I can detect any changed bits. I will discover errors when the shit already hit the fan but at least I can alarm for it within the next scan cycle.


——————— Update 19 March 2012 —————————————–
One month has passed. I have done a little on the PCB layout but it is still just rough placement of the components.
I have had some trouble at work that has required my attention but the last week I have been on vacation.
There has been some thinking about how this card shall be used though. I will try to make this card more of a SPI-bus device so that I’m not completely focusing on the Arduino but also on other single board computers like the Raspberry Pi for example. This will not affect the schematics much but it is more on the layout this will be done.
The Raspberry Pi is cheaper than the Aurduino and I can use it as a platform for but it is not entirely suitable for being just an I/O module because of the complexity of carrying the Linux OS. The Raspberry Pi also need an SD card which will get the price tag up a little for the complete module.
I will try to get the Mudbus software to the point where it is ready for production though because it will still be used in my systems.


——————— Update 16 April 2012 —————————————–
Fixed a millis rollover problem in my example file copy_in2out_mb.
I’m still working with the PCB layout of the I/O module…
——————— Update 5 May 2012 —————————————–
Here is the ongoing work.


I publish this not to provide any ready solutions but to get some inputs from you. I have been designing industrial electronics professionally on and off since 1984 but I don’t know everything so I’m happy for any feedback I can get.


Changes that I plan:


1. To make sure people separate the power to the processors from the power to the rest of the system I will use Power over Ethernet for the processor modules. Arduino Ethernet has it by design.
Raspberry Pi will need an add on module and a different magneto Ethernet connector.


2. I will provide an optional relay that can be used to turn on/off the 230VAC to the 24V power supply that powers the I/O side of the system.


3. This modules are 8in/8out only. There is an SPI connector that can be used for adding more I/O so I plan a series of modules. I have not decided yet but normally there are more inputs than outputs so maybe I make separate modules for inputs and outputs. Schematics will be almost exactly copies of the input and output circuits I already have.


4. A box… I have made a vacuum forming machine… well just a wooden frame with some holes and a pipe to connect the vacuum cleaner. I will do some prototyping to see what is practical. Maybe I end up with buying a standard box for DIN rail mounting.


5. I’m working in electronic and fine mechanic assembly and part manufacturing. I will try to investigate what I need to do to interface with applications in other areas of activity for example HVAC systems.  The long term goal is to provide the community with industrial grade open source hard/software solutions for as many applications as possible.


I use magnetic couplers ADuM1300 to separate the processor modules galvanically from the rest of the system.
The shift-registers are on the noisy side and needs protection by rc nets.
The input IC is SCLT3-8
The output driver is VN808
These layouts are ongoing work and will be changed.
These layouts are ongoing work and will be changed.

Mockup of the box. I have not decided if I should make it for mounting like this or if shall make turn it 90 deg, card edge to the DIN rail, to save width in the cabinet. In that case the LEDs are not going to be where it is written on the foam…
There will be expansion module too…
Or maybe put the Arduino on top and cut the thing?


And yes, finally my Raspberry Pi arrived from Element14. So now I will compile for ARM and see if it works.


Raspberry Pi is bigger than the Arduino but I think I make one version of the board and the box to fit both of them.

40 Responses to “Process control based on free resources …”

  • Komal says:


    Great work Martin!

    I am new to arduino. I am trying to implement Modbus TCP client (master) on ethernet.
    Can you please guide me what modifications do I need to make in your library and code?
    Or whether you have a similar library for Modbus TCP Master.

    Please guide.

    Thanks a lot.


    • Martin says:

      Dear Komal
      There is not much that are the same in the code for modbus clients and modbus server. The “Mudbus” library used in this project is a server. The clients are running Linux and you can use the “Libmodbus” library, but I don’t think there is any Arduino version. You can always use a Raspberry Pi as client. It is a Linux computer nicely priced…
      Sorry I don’t have any modbus client lib. There may be other so search around in the forums may give you some hints.
      Best regards.

  • cody says:

    Great work!..
    I just downloaded the newest Arduino 1.6.5 and found this site, for the board manger plugins for NodeMcu using the ESP8266 Wifi. Looking at the examples it supports tcp ports.
    With a little work I think Mudbus can run on this little gem.

  • Pedro says:

    Hi, first tnks, great job. if a wanna use with wireless module, what i have to do? i do a simply change or hard job? if simply, can u help me? tnks.

    • Martin says:

      Thanks Pedro!
      I’m afraid I don’t have any experience with the wireless module.
      I’m not sure if the wireless module is supported by the Ethernet lib that is used by the Mudbus software. Without Ethernet lib it will not work…
      One way around it is of course to connect your Arduino via an Ethernet cable to a wireless Ethernet router but it really is not a portable solution as you need to carry around the Arduino plus the router…

  • mohammad says:

    hi, i have a problem and that is : Ethernet fails connecting after a while .when i connect of server to boar ,Connection is established from 5 minutes – 1 days, then Ethernet refuses to make a successful connection to a server until the board is reset. in your opinion , What should I do?
    thanks in advance

    • Martin says:

      usually when things works for a while and then stop working, it is because of memory problems. Arduino does not have any memory management system so if you have too much variables declared you may end up with overlapping memory areas.
      If you use mudbus you should try to reduce the size of these ones to numbers that you really need (in the file Mudbus.h):
      #define MB_N_C_0x 100 //Max coils for Modbus is 100 due to limited memory
      #define MB_N_I_1x 100 //Max inputs for Modbus is 100 due to limited memory
      #define MB_N_IR_3x 64 //Max 16 bit input registers is 64 due to limited memory
      #define MB_N_HR_4x 64 //Max 16 bit holding registers is 64 due to limited memory

  • mohammad says:

    hi, i have a problem and that is : Ethernet fails connecting after a while .when i connect of server to boar ,Connection is established from 5 minutes – 1 days, then Ethernet refuses to make a successful connection to a server until the board is reset. in your opinion , What should I do?
    thanks in advance

  • Patricia Mendoza says:

    I’m trying to use the modbus tcp examples codes and I have an error on this line Mudbus Mb; and the text box says this:
    ‘Mudbus’ does not a name type
    Light.pde: In function ‘void setup()’:
    Light:29: error: ‘Mb’ was not declared in this scope
    Light.pde: In function ‘void loop()’:
    Light:35: error: ‘Mb’ was not declared in this scope

    Please can you help me with this?

    • Martin says:

      I’m sorry, have only tested my the latest version with one example and that is the copy_in2out_mb.ino. The rest of the examples should work with older version. Please see Dee Wykoff’s original versions.

  • Bob Moors says:

    I am wondering about floating point in modbus tcp. How does proview handle it? I have done some testing with both ENC28J60 board and wiznet. I think the ENC28J60 takes too much cpu time to give a timely responce. I really like this project I am wanting to use it on Load Cells and bring ethernet to the load cell, hence the use of floating point.

    • Martin says:

      As far as I remember the only register format in Modbus is 16bit words but you can of course use a number of 16bit words to encapsulate any other format as long as it is properly decoded in the receiving end. Proview… I don’t know, but they have a forum. You can implement the conversion in the driver or in the application…
      Take care.

  • Andrew says:

    Hi, I am kinda new to all of this, but do you think that it is possible to get the modbus library to work with any of the arduino wifi cards like the WiFly or the Arduno WiFi Shield? I know that the modbus library uses the Ethernet library but could it be modified to work with these other libraries? Thanks!

  • Trikos says:


    I start tests with s7 1200 and 2 arduino mega. Is there a away, to check if there is a connection error, or any other faults on bus??

    • Martin says:

      I use wireshark to see the traffic… And in order to route the traffic through your computer the easiest way is to use arp poisoning. Ettercap is good for that.

      • trikos says:

        i mean in arduino side, if connection is lost, to switch off some outputs as example

        • Martin says:

          Maybe you can let the Arduino reset some flag that another host sets frequently via modbus. If the flag remain reset for more than a certain time then you know the communication doesn’t work… Like a watchdog.

  • Chiara says:

    got some errors due to:

    #include “Mudbus.h”

    instead of

  • Zaid Pirwani says:



    Can you please tell me if this ModBus TCP Library will work when used with an Arduino UNO and an ENC28J60 board or is it solely designed for the Wiznet ethernet, in that case, will it work with Wiznet W5100 Ethernet shields for Arduino?

    and one LAST THING, will this work with RSLOGICS PLC software for Raspberry Pi.

    Their software also has support for ModBus TCP Slaves.

    Thanks for your time.!

    • Martin says:

      The dependency is the arduino ethernet library. If that library can handle the chip/board you want to use, it should be no problems…

      When it comes to compatibilty with Resologis products, I don’t know. If they are reasonbly compatible with the modbus/tcp protocol, it should work.
      Resologis is just another one of those proprietary software vendors that dump prices for educational or private use, just to turn around and charge for any “commercial” use. I would stay away from them and use free software like or something like that. Look for free licenses for example GPLv2 or GPLv3…

      • Zaid Pirwani says:

        Thanks Martin, For now, I am just wanting to be sure if it will work with ENC28J60 or not, as the Arduino Ethernet Library is for the Wiznet W5100 and those are quite expensive, I am getting ENC28J60 Ethernet breakout boards at half the cost of Wiznet W5100 shields, can you please check or tell me how to check – I myself will try testing tonight.

        I don’t have either at the moment, so the only way I can check is to get the code and then compile it in Arduino and see if it compiles or not.

  • Mauricio AP says:

    I’m trying to use your library to send an information entering through the serial port and then to operations, to publish it on modbus tcp.
    Get stuck the Arduino Uno Ethernet at the try … I think it uses the port to something in the library …
    Is there any way to use an Arduino Uno Ethernet serial port to read … and ethernet output to publish the data in Modbus tcp?
    Regards from Spain

    • Martin says:

      Dear Mauricio
      The mudbus lib can be used only as slave. You can read out information from and write information to the Arduino.
      If you use rs232 to send data to the arduino, that data can be read by a Modbus master sending a request to the Arduino. The Modbus master can send data to the Arduino and you can let the Arduino send that data on rs232.
      But you can not use this library to send out stuff to other modbus slaves.
      Take care

  • Remi says:


    I am trying to use your library which look great.
    But I cant work out how to do.

    I try to read registers on a socomec device,
    I have the IP adress, the port number, the ID slave, the number of the register and so on. But I don’t understand how to do the coding part so I can get it on my arduino device.

    The socket i’d like to send (if i understand well the modbus/TCP protocol) is 00 01 00 00 00 06 05 03 C5 5E 00 02.

    Have you got any idea of the code i need to use to put on my arduino device to send the query to the socomec device and get a answer for him to read (on the screen) or store in a table?

    • Martin says:

      Sorry for my late reply. The mudbus library is making the Arduino listen to incoming requests so that other devices can read from and write to the Arduino. You cannot use this library to read from or write to another device.
      You can for example write some code to read some value from a sensor and put that value into a memory location. Mudbus can make this memory location readable from Ethernet.

  • Sadettin Karaman says:

    Hi I’m just using the mudbus library to exchange data. Is this possible to while I’m using this library to create another server in the same ip but in different ports?

    • Martin says:

      To double it up… I think the code needs a major rewrite. I don’t think it is easy with the limited memory of the arduino…

    • Simon says:

      System with the watch modscad32
      After a period of time gives timeout error
      I could not find any solution with easy access.
      Arduino Uno R3 + Arduino Ethernet Shield Wiznet W5100
      attached screenshot

      • Martin says:

        Impossible to say… Maybe use wireshark to se what happens?
        I have now 15 temp/hum loggers based on arduino ethernet poe sampled every 10s 24/7 without any timeouts… I did some testing with high sample rate and it worket ok with something like 25 mS if I remember correctly.

  • gdpeng it says:

    great work, Martin….
    I just entered Proview Forum.
    My goal is having Arduino acting as a ModbusTCP distributed I/O (with yr relay and possibly other specialized board).
    And A raspi or other ARM mini board acting as the minimumu-needed-to-run Proview runtime.

    Are you also on this idea ?

  • marc says:

    Hi Martin,
    I am sorry I am spamming but I want to ask you something.
    Please, when you have time, can you have a look at my post on the Proview forum and tell me if you are interested?
    Greetings, Marc

  • Marc says:

    Thanks for sharing, Martin.
    Great project.


  • Martin says:

    Dear Jens
    I think it would work with some addition of an address offset in the Mudbus software to fit the address map of the wago controller.
    It would be interesting to make a version of Mudbus and an example application in the Wago that is verified and publish it to the Arduino community.
    On the hardware side, I’m still working on the layout adding connector for Raspberry pie and an optional relay to control the power supply so I can power on/off the whole thing from the main controller. The processor will in that case be powered via the Ethernet cable PoE. I’m also working on the box and a total concept with runtime running on a Raspberry Pi when ever I can get it delivered to me.
    Having all these plans it is still a hobby project and I will publish the layout masks when I have tested the first prototype.

  • Jens says:

    It looks really nice.
    How far are you?
    When do you expect sales?
    I intend to apply it to modbus with a WAGO 750-841 Controller, should not it be possible?

    All the best

  • Martin says:

    Yes you can expand the tables as you like, but you have some memory restrictions because of the limited ram of the Arduino.
    The declarations in the Mudbus.h file are just memory arrays. It is up to the application to copy the contents of these to and from actual I/O pins or A/D or D/A converters. In the examples there is a file copy_in2out_mb that is copying just the memory arrays to each other so it looks like if the outputs where connected to inputs…
    These declarations works:
    #define MB_N_C_0x 100
    #define MB_N_I_1x 100
    #define MB_N_IR_3x 64
    #define MB_N_HR_4x 64
    These are in the Mudbus.h file.
    You can pull from my Gitorious repo.

  • Woza says:


    I was wondering if it is possible to read data from the arduino above the 0-15 range of the 4x register to read stored values that are not i/o related?

  • Gerald says:

    I could find this MUDBUS Code from Dee Wykoff on google, and now I am using it for a connection between an arduino for collecting measured data and a software called SICAM 230. (It will be a project for a final exam at evening school) It is working pretty good 😉

Leave a Reply

Your email address will not be published. Required fields are marked *

eighteen + = twenty seven