1
\$\begingroup\$

I am designing a automation system and need to have multiple slave devices(probabaly arduino UNO or NANO) communicating both ways with master device (Raspberry PI).

There is a server and database running on a raspbery PI and I need be constatly sending/reading data from individual arduinos that have sensors connected to it. Based on certain actions from the sensors on arduino boards, raspberry PI will be sending sql querys to the database.

My main concern is how do I talk to individual slave boards with a single master device. I only see 3 options here:

  1. Use RS485 modbus to connect all slaves in a daisy-chain enter image description here

enter image description here

  1. Since I have 4 USB ports on my raspberry PI 3b+ and use only 1 for keyboard and mouse, i could use USB-HUB to expand the available USB ports and then connect to individual arduinos as such: enter image description here

  2. Maybe use ETHERNET to connect all devices together? Not sure how would that work and look just an idea..

Any advice is appreciated! Thanks

\$\endgroup\$
4
  • \$\begingroup\$ Thnaks for the reply. Would you suggest how would the wiring look if I used ethernet to communicate with multiple slaves? Would I just add ethernet shield to arduino devices, connect all devices to the same network and use MQQT or simmilar to control slaves? \$\endgroup\$
    – Lukas
    Jul 3, 2020 at 10:09
  • \$\begingroup\$ (moved to an actual answer) \$\endgroup\$
    – user253751
    Jul 3, 2020 at 10:29
  • 1
    \$\begingroup\$ Based on the info you give Modbus seems to be the natural choice. For 50 devices the investment in cable, switches and shields would be huge if you choose Ethernet. If you don't need a huge bandwidth go for Modbus. You can get RS485 shields for 1$ each. Software should be probably easier or the same difficulty than Ethernet \$\endgroup\$
    – Marcos G.
    Jul 3, 2020 at 11:47
  • \$\begingroup\$ The Master and Slave terminology is getting purged throughout industry. FYI. Might as well adjust to the new reality. \$\endgroup\$
    – user57037
    Jul 3, 2020 at 18:35

3 Answers 3

1
\$\begingroup\$

USB and Ethernet are pretty much out of the question here.

For connecting 50 devices and a host with Ethernet, you would need a 51-port switch, or several smaller switches distributed to have the total of 51 ports. Ethernet connections are point-to-point so you need 51 cables as well. Limit is 100m per span, or 90m inside the walls to allow 5m of patch cable at both ends. Power over Ethernet can power these, but that's even more expensive.

For USB, you also need a huge tree of USB hubs to provide 50 ports for 50 slaves. USB has 5meter cable limitation, so that's not much. I don't know how much current one Arduino will draw, but assuming minimum of 1 unit load of 100mA, you can't provide more than 5 or 10 devices out of one USB port, unless hubs are powered.

So only real option from all of these is RS485 it still requires careful designing.

For instance, RS485 has a limit of 32 Unit Loads.

Connecting 50 devices means you need a tranceiver that is rated for half a Unit Load so you can have up to 64 of them on the same bus. The RS485 adapter you draw in the picture has a chip that has a rating of 1 unit load, so you can't connect more than 32 devices on a single bus, and you either need to use another tranceiver board, or split to use two buses with 25 devices plus host adapter on each.

The RS485 bus must be linear. The stubs from bus to a tranceiver must be relatively short, but don't do stubs if you don't have to. The bus must also be terminated to the characteristic impedance at both ends of the bus, with a 120 ohm resistor. The problem is that the tranceiver you draw in the picture has the termination built-in, so they must be modified so only the first and last device are terminated. Or remove termination from all of them, to allow the placement on the bus freely, and use external 120R resistors at suitable places where the bus ends. The bus simply does not work properly if it incorrectly terminated.

The tranceivers also have only two pins for connecting the bus, so there is no ground pin available for connecting a common bus ground reference. It means that with only two data wires, all the boards need to have a common ground reference via some other path. You can't use 2-prong wall warts to power them, but you must use a 3-prong power supplies that gives ground reference to the board. Or they must be powered centrally from one location so they share the same ground. RS485 allows for 7V difference between board ground references, but using ungrounded power supplies don't give a ground reference at all.

