I am programing 3 Arduino Unos to communicate with one another using RS-485 and Modbus communication protocol. 2 of the Arduinos are programmed as slaves and the other one is the master.
One of the slaves has 5 switches connected to it and the other has 5 relays. When a switch is flipped on, a light bulb connected to the relay (on the other slave) will turn on.
I have the programs for both slaves working. Now, I'm programing the master.
I've been using example codes online to learn how to program a Modbus device. Some of the example codes for the ModbusMaster.h library, shows:
node.begin(1, Serial);
The comments say that this line on code is setting slave ID to 1. However, to my understanding, a modbus master does not need a slave ID.
Can someone please explain to me what this function is doing.
If i have 3 Arduinos communicating with one another using RS-485 and Modbus, should i use this function in the master's program in void setup() as followed.
void setup()
{
pinMode(MAX485_RE_NEG, OUTPUT);
pinMode(MAX485_DE, OUTPUT);
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
Serial.begin(115200); //Baud Rate as 115200
node.begin(1, Serial); //Slave ID 1
node.begin(2, Serial); //Slave ID 2
node.preTransmission(preTransmission); //Callback for configuring RS-485 Transreceiver correctly
node.postTransmission(postTransmission);
}
For clarification, the master does not have a slave ID and the other two Arduinos slave IDs are 1 and 2.