From 87ce65ea74c5b51626f2b0c1c4259beeadf51d36 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Thu, 29 Dec 2022 10:33:04 +0100 Subject: [PATCH 1/5] Explicitly list supported architectures: avr,megaavr,samd,mbed_nano,mbed_portenta. (#105) As those are also verified by CI build. --- .github/workflows/compile-examples.yml | 4 ++-- library.properties | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index b344943..73efe26 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -51,10 +51,10 @@ jobs: - fqbn: arduino:samd:mkrwifi1010 ethernet: true nina: true - - fqbn: arduino:mbed:nano33ble + - fqbn: arduino:mbed_nano:nano33ble ethernet: false nina: false - - fqbn: arduino:mbed:envie_m7 + - fqbn: arduino:mbed_portenta:envie_m7 ethernet: false nina: false diff --git a/library.properties b/library.properties index 02761ad..fe06616 100644 --- a/library.properties +++ b/library.properties @@ -6,6 +6,6 @@ sentence=Use Modbus equipment with your Arduino. paragraph=Using TCP or RS485 shields, like the MKR 485 Shield. This library depends on the ArduinoRS485 library. category=Communication url=https://www.arduino.cc/en/ArduinoModbus/ArduinoModbus -architectures=* +architectures=avr,megaavr,samd,mbed_nano,mbed_portenta includes=ArduinoModbus.h depends=ArduinoRS485 From b7270941e3d5eb405db86e0445bcd846527db002 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 4 Jan 2023 10:00:21 +0100 Subject: [PATCH 2/5] Drop official support for AVR for this library. (#106) This is imho necessary since even one of our own examples does not link anymore, due to the required memory exceeding the available ressources of the ATMEGA328P based Arduino Nano. --- .github/workflows/compile-examples.yml | 6 ------ library.properties | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 73efe26..e557383 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -39,12 +39,6 @@ jobs: matrix: board: - - fqbn: arduino:avr:nano - ethernet: true - nina: false - - fqbn: arduino:avr:leonardo - ethernet: true - nina: false - fqbn: arduino:megaavr:uno2018:mode=off ethernet: true nina: true diff --git a/library.properties b/library.properties index fe06616..40eebe3 100644 --- a/library.properties +++ b/library.properties @@ -6,6 +6,6 @@ sentence=Use Modbus equipment with your Arduino. paragraph=Using TCP or RS485 shields, like the MKR 485 Shield. This library depends on the ArduinoRS485 library. category=Communication url=https://www.arduino.cc/en/ArduinoModbus/ArduinoModbus -architectures=avr,megaavr,samd,mbed_nano,mbed_portenta +architectures=megaavr,samd,mbed_nano,mbed_portenta includes=ArduinoModbus.h depends=ArduinoRS485 From baacd3ad0ecb349aaaf516a57f73e121617f444e Mon Sep 17 00:00:00 2001 From: Giampaolo Mancini Date: Tue, 10 Jan 2023 16:07:38 +0100 Subject: [PATCH 3/5] Add CI for Opta --- .github/workflows/compile-examples.yml | 3 +++ library.properties | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index e557383..fe29687 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -51,6 +51,9 @@ jobs: - fqbn: arduino:mbed_portenta:envie_m7 ethernet: false nina: false + - fqbn: arduino:mbed_opta:opta + ethernet: true + nina: false # Make board type-specific customizations to the matrix jobs include: diff --git a/library.properties b/library.properties index 40eebe3..adacb35 100644 --- a/library.properties +++ b/library.properties @@ -6,6 +6,6 @@ sentence=Use Modbus equipment with your Arduino. paragraph=Using TCP or RS485 shields, like the MKR 485 Shield. This library depends on the ArduinoRS485 library. category=Communication url=https://www.arduino.cc/en/ArduinoModbus/ArduinoModbus -architectures=megaavr,samd,mbed_nano,mbed_portenta +architectures=megaavr,samd,mbed_nano,mbed_portenta,mbed_opta includes=ArduinoModbus.h depends=ArduinoRS485 From 4be4d044b851311cf976ba104bca0fcc2cfac8d4 Mon Sep 17 00:00:00 2001 From: Giampaolo Mancini Date: Tue, 10 Jan 2023 16:21:11 +0100 Subject: [PATCH 4/5] Add example for RTU with RS485 parameters --- .../ModbusRTUClientParameters.ino | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 examples/RTU/ModbusRTUClientParameters/ModbusRTUClientParameters.ino diff --git a/examples/RTU/ModbusRTUClientParameters/ModbusRTUClientParameters.ino b/examples/RTU/ModbusRTUClientParameters/ModbusRTUClientParameters.ino new file mode 100644 index 0000000..91b9ec4 --- /dev/null +++ b/examples/RTU/ModbusRTUClientParameters/ModbusRTUClientParameters.ino @@ -0,0 +1,75 @@ +/* + Modbus RTU Client Parameters + + This sketch is the same as ModbusRTUClientToggle and shows how to set + a few RS485 parameters. + + Circuit: + - Arduino Opta + - GND connected to GND of the Modbus RTU server + - A(-) connected to A of the Modbus RTU server + - B(+) connected to B of the Modbus RTU server +*/ + +#include // ArduinoModbus depends on the ArduinoRS485 library +#include + +constexpr auto baudrate { 19200 }; + +// Calculate preDelay and postDelay in microseconds as per Modbus RTU Specification +// +// MODBUS over serial line specification and implementation guide V1.02 +// Paragraph 2.5.1.1 MODBUS Message RTU Framing +// https://modbus.org/docs/Modbus_over_serial_line_V1_02.pdf +constexpr auto bitduration { 1.f / baudrate }; +constexpr auto wordlen { 9.6f }; // try also with 10.0f +constexpr auto preDelayBR { bitduration * wordlen * 3.5f * 1e6 }; +constexpr auto postDelayBR { bitduration * wordlen * 3.5f * 1e6 }; + +void setup() { + Serial.begin(9600); + while (!Serial); + + Serial.println("Modbus RTU Client Toggle w/ Parameters"); + + RS485.setDelays(preDelayBR, postDelayBR); + + // start the Modbus RTU client in 8E1 mode + if (!ModbusRTUClient.begin(baudrate, SERIAL_8E1)) { + Serial.println("Failed to start Modbus RTU Client!"); + while (1); + } +} + +void loop() { + // for (slave) id 1: write the value of 0x01, to the coil at address 0x00 + if (!ModbusRTUClient.coilWrite(1, 0x00, 0x01)) { + Serial.print("Failed to write coil! "); + Serial.println(ModbusRTUClient.lastError()); + } + + // wait for 0.5 second + delay(500); + + // for (slave) id 1: write the value of 0x00, to the coil at address 0x00 + if (!ModbusRTUClient.coilWrite(1, 0x00, 0x00)) { + Serial.print("Failed to write coil! "); + Serial.println(ModbusRTUClient.lastError()); + } + + // wait for 0.5 second + delay(500); + + auto coil = ModbusRTUClient.coilRead(0x02, 0x00); + + if (coil < 0) { + Serial.print("Failed to read coil: "); + Serial.println(ModbusRTUClient.lastError()); + } else { + Serial.print("Coil: "); + Serial.println(coil); + } + + // wait for 0.5 second + delay(500); +} From 7df67be4ca1b0501c39007431dce1e2d3d2fc15a Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 16 Jan 2023 11:43:25 +0100 Subject: [PATCH 5/5] Release 1.0.8. --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index adacb35..4a076b3 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoModbus -version=1.0.7 +version=1.0.8 author=Arduino maintainer=Arduino sentence=Use Modbus equipment with your Arduino.