Skip to content

Commit

Permalink
add modbus software serial example
Browse files Browse the repository at this point in the history
  • Loading branch information
lmtreser committed Jul 31, 2024
1 parent 8fd8aa0 commit deee00e
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions dispositivos/modbus/ModbusRTUSlave_SS.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
ModbusRTUSlave Software Serial
Este ejemplo permite configurar y usar una placa Arduino UNO como dispositivo Modbus esclavo
mediante Software Serial.
Usa la biblioteca ModbusRTUSlave (https://github.com/CMB27/ModbusRTUSlave).
Circuito:
- Un LED integrado en el pin 13
- Serial RX a pin 10 - RO de un conversor MAX485/SN75176
- Serial TX a pin 11 - DI de un conversor MAX485/SN75176
Trama de datos (master):
ON: 02 05 00 00 FF 00 8C 09
OFF: 02 05 00 00 00 00 CD F9
Created: 2023-07-22
By: C. M. Bulliner
Modified: 2024-01-27
By: C. M. Bulliner
Modified: 2024-07-25
By: L. M. Treser
Last Modified: 2024-07-31
By: L. M. Treser
*/

#include <SoftwareSerial.h>
#include <ModbusRTUSlave.h>

const uint8_t coilPin = 13;
const uint8_t dePin = 7;
const uint8_t rxPin = 10;
const uint8_t txPin = 11;
const uint8_t modbusId = 2;

SoftwareSerial mySerial(rxPin, txPin);
ModbusRTUSlave modbus(mySerial, dePin);

bool coils[1];

void setup() {
pinMode(coilPin, OUTPUT);
modbus.configureCoils(coils, 1);
modbus.begin(modbusId, 38400);
}

void loop() {

modbus.poll();
digitalWrite(coilPin, coils[0]);
}

0 comments on commit deee00e

Please sign in to comment.