I am building a bunch of slave devices (Arduinos) that operate autonomously, but will report data back to a single raspberry pi and update their clocks from the pi's time.
I've only worked with one arduino using serial, but I would imagine that 20 arduinos needs a special solution. I don't know how to split serial, but I've also considered SPI and I2C. Would either of these be the way to go?
Given that there are 20 units, I don't think I should go with wifi as I fear there would be loss of connectivity often. I prefer a hardwired method.
EDIT: Also, these arduinos won't be close to each other. They will be spread out, no more than 30 feet from the pi.
-
I2C works with 20 slaves. With SPI you'd at least have to use some generic GPIO pins as address lines. Both should do.Ghanima– Ghanima ♦2016年04月08日 15:28:29 +00:00Commented Apr 8, 2016 at 15:28
-
@Ghanima can data be written in both directions? Can the slave report 'all good' or 'error on pin 1', for example? Also, the furthest arduino will be 30 feet from the pi.pekasus– pekasus2016年04月08日 15:49:31 +00:00Commented Apr 8, 2016 at 15:49
-
1You will probably have trouble running 20 30ft I2C connections. I2C likes to have very-low capacitance on the clock and data lines. See electronics.stackexchange.com/questions/106265/… . There are nuances to different electrical topologies as well e.g. ring vs star.jamesbtate– jamesbtate2016年04月08日 18:12:25 +00:00Commented Apr 8, 2016 at 18:12
-
2As per the last comment you would probably get better connectivity via wifi, not worse.goldilocks– goldilocks2016年04月08日 18:23:11 +00:00Commented Apr 8, 2016 at 18:23
-
1I think you need multipoint bus such as RS-485 or CAN. You could use I2C with P82B96 or similar buffer IC as well.edo1– edo12016年04月09日 00:21:08 +00:00Commented Apr 9, 2016 at 0:21
4 Answers 4
schematic
simulate this circuit – Schematic created using CircuitLab
I2C will be just fine, but don't forget to apply a power and use diodes to ensure a proper power flow
-
You might want to explain that diodes part.2016年04月08日 21:08:50 +00:00Commented Apr 8, 2016 at 21:08
-
@Ghanima three diodes per power line (+ and -/gnd)Alexey Vesnin– Alexey Vesnin2016年04月08日 21:10:57 +00:00Commented Apr 8, 2016 at 21:10
-
Let me rephrase my question: why?2016年04月08日 21:12:28 +00:00Commented Apr 8, 2016 at 21:12
-
@Ghanima I had some cases in I2C "long chains" when the I2C master's VCC was not enough to properly power it all on, discovered just by an experiment adding slaves one by one. The problem is that an external PSU must have the same GND with master(RPi) and the diodes to prevent SoC from frying - there are some precedents not only with RPiAlexey Vesnin– Alexey Vesnin2016年04月08日 21:19:08 +00:00Commented Apr 8, 2016 at 21:19
-
2What on earth is "I2C VCC" supposed to be? I²C has 2 open-drain data lines with pullup to supply voltage. The Pi has on-board pullup.Milliways– Milliways2016年04月09日 01:31:19 +00:00Commented Apr 9, 2016 at 1:31
I'd use Wifi and sockets. It's relatively simple to use Qt (or even plain C++) to implement a multi-connection client/server. There are lots of tutorials on the net.
-
I looked that up, but that looks like it may be overkill for the small amount of data that I'll be sending. It looks like I'd have to develop my own software in C++ for the networking vs using a library for I2Cpekasus– pekasus2016年04月08日 20:44:45 +00:00Commented Apr 8, 2016 at 20:44
You should be able to use I2C over these distances with careful layout. I would suggest you use the slowest I2C speed (although the Pi default is already 100kHz). You should also use a bi-directional level converter at the Pi end as the high level would otherwise be marginal for the Arduino.
-
I ordered this for a level converter sparkfun.com/products/12009pekasus– pekasus2016年04月09日 01:55:19 +00:00Commented Apr 9, 2016 at 1:55
A wired solution would be to use RS-485. You can connect many devices on a single twisted wire (two wire) cable. There is an good example at https://arduino-info.wikispaces.com/SoftwareSerialRS485Example. The modules shown are really cheap. I see vendors having 5 of them for 7.99. You can also use a USB to RS-485 dongle on the Raspberry Pi.
-
More detail is needed. The link might provide the answer, but the essence of what is on the webpage needs to be included in your answer.2016年04月14日 19:12:48 +00:00Commented Apr 14, 2016 at 19:12
-
So I guess I would just put two wires into each screw terminal if I want to link them with more than 2 arduinos, correct? This won't affect the signal?pekasus– pekasus2016年04月14日 19:30:34 +00:00Commented Apr 14, 2016 at 19:30