Communication Arduino Siemens logo 8 Modbus tcp/ip

Hello everyone,

I am new here to the forum and to arduino.
I would like to learn more about communication between arduino and Siemens logo 8 via modbus tcp ip.
Does anyone have a simple example of this?
I would like to learn to switch a marker flag high or low.

Thanks in advance

Greetings Peter

@patj88, your topic has been moved to a more suitable location on the forum. Introductory Tutorials is for tutorials that e.g. you write, not for questions. Feel free to write a tutorial once you have solved your problem :wink:

Anything in here that might be of help? arduino Siemens logo 8 - Google Search

I used a program fl prog to create arduino code. With this I was able to make a working sketch.
but lost this one. And searching a simple sketch as an example to learn from. Sending a coil high or low.

greetz

At eps8266modbus I found this example.
But it is not clear to me how I can indicate these with the addresses to my Siemend Logo.

/*
  Modbus-Arduino Example - Test Led (Modbus IP ESP8266)
  Control a Led on GPIO0 pin using Write Single Coil Modbus Function 
  Original library
  Copyright by André Sarmento Barbosa
  http://github.com/andresarmento/modbus-arduino

  Current version
  (c)2017 Alexander Emelianov (a.m.emelianov@gmail.com)
  https://github.com/emelianov/modbus-esp8266
*/

#ifdef ESP8266
 #include <ESP8266WiFi.h>
#else //ESP32
 #include <WiFi.h>
#endif
#include <ModbusIP_ESP8266.h>

//Modbus Registers Offsets
const int LED_COIL = 100;
//Used Pins
const int ledPin = 0; //GPIO0

//ModbusIP object
ModbusIP mb;
  
void setup() {
  Serial.begin(115200);
 
  WiFi.begin("your_ssid", "your_password");
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
 
  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  mb.server();

  pinMode(ledPin, OUTPUT);
  mb.addCoil(LED_COIL);
}
 
void loop() {
   //Call once inside loop() - all magic here
   mb.task();

   //Attach ledPin to LED_COIL register
   digitalWrite(ledPin, mb.Coil(LED_COIL));
   delay(10);
}

Hello,

I found how to make connection between my Logo and an ESP8266.
It serialprints a message and when i disconnect the ethernetcable of the Logo the message stops.

Right now i am stuck on activating a coil:

COIL1VALUE stays 0
val = 1 when D0 is high.

void loop() {

   mb.task();

    if (mb.isConnected(remote)) {   
            Serial.println("connectie met logo");
              delay(1000); 

                 
     
val=digitalRead(D0);       
digitalWrite(val,mb.Coil(COIL1));  
COIL1VALUE = digitalRead(COIL1);
Serial.println(COIL1VALUE);
Serial.println(val);
    
    }
   
    
     
 else {
    mb.connect(remote);        
  }
  
  delay(10);                  
}

Thanks in advance for helping me.

Hi,
That's basic example to set LOGO output via Arduino ModbusTCP

#if defined(ESP8266)
 #include <ESP8266WiFi.h>
#elif defined(ESP32)
 #include <WiFi.h>
#else
#error "Unsupported platform"
#endif
#include <ModbusTCP.h>

const int REG = 0;               // Modbus Hreg Offset
IPAddress remote(192, 168, 30, 18);  // Address of Modbus Slave device

ModbusTCP mb;  //ModbusTCP object

void setup() {
  Serial.begin(115200);
 
  WiFi.begin("SSID", "PASSWORD");
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
 
  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  mb.client();
}

void loop() {
  if (mb.isConnected(remote)) {   // Check if connection to Modbus Slave is established
    uint16_t trans = mb.writeCoil(remote, REG, true);  // Initiate Read Hreg from Modbus Server
    while(mb.isTransaction(trans)) {  // Check if transaction is active
      mb.task();
      delay(10);
    }
  } else {
    mb.connect(remote);           // Try to connect if no connection
  }
  delay(100);
}