Skip to content

Commit

Permalink
update modbus arduino example
Browse files Browse the repository at this point in the history
  • Loading branch information
lmtreser committed Oct 4, 2024
1 parent 7380e8d commit b7d0872
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion dispositivos/modbus/Arduino/ModbusRTUSlave_SS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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
Expand Down Expand Up @@ -39,16 +39,19 @@ const uint8_t modbusId = 2;
SoftwareSerial mySerial(rxPin, txPin);
ModbusRTUSlave modbus(mySerial, dePin);

uint16_t inputRegisters[1];
bool coils[1];

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

void loop() {

inputRegisters[0] = random(0, 30);
modbus.poll();
digitalWrite(coilPin, coils[0]);
}

0 comments on commit b7d0872

Please sign in to comment.