Connecting Arduino's to Raspberry Pi

Hey guys,

Basically the title, but read on for a full story or TL;DR at the bottom.
I wouldn't be surprised if this one has been done to death, but for a while I'd been running a rather crude setup for home automation and sensing with an Arduino Nano doing a lot of I/O for sensors and relays and transmitting CSV values to an RS232 line for the Pi to read and send into MySQL and another Arduino also listening to post on a simple HTML with its ethernet shield.
The limitations of what I had going were the DHT22 temp/humid sensors would work half the time talking back to the Arduino, eventually reading nanC until a power cycle would bring them back. Only an issue on those >1m to 10m away, 12V relays switching would EMP the sensors too.

My proposed solution is I really like the DHT22's and I want to keep them, so I'll deploy ATTiny's with the DHT22's to read the sensors with one digital pin and use two pins to talk on RS485 with MAX485 modules. The Raspberry Pi will also join the RS485 network but request action from the Arduino's.
The Arduino's will reply with a CSV that the Pi will read the first value as hey, you want to database this. Followed by an Arduino ID then CSVs the Pi will be coded to understand as per Arduino.
The Pi will also be able transmit controls where required, like changing the state of digital outputs to control relays etc. (for the garden watering etc, from an Arduino in the garden shed).
The Arduino's don't have to be reprogrammable, I don't mind coming around when I need to with a laptop to USB update them.
Update times from the Arduino's need not be more than 1 second, so offsetting or sequencing the asking of each Arduino for its information won't overwhelm the RS485 network.
Again, the intention is for the Arduino's to remain quiet on the RS485 network until the Pi asks them to send their details, or the Pi asks them to change states. So there would be no cross-talk problems, plus I don't need a busy or fast network anyway.

Here's a diagram: http://dglad4.dynu.net/share/piarduinors485.png

TL;DR
I want to attach my Pi to RS485 and also several distant Arduino's. The Arduino's will only talk when the Pi asks for a CSV string reply. The Pi can tell the Arduino's to change their I/O states. No Arduino reprogramming over RS485 required.

I just want to know if this is possible to do before I order the parts, learn new code and change my system.

Much appreciated guys! Thanks.

Hi,
OPs image.

Hi,
Did you use pullup resistors on the DHT22 signal lines?
Can you post a circuit of your Arduino end of the network?

Tom... :slight_smile:

I note a blunder in your diagram - it says "Arduino UNO" but you sensibly refer to using Nanos instead. :grinning:

Your plan sounds most sensible, using RS485 for distance communication in a master-slave process.

TomGeorge:
Hi,
Did you use pullup resistors on the DHT22 signal lines?
Can you post a circuit of your Arduino end of the network?

Tom... :slight_smile:

Yes I tried all recommended values but I get the same result. I'm already pushing the sensor single digital comm lines longer than they're made for so I'm impressed they work at all.
The cost of ATTiny's and MAX485's seem a very viable solution to get sensors anywhere I like and even further away, with bonus extra I/O and local code.

I haven't got my proposed circuit made, but I'd say I'll need pull ups which may already be on the MAX485 boards. The line on my diagram just shows there will be no definite to my number of devices/Arduino's.

Cheers.

Paul__B:
I note a blunder in your diagram - it says "Arduino UNO" but you sensibly refer to using Nanos instead. :grinning:

Your plan sounds most sensible, using RS485 for distance communication in a master-slave process.

Ah yes good spot, but I could well have Uno's and Nano's on the 485 network along with ATTiny's.

Thanks, as no one has said straight up it's a bad idea it sounds like I should just order the MAX485 modules. I hope the code is viable to program!
I'm also so sick of USB serial devices changing /dev/ttyUSB IDs all the time, Windows COM port numbers too so it must be a USB controller thing. Hopefully RS485 solves this for me as I found no cheap solution to get extra dedicated RS232 ports to the Pi, ethernet network or PC via expansion like PCI-Ex.

On the hardware side. the RPi is 3.3v and some of the cheap RS485 boards are 5v. some are 3.3/5V but are not as common.

I know you are not seeking to do much about the EMF, but you can get some boards that will drive your motors and put the board and motor on a different power supply. have one board/power supply for reading, one board/power supply for controls.

dglad4:
Ah yes good spot, but I could well have Uno's and Nano's on the 485 network along with ATTiny's.

I would hope you do not intend to use UNOs. Clumsy things those!

dglad4:
I'm also so sick of USB serial devices changing /dev/ttyUSB IDs all the time,

I thought that behaviour was mostly characteristic of the Leonardo/ Pro Micro. I have seen it in the past, but my current Mint with a reasonably recent IDE is extremely well behaved. Can't speak for the Pi.

I really must go and try out the Leostick again that I bought as my entry into Arduino back in around 2012! I believe I gave up on it due to exactly this problem. :astonished:

How far away is the farthest sensor?

dave-in-nj:
On the hardware side. the RPi is 3.3v and some of the cheap RS485 boards are 5v. some are 3.3/5V but are not as common.

I know you are not seeking to do much about the EMF, but you can get some boards that will drive your motors and put the board and motor on a different power supply. have one board/power supply for reading, one board/power supply for controls.

Yeah I was thinking this might happen too, but level shifting is a pretty easy thing to DIY. I had to level shift my Arduino-Pi serial.

It's not noise getting to them, just line capacitance that disrupts the otherwise sharp digital comms I think. The only inductive load I have disrupting sensors is one particular 12V relay, so being off a 12V supply I can only say its spikes are still mutually inducting within my cable duct. I have a flyback diode directly at the relays coil, before the coils power wires run a metre through the duct back to the transistor switching board. Being a standard silicon diode I guess it's not fast enough to quench all the back EMF.
My analogue readings still seem fine, but I don't need them to sample fast (pretty much only line and battery voltage measuring).

SteveMann:
How far away is the farthest sensor?

30 metres. Doesn't exist yet but I'd like one outside in the garden greenhouse. The current furthest that mostly doesn't work is probably 15 metres. Totally reliable is 30cm. Reliable until a 12V relay EMPs/spikes is 7 metres away. Power cycling the 5V to these sensors tends to reset them going again, with some staying good longer than others.

So I've had no DHT22 work solid over 30cm, but work on and off up to 15 metres.