I need to install multiple sensors/actuators (hooked up to Nanos) throughout a few rooms.
I need all of these sensors and actuators to be able to communicate with a PC, which would possibly be a few tens of meters away from some of the devices.
I don't care about bandwidth. I just need it to be reliable (occasional transmissions failures are tolerable but everything should recover pretty much without human intervention) and to be scalable in number of devices.
I'm not sure on what is the best way to implement this.
Here are the approaches I have though of:
"Central" controller approach
I was thinking of multiple I2C networks of Nanos, each one sharing the same +5V rail, on a wire that would be only a few meters long, and for each networks one of the microcontrollers would act as a router to exchange the data with a "central" microcontroller (Mega?) via serial port, and then this "central" microcontroller would route the data to and from a computer via virtual serial port.
- Low cost, you can find Nano clones for 3-4$.
- Trivial to implement
- Wouldn't a 5V rail be inefficient for a cable several meters long?
- What is the maximum length for serial communication through a simple TX/RX twisted pair? The networks could be a few tens of meters far from the "central" microcontroller. (Also, should they share a common ground? How would I achieve this using different power sources, e.g. separate wall adapters?)
- How can I scale this if I need more than 3 I2C networks? I don't want to buy a Mega for every three networks (maybe four with a software serial port), because I want this to stay as cheap as possible and I'd rather have only one virtual serial port to deal with on the PC.
I was thinking to connect all the Nanos to the PC with a USB cable.
- Trivial to implement.
- USB hubs are cheap.
- USB has a theoretical maximum length of 5 meters, which in practice is a bit longer, but it's still there.
- [Way too] many serial ports to manage on the PC.
I'm open to your ideas!
You could make the I2C scheme work with strong(low value) pullup resistors and reduced signaling rates. It has the advantage of multiple addressable slaves.
However, I would also consider softserial with as many ports as your need on the Mega and a single port on each Nano. Keep the signaling rate low. Instead of feeding +5V down the cable, use a three wire cable and 8V - 9V to Vin on each board. The regulators need about 7V5 or higher but too high just creates unnecessary heat. Hook up one Mega and two Nanos on the bench and get it working first before adding more and lengthening the cable.
Since you are using Nanos, they are all in one room, you are worried about the number 3, and low cost is in order, I guess an NRF24 network is worth considering. Then the central device relays to the PC on the other side of the world by whatever means, and I imagine that can be a Nano too. No Mega needed.
Normally reliability does not walk together with "cheap". As you already pointed out you might end up spending some time/effort just to solve the low voltage power rail. Some ideas below:
Ideally you want to keep the voltage as higher as possible but as the cheap nodes are all based on LDOs you'll be just "burning" the extra voltage.
One option if you wanna stick with the Nanos, is to have a 24V rail, powered from a good quality PSU and a switching regulator attached to each node to step-down the voltage. You'll be able to find a few option from eBay/Aliexpress that can easily step-down from 12/24V to 5V while keeping some reasonable efficiency, for example: http://www.aliexpress.com/item/2pcs-Small-Size-DC-DC-12V-to-5V-Step-Down-Buck-Converter-Power-supply-Module-for/32325193651.html
For the communication media, if wireless you could use NRF24, which is very cheap and popular (as already mentioned) or RFM69 if you need some extra range.
In case you prefer wired communication, note that I²C is designed for short distances only and you probably will need some bus extender to keep the communication reliable on a longer cable (http://www.ebay.com.au/itm/Differential-I2C-Long-Cable-Extender-PCA9600-with-Boost-Converter-for-Arduino-/111776770514?_trksid=p2141725.m3641.l6368) which might increase the project cost.
The solution of having an I2C network per room and every room having a master node talking to a PC via serial could work if you use a RS232 extender: RS232 Repeater, Extend up to 4000 FT with this RS232 Extender or http://www.ebay.com.au/itm/USR-TCP232-2-RS232-to-Ethernet-TCP-IP-Converter-Module-Q00222-/141916435268?_trksid=p2141725.m3641.l6368. I personally wouldn't use more than a single Serial connection for the whole solution.
An interesting alternative is to use CAN Bus, which is a more robust solution and can run for long distances on a CAT5e. Just use a pair for data and the other wires for GND and 12/24V.
Wireless + Battery Powered
Have you considered battery operated nodes? Considering all time and cost to build your nodes and wired the solution, you might be better to use 100% wireless options like Moteino or Whisper Node.
I got my nRF24s working with this Tutorial
I suggest you use the TMRh20 version of the RF24 library - it solves some problems from the ManiacBug version
The pair of programs in this link may be useful - at least to demonstrate basic connectivity.
If you are content for one Arduino to act as master and poll the other "slaves" in turn my code can easily be extended to do that.
The NRF24 modules seem like the perfect solution. They are amazingly cheap and they definitely have the range I need.
I think the way to go will be Arduino Pro Minis (3.3V, so no level converter needed) equipped with NRF24s, and a Uno R3 with an NRF24 and an Ethernet shield.
This way I can create a mesh network using TMRh20's library and relay everything from and to the computer via Ethernet (so distance is no concern).
For the power rail, I'd use a good 12V DC power supply (maybe the type that's normally used for LED strips?) with 1-1.5 mm gauge wire and these converters which should be able to power the wireless modules without a problem.
I should be able to set up each node with less than 10$ including a custom PCB from Jackaltac to avoid protoboard madness.
What do you think?
Here's a nice switching regulator for each board. You can buy them by the sheet. They work nicely for Arduinos and RC receivers from a 12V source.