6

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.

pekasus
  • 193
  • 8
  • 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 Apr 08 '16 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 Apr 08 '16 at 15:49
  • Both I2C and SPI follow master-slave architecture with a single master - the Pi. Which means that the Pi typically polls all the slaves. WRT the distance it might be pushing limits a little here (but this suggests it might work). – Ghanima Apr 08 '16 at 16:17
  • sounds like a cool project. When you finish it, if it's something public, you shoudl post a link in your comments too (to wherever you blog about it). SE is a question and answer site, but using comments to tell us a little more about your project is welcomed when it's not just advertising. – Baronz Apr 08 '16 at 16:36
  • 1
    You will probably have trouble running 20 30ft I2C connections. I2C likes to have very-low capacitance on the clock and data lines. See http://electronics.stackexchange.com/questions/106265/maximum-i2c-bus-length . There are nuances to different electrical topologies as well e.g. ring vs star. – jamesbtate Apr 08 '16 at 18:12
  • 2
    As per the last comment you would probably get better connectivity via wifi, not worse. – goldilocks Apr 08 '16 at 18:23
  • @Ghanima it looks like I will just make it distance-wise (10m), but I am wondering if the junctions I have to make would increase the capacitance. – pekasus Apr 08 '16 at 20:08
  • @Baronz this is for a hydroponic project that will break the unit into pods that can change light times and other conditions individually. It will hopefully one day be a commercial product for urban food and medical uses. – pekasus Apr 08 '16 at 20:09
  • 1
    I think you need multipoint bus such as RS-485 or CAN. You could use I2C with P82B96 or similar buffer IC as well. – edo1 Apr 09 '16 at 00:21

4 Answers4

1

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.

Myg0t
  • 111
  • 10
  • 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 I2C – pekasus Apr 08 '16 at 20:44
1

You should be able to use I²C over these distances with careful layout. I would suggest you use the slowest I²C 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.

Milliways
  • 59,890
  • 31
  • 101
  • 209
1

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.

Andy G
  • 11
  • 1
  • 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. – Darth Vader Apr 14 '16 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 Apr 14 '16 at 19:30
0

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

Alexey Vesnin
  • 926
  • 9
  • 16
  • You might want to explain that diodes part. – Ghanima Apr 08 '16 at 21:08
  • @Ghanima three diodes per power line (+ and -/gnd) – Alexey Vesnin Apr 08 '16 at 21:10
  • Let me rephrase my question: why? – Ghanima Apr 08 '16 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 RPi – Alexey Vesnin Apr 08 '16 at 21:19
  • @AlexeyVesnin thanks for the drawing! I don't get why I connect the 5v PSU to the RPi VCC. Why not just remove that segment? – pekasus Apr 08 '16 at 21:29
  • you connect both - RPi and PSU to the i2c chain, they are must not be connected - that's what a diodes here for – Alexey Vesnin Apr 08 '16 at 21:30
  • 2
    What 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 Apr 09 '16 at 01:31
  • @Milliways yes, that's why no extra pull-up on a schematics. But if you'll take a look at the most of in-stock I2C device modules you'll have not three, but four lines, including 3.3 or 5 V VCC line. And it is for a very good reason, because if you will have a 3-pin i2c module, you can experience some data transmission problems, but they are gone just by supplying a same* PSU for the module as for the master, i.e. have a VCC line. I laughted at the i2c device modules makers at start too, when I saw four lines. Afterwards I've learned their wisdom in a hard way - there MUST be VCC – Alexey Vesnin Apr 09 '16 at 15:07
  • @AlexeyVesnin I understand we need 4 lines, but why connect VCC(5V) of the Arduinos to the VCC(3.3V) of the Pi, even with a diode? – pekasus Apr 09 '16 at 17:11
  • @pekasus Arduino uses 3.3 and 5V variants - as far as I know. If you'll use a 3.3V - use a DC-DC downstep, of course, and GPIO#1 at RPi for 3.3V respectively – Alexey Vesnin Apr 09 '16 at 20:12