0

I have one PC running Visual Studio and a program that will be sending commands to Arduinos via serial COM Ports. So, in 11 Nano MCUs, I will have motor drivers L293D/L298N ICs, while in other Nanos I will have sensors.

What I would like to do is have a program in Visual Studio which sends commands via serial to actuate motors to each and every MCU on board. This is a robotic application and everything I mentioned above will be enclosed within the Humanoid.

Here are some examples of what I'm thinking of doing:

char data = Serial.read();
if (data == 'A') 
{
  digitalWrite(13, HIGH);
}

Or something like this:

servodata = Serial.read();
if (servodata == '1') // Single Quote! This is a character.
{
  SERVO.write(pos); 
}             

As you can see, Arduinos will have something like this running and waiting for Visual Studio to send commands via serial to one or multiple MCUs simultaneously. I'm thinking 30 char dividing/spiting that number across each Rx Arduino.

  • 1
    Does my answer address what you wanted to know? – Russell McMahon Sep 3 '15 at 8:47
5

It's not obvious what the exact query is but answering the subject line question:

You can easily multidrop connect multiple serial / RS232 COM ports by having all slave RX inputs and the master TX output on one line, and all slave TX outputs connected by an OR network to a single line to the master's RX input. The master 'talks' to all slaves at once. Each slave talks to only the master. Only one slave can usefully talk at once. Message destination assignment and slave-talking arbitration is carried out in software.

As shown below, the OR network at each slave can be as simple as a diode with cathode (bar side) to TX line and anode to common line to master RX. A single pullup resistor (or an internal pullup in the master on the RX line) pulls the line high when all slave TX lines are high.

This diagram shows how simple multidrop communications can be.
NB - As shown the diodes polarity is for true RS232 with logical 1 = low = negative.
When connecting directly between UART TTL lvel (5V/0V) outputs reverse the diodes.

Also, add a pullup from +5V to the Blue RX line to the master - 10k to 5V is probably OK.

Multidrop network for RS232
From here - Multidrop network for RS232.

When a slave TX pin is high its diode is "blocked" and it does not affect the common slave to master level. When any slave TX line goes low the common line is pulled low via its diode and the master sees the low. Normal RS232 COMs can occur between slave and master.

When the master sends all slaves see the transmission at once. A basic protocol must be established to allow messages to be handled by the intended recipient. This could consist of, e.g. sending an address word + command word or words. You can have a single slave act on a message or all slaves or a sunset, based on your addressing system.

The slave to master direction allows only one slave to send at one and you must ensure either that only one slave ever sends at a time and/or that collisions are able to be resolved.

Despite the obvious limitations of such a system it can work very well and is cheap and simple to implement. If there are many slaves the loadings should be checked so that e.g. the master TX is able to drive all slave RXs at once. As the circuit is unidirectional it is easy to add a basic buffer.

  • kind of very vaguely for a noob to understand some of your tech talk but im trying here – Frank Sep 3 '15 at 13:52
  • 1
    @Frank'sDesig'Nature - Look at the circuit above. Reverse the diode directions as you are using 0V/5V and not true RS232. Add a 10k from Master RX (blue line) to =%V. Try it. When Master drives TX line all slave RXs see the data. When any slave transmits the master sees the data but no slave does. – Russell McMahon Sep 4 '15 at 15:16
  • 1
    is there a reason why i cant just use one of those USB 3.0 5GBPS extension port? i men i use 2 usb port as in now from a extension of 4 usb all connected to one usb in my tablet and from there i open 2 terminals when i debug Tx and Rx from 2 diff arduinos with no issues SO why do i have to use this format? and not the usb way ? seems like a work out just to tx/rx data when the ide already does this with out extra crap like we been talking about? – Frank Sep 4 '15 at 18:43
  • [link]ebay.com/itm/111717351068 – Frank Sep 4 '15 at 19:10
2

RS-485 or RS-422 are the normal industrial ways of having one serial port talk to many devices, especially in noisy environments with lots of motors. It requires a driver chip for each device to get the right electrical interface.

RS-485 provides bi-directional communication if you want to receive data back from your remote nodes, and RS-422 provides "simplex" or uni-directional communication if you just want to blindly send commands with no feedback.

As for software, my ICSC library would probably be the easiest route to take - it allows you to address individual devices on an RS422 or RS485 bus and send commands to them.

  • @Russell McMahon thanks for your detail explanation despite the crazy typos i followed enough tho i think your under the impression that the slave arduino's will be tx anything back to the master "computer doing all the Tx" just want to be clear of this cuz you are talking a lot about slaves talking to anything when this will not be happening, the slave all they do is drive motors, thats is nothing else the have a sketch running that is looking for a parameter to be called serially using a long list of break/switch statements – Frank Sep 3 '15 at 13:35
  • this are the type of command i like to send to each Slave Serial.println('LT2|LP3|LM5|LR4|LI6'); or 'LT2|LP3|LM5|LR4|LI6' i want to send this type of block to each individual slave tho keep in mind that the above block is only to activate that slave and its speed, a additional block will follow with direction – Frank Sep 3 '15 at 13:53
  • like this guys ? !Valid XHTML – Frank Sep 3 '15 at 15:51
  • and if so i guess my next question would be if everything is tied common style how would the pc know who to send what to ? if send 'LT2|LP3|LM5|LR4|LI6' and i want that to be for one specific arduino i dont want all the arduinos to take those parameters in this example block 'LT2|LP3|LM5|LR4|LI6' the LT2 go's as follow (L is the mcu while the T is = to the pin on that mcu (pin D7 ect..) and the 2 is speed aka delay(2); ) so as you can see will all the other arduino who aren't 'L' won't use this data in the serial port? how would i addressing be done ? – Frank Sep 3 '15 at 15:59
  • The question about getting a particular Arduino to respond to a particular command is also asked by the OP here: How can I get a unique address for all my Arduino boards while in RS485? – Nick Gammon Sep 4 '15 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.