#include #define MODBUS_SERIAL Serial1 #define MODBUS_BAUD 9600 #define MODBUS_CONFIG SERIAL_8N1 #define MODBUS_UNIT_ID 100 #if (defined(ARDUINO_NANO_RP2040_CONNECT) && !defined(ARDUINO_ARCH_MBED)) || defined(ARDUINO_NANO_ESP32) // These boards operate unsing GPIO numbers that don't correspond to the numbers on the boards. // However they do have D# values #defined to correct this. const int8_t buttonPins[2] = {D2, D3}; const int8_t ledPins[4] = {D5, D6, D7, D8}; const int8_t dePin = D13; #else // Other boards do not have D# values, and will throw an error if you try to use them. const int8_t buttonPins[2] = {2, 3}; const int8_t ledPins[4] = {5, 6, 7, 8}; const int8_t dePin = 13; #endif const int8_t knobPins[2] = {A0, A1}; ModbusRTUSlave modbus(Serial1); const uint8_t numInputRegisters = 2; uint16_t inputRegisters[2]; float wert; String scaleOutput; void setup() { Serial2.begin(9600); pinMode(knobPins[0], INPUT); pinMode(knobPins[1], INPUT); pinMode(buttonPins[0], INPUT_PULLUP); pinMode(buttonPins[1], INPUT_PULLUP); modbus.configureInputRegisters(inputRegisters, numInputRegisters); MODBUS_SERIAL.begin(9600, SERIAL_8N1); modbus.begin(MODBUS_UNIT_ID, MODBUS_BAUD, MODBUS_CONFIG); } void loop() { if (Serial2.available()) scaleOutput = Serial2.readStringUntil(B00001101); wert = scaleOutput.substring(1,5).toFloat(); inputRegisters[0] = (wert); inputRegisters[1] = (12345); modbus.poll(); }