Multiple Arduino Connection

Newbie here! Feel free to correct me if I'm wrong :)

Did my research and found 3 possible solutions for multiple arduino connection 1. Serial Port - use tx and rx - no clock; devices need to agree on data rate - a start and stop bit is added to each frame [which affects data] 2. SPI - use four lines (miso, mosi, sck, csn where n requires 1 i/o pin) - only 1 master 3. I2C - use sda and scl - add extra bit [ack] to frame - multi master system - support upto 1008 slave devices?

I'll be connecting a lot of motors and sensors so I'm going to need more than 2 arduinos.

What connection should I use? Serial communication only support 2 arduinos but I've seen others using it to connect even 4. Is it advisable? What are the other pros and cons? If I'll be using I2C, what does 24LC256 do? Is it for data storage only? Is it needed if I'll be controlling multiple arduino?

I'll be connecting a lot of motors and sensors so I'm going to need more than 2 arduinos.

No, use a port expander or shift registers to give you more I/O.

It is a classic beginners mistake to think you need more processors when you only need more I/O. If you use more processors you get a very messy inefficient solution that is hard to code. Either get a Mega with more I/O built in or a chip like the 23017 ( I2C ) or 23S17 ( SPI ) port expander.

what does 24LC256 do? Is it for data storage only?

Link broken? It is an I2C memory chip for data storage only nothing else.

Is it needed if I'll be controlling multiple arduino?

No, but then you won't be controlling multiple Arduinos will you. ;)

Grumpy_Mike: It is a classic beginners mistake to think you need more processors when you only need more I/O. If you use more processors you get a very messy inefficient solution that is hard to code.

Amen to that!

The only justification for using multiple processors is when the I/O is geographically distributed and you wish to minimise the length of data paths.

In which case you need to start building network protocol stacks. Do-able but starts to occupy significant program space and processing.

Or when the IO is processor intensive and you want to offload the job, not an issue here I would think.


Rob

Grumpy_Mike: It is a classic beginners mistake to think you need more processors when you only need more I/O. If you use more processors you get a very messy inefficient solution that is hard to code. Either get a Mega with more I/O built in or a chip like the 23017 ( I2C ) or 23S17 ( SPI ) port expander.

Are you talking about this one MCP23017? Could you teach me how to connect it to the arduino?

Paul__B: The only justification for using multiple processors is when the I/O is geographically distributed and you wish to minimise the length of data paths.

Thank you! +Karma points to both of you :)

So... I'm thinking of expanding my arduino's IO but I still want to use multiple arduino. I want my arduinos to communicate in 5 meter distance. How will you then answer my first questions?

using an expander and connecting it to another arduino

I thought we had determined that multiple Arduinos were not required.

Do you really think they are? If so why so? And if they are then you don't need the IO expander chip.

If they are physically remote from each other then OK, but if you are worried about processing power it's unlikely (as a beginner) that you will trip over that, and if you do it's easier to get a more powerful Arduino, say a Due.

EDIT: I see your post changed.

I want my arduinos to communicate in 5 meter distance.

Technically 5M is to far for I2C or SPI, that said people do use I2C over that distance and more even in it's standard form, certainly with buffer/driver chips. Likewise for SPI, it depends on the speed required.

RS485 over async serial would be my preferred option, but you will have to DIY a comms protocol, that is not easy if it's to be reliable.


Rob

Graynomad: If they are physically remote from each other then OK, but if you are worried about processing power it's unlikely (as a beginner) that you will trip over that, and if you do it's easier to get a more powerful Arduino, say a Due.

Sorry, sir, I got lost on the "...if you are worried about processing power". What do you mean? External Power supply?

Graynomad: Technically 5M is to far for I2C or SPI, that said people do use I2C over that distance and more even in it's standard form, certainly with buffer/driver chips. Likewise for SPI, it depends on the speed required.

If I'll be changing the distance to 3 meters, will it be possible?

.if you are worried about processing power". What do you mean?

The number of computer instructions per second your project requires.

Are you talking about this one MCP23017? Could you teach me how to connect it to the arduino?

Top hit from google http://tronixstuff.com/2011/08/26/tutorial-maximising-your-arduinos-io-ports/

If I'll be changing the distance to 3 meters, will it be possible?

Close but no coconut.

Why not come clean and say what you want to do instead of asking for advice on what you think might be the solution. Another classic beginners mistake.

Grumpy_Mike: Why not come clean and say what you want to do instead of asking for advice on what you think might be the solution. Another classic beginners mistake.

We have this project that needs 3 arduinos: A, B & C; A will control B & C from 3 meter distance while B & C-- both have 10 inputs (sensors) and 10 outputs (motors)--will function depending on A's instruction. I'm sorry I forgot to type in the distance problem in my first post and that I'm asking weird questions instead of just stating the problem.

