Arduino MODBUS TCP comunication with LOGO! SIEMENS PLC

Hello guys, I am trying to connect arduino mega with ethernet shield to SIEMENS LOGO! plc via the modbus protocol, using the ArduinoModbus library.

I need help from someone who has more experience with this protocol. I already meke the Modbus slave with eight outputs. It works fine but after i reconnect the slave or shut down the power source or if i press reset button, communication breaks and it will never ever start again. I have to upload a program and then it works. Nothing else helps (reset, shut down and turn on, reconnect ethernet cable) I have to upload the arduino program again....

The second problem is that I am not able to transfer data from the arduino into the plc. I tried a lot of different ways and adres.

Here is the program:

#include <SPI.h>
#include <Ethernet.h>

#include <ArduinoRS485.h> 
#include <ArduinoModbus.h>

uint16_t analog1 = 0;
uint16_t analog2 = 0;
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 0, 4);
EthernetServer ethServer(510);
ModbusTCPServer modbusTCPServer;

#define Pin00 2
#define Pin01 3
#define Pin02 4
#define Pin03 5
#define Pin04 6
#define Pin05 7
#define Pin06 8
#define Pin07 9
#define Pin08 A0
#define Pin09 11
#define Pin10 12
#define Pin11 13



void setup() {
  
  Ethernet.init(10);  // Most Arduino shields
 
 
  Ethernet.begin(mac, ip);
  
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    while (true) {
      delay(1); 
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
  }
  
  ethServer.begin();
  if (!modbusTCPServer.begin()) {
    while (1);
  }
  

  pinMode(Pin00, OUTPUT);
  pinMode(Pin01, OUTPUT);
  pinMode(Pin02, OUTPUT);
  pinMode(Pin03, OUTPUT);
  pinMode(Pin04, OUTPUT);
  pinMode(Pin05, OUTPUT);
  pinMode(Pin06, OUTPUT);
  pinMode(Pin07, OUTPUT);
  pinMode(Pin08, OUTPUT);
  pinMode(Pin09, OUTPUT);
  pinMode(Pin10, OUTPUT);
  pinMode(Pin11, OUTPUT);
  
  digitalWrite(Pin00, LOW);
  digitalWrite(Pin01, LOW);
  digitalWrite(Pin02, LOW);
  digitalWrite(Pin03, LOW);
  digitalWrite(Pin04, LOW);
  digitalWrite(Pin05, LOW);
  digitalWrite(Pin06, LOW);
  digitalWrite(Pin07, LOW);
  digitalWrite(Pin08, LOW);
  digitalWrite(Pin09, LOW);
  digitalWrite(Pin10, LOW);
  digitalWrite(Pin11, LOW);
  
  // configure a single coil at address 0x00
  modbusTCPServer.configureCoils(0x00,8);
  modbusTCPServer.configureInputRegisters(0x08, 1);
}






void loop() {
  
  EthernetClient client = ethServer.available();
  
  if (client) {
    modbusTCPServer.accept(client);
    while (client.connected()) {
      modbusTCPServer.poll();
      updateSTAT();
    }
  }
}


void updateSTAT() {
  int coilValue00 = modbusTCPServer.coilRead(0x00);
  int coilValue01 = modbusTCPServer.coilRead(0x01);
  int coilValue02 = modbusTCPServer.coilRead(0x02);
  int coilValue03 = modbusTCPServer.coilRead(0x03);
  int coilValue04 = modbusTCPServer.coilRead(0x04);
  int coilValue05 = modbusTCPServer.coilRead(0x05);
  int coilValue06 = modbusTCPServer.coilRead(0x06);
  int coilValue07 = modbusTCPServer.coilRead(0x07);
 
  analog1 = analogRead(A1);

  modbusTCPServer.holdingRegisterWrite(0x08, analog1);
 
  
  if (coilValue00 == HIGH) {
    digitalWrite(Pin00, HIGH);
  } else {
    digitalWrite(Pin00, LOW);
  }

  if (coilValue01 == HIGH) {
    digitalWrite(Pin01, HIGH);
  } else {
    digitalWrite(Pin01, LOW);
  }

  if (coilValue02 == HIGH) {
    digitalWrite(Pin02, HIGH);
  } else {
    digitalWrite(Pin02, LOW);
  }

  if (coilValue03 == HIGH) {
    digitalWrite(Pin03, HIGH);
  } else {
    digitalWrite(Pin03, LOW);
  }

   if (coilValue04 == HIGH) {
    digitalWrite(Pin04, HIGH);
  } else {
    digitalWrite(Pin04, LOW);
  }

   if (coilValue05 == HIGH) {
    digitalWrite(Pin05, HIGH);
  } else {
    digitalWrite(Pin05, LOW);
  }

   if (coilValue06 == HIGH) {
    digitalWrite(Pin06, HIGH);
  } else {
    digitalWrite(Pin06, LOW);
  }

   if (coilValue07 == HIGH) {
    digitalWrite(Pin07, HIGH);
  } else {
    digitalWrite(Pin07, LOW);
  }

}

And now about the connection with plc. I am not sure if it is the right method to connect these devices together. But I am using NetworkOutput with a manually defined address.

I also set an input manually because no one of the output registers works via the modbus connection table of the arduino.

So I know that MODBUS uses an IP address and port to connect the device but I am not sure how this modbus address works. You can see in my program that I made 8 coils which start with address 0x00
if i understand it right, it means that I created Coils at adresses 0x00 - 0x07 each one, one bite.

I don't know why but there is an offset (by 1) in the modbus address, so if i want to call 0x00 i have to call 0x01. I used address from 1 to 8 in siemens plc to connect outputs located on address 0x00 - 0x07

After I added a holding register to address 0x08 I am not able to read them in SIEMENS PLC.

So 2 main problems:
Works only after fresh uploaded software.
Holding registers are not accessible from PLC

I tried to respect this table but it didn't work.

This also didnt work.

And this is not working holding register.

1 Like

Did you make a progress? I would like to try it also.

2 Likes

I'm in it but I'm going anyway

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.