Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: **Modbus Communication** - Source Code NOT compiled for: ESP8266 NodeMCU V1.0 - Source Code created on: 2024-11-28 05:25:27 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Implement a Modbus communication protocol to */ /* enable data exchange between Arduino and Modbus- */ /* compatible devices, ensuring reliable and */ /* efficient control of connected components. */ /****** END SYSTEM REQUIREMENTS *****/ /* START CODE */ /****** DEFINITION OF LIBRARIES *****/ #include
//https://github.com/4-20ma/ModbusMaster //#include
// SoftwareSerial is not compatible with ESP8266 as it doesn't support multiple serial ports like Arduino /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ ModbusMaster node; // Define MODBUS_SERIAL to use the default Serial for ESP8266 #define MODBUS_SERIAL Serial void setup(void) { Serial.begin(115200); MODBUS_SERIAL.begin(115200, SERIAL_8N1, 14, 27); // IO14: RX, IO27: TX node.begin(1, MODBUS_SERIAL); // Initialize Modbus master with slave ID of 1 } void loop(void) { uint8_t result; // Variable to hold the result of the Modbus request uint16_t data[10]; // Buffer to hold the data result = node.readHoldingRegisters(0, 1); // Read one holding register from address 0 if (result == node.ku8MBSuccess) { // Check if the read was successful Serial.print("Flow Rate: "); Serial.println(node.getResponseBuffer(0)); // Print the value of the first holding register } else { Serial.print("Error reading Flow Rate: "); Serial.println(result); // Print the error code } delay(2000); // Wait for 2 seconds before the next loop iteration } /* END CODE */
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)