Created
November 14, 2020 16:53
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 = ®Bank; | |
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