\$\endgroup\$
4
  • \$\begingroup\$ Hmm, I missed the limit of 32 unit loads. \$\endgroup\$
    – user253751
    Jul 3, 2020 at 13:41
  • \$\begingroup\$ Can you use a non-linear bus if you reduce the baud rate? \$\endgroup\$
    – user253751
    Jul 3, 2020 at 13:45
  • \$\begingroup\$ In a star bus, all nodes are stubs. It could be done, but it's really an exception so there is no material how to do it so that it works, because it's not meant to be used like that. Reducing the baud rate itself does not help, it's the signal rise/fall time that needs to be slower. \$\endgroup\$
    – Justme
    Jul 3, 2020 at 14:00
  • \$\begingroup\$ Then maybe you can add some extra capacitance to each node. Anyway it sounds possible \$\endgroup\$
    – user253751
    Jul 3, 2020 at 14:22
1
\$\begingroup\$

Moving comments to an answer:

  • Yes, any of these will work.

  • RS485 is cheapest, and Ethernet is fastest.

  • With USB you need hubs; with Ethernet you need switches. With RS485 you just connect all the devices to a single cable, but the speed is slower.

  • Don't forget USB has a maximum distance of 5 metres between hubs, and a maximum of 5 hubs in a chain. The only advantage of USB is that you could use it to reprogram the Arduinos remotely.

Thnaks for the reply. Would you suggest how would the wiring look if I used ethernet to communicate with multiple slaves? Would I just add ethernet shield to arduino devices, connect all devices to the same network and use MQQT or simmilar to control slaves?

  • Each Arduino would need an Ethernet shield
  • Each Arduino, and the Pi, would need to be plugged into an Ethernet switch. Unlike USB, Ethernet switches can be chained together with no limit, and they can be up to 100 metres apart.
  • You might be able to find some old (100Mbps only) professional-grade network switches on eBay, with maybe 24 ports each for only a couple of dollars per port. They should be cheaper because most people who use them upgraded to gigabit switches. You might even find 10Mbps hubs for cheaper still.
  • I think it would be easiest to use a custom UDP protocol to control the slaves - unless you already know an MQTT library that you want to use.

Out of these three options, I would recommend RS485 if you don't need high speed.

Edit:

  • "Justme"'s answer talks about some important limitations of RS485.
\$\endgroup\$
0
\$\begingroup\$

Interesting question. In any case, you're going to have some mess. What about wireless connection? Some ESP32 module is cheap, easy to setup with Arduino IDE, you can make individual addresses for your arduinos. They also don't take much space or power. You can have a local secure wifi-network uniting RaPi and all Arduinos.

Your host device raspberry can be connected to router that will unite all arduinos, router can support so many connections at once. Alternatively, RaPi can have several ESP32 as well (one ESP32 can support up to 10 connections with other devices). It's not the cheapest option, but it will make everything so much cleaner without 10km of wires. I would at least try to implement it with, say, 2 ESP32+arduinos and one ESP32 in raspberry as a host and I would just see if it works. All you'll need to do will be to provide power to all those arduinos, other than that, you'll have beautiful wireless net. Provided the signal reaches the RaPi.

Of course, there're many aspects of the project you need to take into account even to decide if it's viable at all to make such a thing, if you have serious distance between arduinos, you may want to invent something to make it work.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ @Lukas What is the grade of the processing / data gathering that will be done in the distributed devices? Maybe you could use ESP32 or even ESP8266, no need for Arduinos. \$\endgroup\$
    – mguima
    Jul 7, 2020 at 16:02
  • \$\begingroup\$ Yes from what I have been reading I think i will be using esp32 or esp8266, what I am worried about tho, is connecting 50 of those on the same network. Will I even be able to do that with a standard router/ \$\endgroup\$
    – Lukas
    Jul 14, 2020 at 4:26
  • \$\begingroup\$ I googled that, ESP can have up to 10 connections at once, but routers can easily have over 100. Of course, you're free to google and verify it yourself \$\endgroup\$
    – Ilya
    Jul 14, 2020 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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