So i have a Windows form application which is connected to my 'MASTER' Arduino with a USB cable. I can write to the port and then execute operations on the Arduino accordingly.
My master Arduino is connected to 3 other 'SLAVE' Arduino's via TTL-RS485 modules.
My question is - How can share the serial communication between all the Arduino's so that if I send a command via the PC that every Arduino receives the command?
Also, the SLAVES need to send back data to the PC with the serial communication.
you can have multiple slaves listening on their TTL-RX line connected to the TTL-TX line of your PC. that will work, so all the slaves can get the message
but you can't have all the Tx joined together and sending data back to the Rx of your PC.
Adding a diode on each Tx line and a pull-up can probably do the trick so that you don't destroy your Tx pins but you also need to solve the issue that only one slave will be able to talk at a given time.
@mr_tropica, when using RS485 with multiple slaves, slaves are identified by an ID. So when you send a message like ID data the slave for who it's intended will pick it up while the others ignore it. You're free to use a common ID (e.g. 0) that all slaves will listen to.
To get data from a slave, you need to use polling and poll each slave in sequence using the unique ID.
It's not a multi-master bus as required by a master PC and a master Arduino. This suggests to use different protocols between the PC and master Arduino and the master Arduino and its slaves. This suggests to me a full duplex serial protocol between PC and master Arduino and something different (I2C...) to the slaves. Except if a Mega is used with multiple Serial ports.
Humm, use ESP32's with WiFI and MQTT for comms. Install MQTT Broker, for free, onto the PC. On the PC use Node-Red as a traffic manager or wrote your own code.