Skip to content

Instantly share code, notes, and snippets.

@paolocavagnolo
Created November 14, 2020 16:53
Show Gist options
  • Save paolocavagnolo/e3c50ca65e479a7f72b06fcc18a16e36 to your computer and use it in GitHub Desktop.
Save paolocavagnolo/e3c50ca65e479a7f72b06fcc18a16e36 to your computer and use it in GitHub Desktop.
modbus with CONTROLLINO mega after modifying a modbus library, see here https://github.com/CONTROLLINO-PLC/CONTROLLINO_Library/issues/36
#include <Controllino.h>
#include <modbus.h>
#include <modbusDevice.h>
#include <modbusRegBank.h>
#include <modbusSlave.h>
modbusDevice regBank;
modbusSlave slave;
void setup() {
regBank.setId(1);
pinMode(CONTROLLINO_RS485_TX, OUTPUT);
pinMode(CONTROLLINO_RS485_RX, INPUT);
pinMode(CONTROLLINO_RS485_nRE, OUTPUT);
pinMode(CONTROLLINO_RS485_DE, OUTPUT);
regBank.add(1);
regBank.add(2);
regBank.add(3);
slave._device = &regBank;
slave.setBaud(19200);
}
void loop() {
regBank.set(1, digitalRead(CONTROLLINO_A10));
regBank.set(2, digitalRead(CONTROLLINO_A11));
digitalWrite(CONTROLLINO_D0,regBank.get(3));
slave.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment