Hello,
i have some trouble with the inital setup of my modus setup.
I want to connect an Arduino Uno to my mach3 via modbus to instal some external periphery.
- the mist sprayer and the pump
- feed override and start/stop
In my fist setup I only want to switch the LED (PIN13) on the UNO on and off using M7 and M9.
I write the Arduino code:
#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.
If I read the holding register I get back an 0000. If I write 0001 to it, the LED goes on, if I write 0000 to the holding register the LED goes off.
The the UNO and the modbus is correct.
But now I can do what I want, I can not switch the LED on by M7.
I think there es some error, but I did not find it. Please help my.
My M7
SetModOutput(0, 1)
And the ModBusConfigration Screen