I need to send and receive data (integers representing values and status') between a small number of arduinos. What options are there? USB? I2C? Others? Examples (or links to examples)?
USB is not really an option - it is for connecting an Arduino to a PC.
I2C and SPI are options if the distances are very short - measured in centimetres.
For distances up to about 2 or 3 metres a simple wired serial connection could be used and for longer wired distances RS485 can be used.
Wireless is also an option, The cheap and effective nRF24L01+ modules will work over a range of about 20 or 30 metres depending on the surroundings (this is the system I am familiar with). For longer ranges the lower frequency HC12 modules would probably be suitable and for very long ranges LoRa can be used.
I'm not going to make centimeters, but less than a dozen meters (likely <5m).
I debate on wireless as I still would need to run power. (oh I can't wait for the day when we can transmit power wirelessly as well).
Ethernet? Overkill?
Looking at RS-485, has any one tried and had success with these modules?
I see I forgot to mention Ethernet - sorry.
I have not used those RS485 modules but I can't see why they would not work.
...R
adwsystems:
I'm not going to make centimeters, but less than a dozen meters (likely <5m).I debate on wireless as I still would need to run power. (oh I can't wait for the day when we can transmit power wirelessly as well).
Ethernet? Overkill?
Looking at RS-485, has any one tried and had success with these modules?
SparkFun Transceiver Breakout - RS-485 - BOB-10124 - SparkFun Electronics
Remember, it runs on 3.3 volts, so don't kill it with 5 volts.
Paul
Paul_KD7HB:
Remember, it runs on 3.3 volts, so don't kill it with 5 volts.Paul
I noticed that. Hopefully I will remember. I also notice the nRF24L01+ modules are 3.3V as well.
On that note, how do you make the nRF24L01+ work in a setup with more than just two devices?
adwsystems:
On that note, how do you make the nRF24L01+ work in a setup with more than just two devices?
This Simple nRF24L01+ Tutorial should help with that.
...R
In my experience, wired is more reliable. Probably you could use the simple wired serial connection Robin2 mentioned if you don't need lots of speed. At sub-maximum speeds this should easily span 5 meters.
I have successfully used RS-485. This kind of module. They're easy and inexpensive to get, easy to wire up, and easy to program. We ran them over twisted pair more than 300 meters, and although data integrity isn't 100%, it's really close. Simple checksum/retry protocol is sufficient. For less than 5 meters, I expect corruption would be negligible.
But there are other ways as well. LEDs and photo diodes if you want to go that route. Infrared if you don't want it visible.
Speakers or piezo units and microphones also work. Ultrasonic if you don't want to hear them. Mechanical switches with motors and string or wires or rods or belts.
I kind of glossed over the missing detail in
Robin2:
For distances up to about 2 or 3 metres a simple wired serial connection could be used...
Jimmus:
In my experience, wired is more reliable. Probably you could use the simple wired serial connection Robin2 mentioned if you don't need lots of speed. At sub-maximum speeds this should easily span 5 meters.
What simple serial connection would allow for multiple transmitters/receivers? Surely not RS-232. Simple straight TTL (0-5V)?
How many?
A Mega or Due will let you have 4 slaves and one master on TTL Serial. A Teensy 3.5 will give you up to 6 Serial ports.
Any more than that and you will have to have a multi-drop communication protocol like MODBUS. That also requires extra hardware at each Arduino.
Honestly once you get more than a few metres of wire, the wireless units cost less than the wire.
MorganS:
How many?
Not sure yet. At least 3, could easily expand to as many as 8 or 10. It could easily make sense to daisy chain the additional 6-8, rather than home runs.
The MODBUS protocol/software layer seems overkill. I don't see the need for the overhead. The RS-485 hardware layer and my own communication tactic (master send and master request-slave respond) would be more than sufficient.
As for wireless, I still have to run wire, just a few less conductors (one 3-wire cable @ $1/m for serial).
Ethernet cables are cheap and premade. So I'm still pondering ethernet as a possible solution, but wonder if it will have as much overhead as MODBUS.
MODBUS is extremely efficient. It was designed in the 1970s when individual bits were more valuable than an hour of programmer's time. A single Ethernet packet (assuming TCP/IP) is probably 1000 times bigger than MODBUS.
RS485 over twisted-pair CAT5 cable will be very good too. You still need some way of addressing the slaves.
I know I should consider both the hardware and software aspects. If I go RS-485 and there is a good, complete, and easy to use library for MODBUS then I might consider it.
Right now I am focusing on finding any and all physical options for communicating between multiple Arduinos (with the primary communication path resembling master-slave, I don't see a reason to have some of the slaves talking to each other)
Possible:
-RS-485
-TTL Serial (5 devices per serial port)
-Ethernet
-Wireless (technically in; but not likely, since this won't be battery powered and wires must be run any way)
Out:
-RS-232
-USB
-I2C (distance)
-SPI (distance)
Any other options?
I had good luck with Ethernet as well. The protocol is a bit more complex, so the libraries are bigger if I remember right. But the library worked flawlessly and was an easy connection to a PC. Seems a bit heavy for Arduino to Arduino though.
Have you ruled out wireless router?
adwsystems:
What simple serial connection would allow for multiple transmitters/receivers? Surely not RS-232. Simple straight TTL (0-5V)?
You are asking questions without stating your requirement. The specification for what is needed should come first.
I am building a series of slave modules (Atmega 328) that will be controlled from a Master (Mega) over a daisy-chained serial link from Serial1 on the Mega. The total end-to-end distance will be about 2 metres.
...R
The question is posed in post #8 for clarification on comments in post #2 and #7.
It has nothing to do with requirements. I want to know what is meant by “a simple serial connection”.
adwsystems:
It has nothing to do with requirements. I want to know what is meant by “a simple serial connection”.
I have found that it is useful to focus answers on the requirements because in most cases when I did not the conversation rambled around in a huge circle and got nowhere until the requirements were clearly established and proved that most of the long conversation had been a completely irrelevant for solving the actual problem.
My sense of "simple serial connection" between two Arduinos is GND to GND, Rx to Tx and Tx to Rx.
...R
For most posts and problems posted here I can see where you are coming from. Many of the people asking questions here seem to have little to no experience designing and executing a project. I can design and execute a project just fine. My problem is trying to increase the slope of my Arduino learning curve. My issue is knowing or finding what is readily available for the Arduino platform. Rather than reinventing the wheel.
In 20+ years of posting on forums like this, I have learned to make sure to focus my original post in order for the responses to stay on track.
I am not (yet) looking for help designing the entire project. On here that would become design-by-committee, and would never get done. At this time I’m just looking for Arduino compatible and available options for connecting multiple Arduinos for the purpose of sending small amounts of data.
Even this small aside is veering from the OP but I feel it is pertinent in order for those with the answers and information (like yourself) to know what I’m looking for and which direction I would like the conversation to head.
At this time the list in post #12 seems complete. I need to decide on the layout of the modules. I will start on a block diagram and post for comments and suggestions in a new thread.
Perhaps I had incorrectly inferred from your Reply #8 that you were gravitating towards simple serial as your solution.
...R
Nah. I read or misread the statement in post #2 and until someone else referred to it, I didn’t realize it. Then I wasn’t sure of what type of connection you were speaking.
Direct serial is an option but I wonder on the reliability of it over a few meters. Additionally, it directly exposes the Arduino pins to the outside world. Whereas any other method has a transceiver chip to act as a buffer between the nasty outside world and the sensitive Arduino pins. Though cheap, probably not a good solution this time.