My teammate suggests we use the tx/rx for board communication but i think it's only limited to two device[internet information is confusing, i don't know what's right]. Also, I don't know more advantages of using I2C so I'm asking you guys.

and about the IO, we'll be using arduino uno. I'll be needing the expander right?

OK it still sounds overly complex. The simplest method would be to use serial but with a protocol. A ready built one is called DMX. http://playground.arduino.cc/Learning/DMX It is what is known as a multi-drop protocol. You assign an ID number to the other arduinos and only the arduino with the matching number responds to messages. So the master arduino addresses messages to the slave ones and it all goes over the same wires.

I was considering a DMX system for my own project, but I have learned that monitoring the DMX signal takes so much of the processing time from the Arduino, that I have little processing time to do much else. I am considering just purchasing a DMX to serial board ($25 kit from http://www.chromationsystems.com) . The system can also send, but only direction at a time.

If you only need to send out the data from A, DMX may be a solution for you. But, since DMX is a one-way communication system, your remote B&C units won't be able to send any data back to A.

Does your system need 2-way communication?

-Joe

($25 kit from http://www.chromationsystems.com)

Don't you just hate links that don't actually link to the product you are talking about.

but I have learned that monitoring the DMX signal takes so much of the processing time from the Arduino, that I have little processing time to do much else.

Now that is just plane silly, it all depends on how you write your code.

But, since DMX is a one-way communication system, your remote B&C units won't be able to send any data back to A.

This however is true. But in principle there is nothing stopping you from linking the last output back into the first input, and writing code that "passes" the baton of master to another device. When a master sees it's own message it does not pass it on.

Grumpy_Mike:

Don’t you just hate links that don’t actually link to the product you are talking about.

Here is a direct link to the product; http://www.chromationsystems.com/dmxtoserial.html

I said, " but I have learned that monitoring the DMX signal takes so much of the processing time from the Arduino, that I have little processing time to do much else."
You said, “Now that is just plane silly, it all depends on how you write your code.”

While I had not done a detail analysis of the program I will be creating, I know that reading quadrature input and DMX input are both time critical. There will be a PID control loop for the motor control as well. While I have seen some simplistic approaches for PID Motor control on Arduino, I know they can get complex from the Arduino’s perspective. I figured the $25 to eliminate one possible headache was a good buy.

-Joe

I figured the $25 to eliminate one possible headache was a good buy.

It would be if it did but I can't see it doing much for your project.

I know (because I have tried) that it's not necessary to connect Tx and Rx to the same device - you could talk to one and listen to another.

I wonder is it possible to join Tx on the master simultaneously to all of the Rx pins on the other devices and also connect all of the Tx pins on the other devices to the Rx pin of the master. And then have an arrangement (such as a unique ID for each slave) so that they all listen to the master and only one of the slaves responds at any one time.

I'm using a protocol like this for a master to communicate with several slaves by wireless, but I don't know if the parallel connection of several wired devices will screw up the signal even if they behave themselves.

...R

join Tx on the master simultaneously to all of the Rx pins on the other devices

That will work.

also connect all of the Tx pins on the other devices to the Rx pin of the master.

That won’t work without extra hardware and an appropriate protocol. The hardware can be just some diodes or line transceivers that allow disabling of the transmitter, eg RS-485 or TTL buffers like 74xx125/126.

The protocol would probably be exactly as you say.


Rob

This is just idle curiosity (or gathering some knowledge for a rainy day) ...

Why would it be necessary to isolate the Tx pins from each other with diodes - I presume you mean something like this

Tx1 ---->|-----| | Tx2 ----->|----| | Rx

Perhaps the Tx pins present a low impedance when they are NOT transmitting? (I don't know, just want to find out)

...R

That's close but the diodes are the wrong way around. As it is because the Tx pins idle high the Rx side will always be high and any Tx pins that go low will have no effect. The correct way is the first part of the pic below.

Perhaps the Tx pins present a low impedance when they are NOT transmitting?

Not normally, all I've seen are "push/pull" outputs, meaning they are either high or low. You can fool with things in registers to get hi-Z for low bits but now we're into the realm of software serial, I've never seen that option for hardware UART pins.

You can get that by using the Tx pin to control the enable of a buffer as shown in the second part of the drawing. I've used 74xx126 buffers here but the trick works with RS-485 transmitters as well.

All the above are good for what we're talking about here or indeed a protocol that allows slaves to transmit when they like as there is no damage caused by voltage-level contention.


Rob

Thanks Rob, I had forgotten that the Tx pins idle high.

...R