4 1 1 1 1 1 1 1 1 1 1 Rating 4.00 (4 Votes)

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

 

 

 

 

 

Reading some forum and blog about  some Modbus implementation for Arduino I feel my curiosity grow up about that..then I decided to test it on my on Arduino Mega 2560 board. I have to admit I've been successfully surprised! In few steps I saw a full running system that could represent a good source point to practice with Modbus Scada (as Proview). Following I wrote the steps I've done:

HW used:

  1. Arduino Mega 2560 
  2. Arduino Ethernet Shield R3

Software used:

  1. Arduino IDE 1.5.5 (free download  from Arduino main website)
  2. Arduino Modbus TCP server (Mudbus.h v.1.0)

 

Into Arduino IDE, first of all it's necessary to import the Mudbus.h library by "import library" command:

 

 

Then just type the following Sketch:

Arduino-Sketch_ModbusTCPSlave

 Into the sketch I've got:

  1. Mb.R[0]=Mb.R[1];                     mapping Modbus register 1 to register 0 (I wrote register 1 from an external client (ex. Modbus Poll)
  2. Mb.C[0]=digitalRead(In22);      mapping Digital Input 22 to Modbus Coil 0

 

Looking at Wireshark  log, it shows the Modbus (Modbus Poll) Client Interrogation by FC03 "read Holding Register" (10 Register starting from addr 1). Client IP =192.168.1.100 --> Destination (Arduino) =192.168.1.99

 

And this is the Arduino Modbus Server answer (Source 192.168.1.99 --> Destination192.168.1.100)

 

NOTE:

The Mudbus.h lib can manage just 2 data type: coil (r/w) and  register (r/w)

  • MB.R[x] = holding register [x]
  • MB.C[x]= coil [x]

This is the note from Google Code website:

A minimal Modbus TCP slave for Arduino. It has function codes 1(read coils), 3(read registers), 5(write coil), and 6(write register). It is set up to use as a library, so the Modbus related stuff is separate from the main sketch. The register and coil data is held as Mb.R[0-125] signed int and Mb.C[0-128] bool

Martin Pettersson Has furnished some changes for compatibility with Arduino 1.0. He also has a git repository at http://gitorious.org/mudbus and a website at http://siamect.com/test3/

Here following some useful link: