DesignSpark Electrical Logolinkedin
Menu Search
Ask a Question

Problem with modbus tcpip

Hi, I'm building an automation in which I use the Siemens IOT 2020, this must communicate with devices using the ModbusTCPIP protocol.
I managed to make the network work using the libraries made available to the Arduino IDE.
I can not get the Modbus to work
in qando I do the test using modscan 32 mi from the time out error.
I tried to use those found on the net but they do not work.

The code I try is this:

#include <Mudbus.h>

#include <Ethernet.h>
// the sensor communicates using SPI, so include the library:
#include <SPI.h>

// assign to MAC address for the ethernet controller.
// fill in your address here:
byte mac [] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
// assign an IP address for the controller:
IPAddress ip (192.168,200,210);
IPAddress gateway (192.168,200,254);
IPAddress subnet (255, 255, 255, 0);

// Initialize the Ethernet server library
// with the IP address and you want to use
// (port 80 is default for HTTP):
EthernetServer server (5002);

Mudbus Mb;

void setup () {
  // start the SPI library:
  SPI.begin ();

  // start the Ethernet connection and the server:
  Ethernet.begin (mac, ip);
 server.begin ();

  Serial.begin (9600);
Mb.R [0] = 10;
  Mb.R [1] = 100;
  Mb.R [2] = 20;
  Mb.R [3] = 30;
  delay (1000);



void loop () {
  // check for a reading no more than once a second

Mb.Run ();
  // Analog inputs 0-1023
  Mb.R [0] = analogRead (A0); // pin A0 to Mb.R [0]
  Mb.R [1] = analogRead (A1);
  Mb.R [2] = analogRead (A2);
  Mb.R [3] = analogRead (A3);
  Mb.R [4] = analogRead (A4);
  Mb.R [5] = analogRead (A5);


Thank you and greetings
0 Votes


[Comment was deleted]

[Comment was deleted]

September 18, 2018 10:26

I have not used the Arduino Sketch Modbus library you mentioned, in my testing I used a Modbus Module within Node-Red, I found this far more useful and you get all the benefits of Node-Red as well. Is there a reason you need to use it within an Arduino Sketch ?

0 Votes

[Comment was deleted]