21
Modbus / Re: Need some help with the inital setup
« Last post by martin2day on October 26, 2025, 04:54:31 AM »image2
#include <ModbusRtu.h>
#define LED1_PIN 13 // Ausgang 1 (z. B. Luft)
#define LED2_PIN 12 // Ausgang 2 (z. B. Flüssigkeit)
Modbus slave(1, Serial, 0); // Slave-ID 1
uint16_t au16data[2]; // Zwei Register: 0 und 1
void setup() {
pinMode(LED1_PIN, OUTPUT);
pinMode(LED2_PIN, OUTPUT);
digitalWrite(LED1_PIN, LOW);
digitalWrite(LED2_PIN, LOW);
Serial.begin(115200);
slave.begin(115200);
}
void loop() {
slave.poll(au16data, 2); // 2 Register abfragen
// LED 1 steuern
digitalWrite(LED1_PIN, au16data[0] ? HIGH : LOW);
// LED 2 steuern
digitalWrite(LED2_PIN, au16data[1] ? HIGH : LOW);
}
I can test this with the Test Modbus.SetModOutput(0, 1) Dim Arduino
Set Arduino = CreateObject("Scripting.FileSystemObject")
Set Port = Arduino.CreateTextFile("COM5:", True)
Port.WriteLine "ON"
Port.Close