DaveSemm
Posts: 160
Joined: Thu Jun 21, 2012 1:16 pm

Need Advice on Max Length of GPIO Input Leads

Fri May 08, 2015 12:58 pm

My home controller system is spreading all over the house...

The GPIO outputs all go via fairly short leads to driver boards, but the inputs come from buttons and other sensors up to 10m away, and now I need to go even further.

Most long cables go to simple buttons, or mechanical relays (e.g. in PIR motion detectors.) All are configured with an internal pull-up resistor. I am about to add some electronic PIR detectors that have a direct 3.3V output; they came without specs, so I don't know how far they can reliably go, but that is another issue.

So far everything seems to work ok. Is there anything I should be doing to protect the inputs from damage or to filter out noise? Should I be using opto-isolators?

drgeoff
Posts: 9925
Joined: Wed Jan 25, 2012 6:39 pm

Re: Need Advice on Max Length of GPIO Input Leads

Fri May 08, 2015 2:51 pm

A series resistor of a few kohms at the RPi end is prudent protection. The pull-up (or -down) should be at the non-RPi end of that resistor. If the inputs are low frequency toggles a capacitor from GPIO pin to ground can reduce noise. Where possible, earth the RPi's ground but not elsewhere.

DaveSemm
Posts: 160
Joined: Thu Jun 21, 2012 1:16 pm

Re: Need Advice on Max Length of GPIO Input Leads

Fri May 08, 2015 8:31 pm

So my own pull up resistor, then a series resistor to the GPIO pin. Presumably then, I should not set the internal pull up resistor? (pull_up_down=GPIO.PUD_OFF). I'll try this. Better safe than sorry.

Most inputs are from a switch or a relay like in a PIR motion detector, so they are essentially DC. So a capacitor to reduce noise might be needed and wont affect the switch. I'll have to borrow an oscilloscope some time and see if there is any noise.

I will be adding a few DS18B20 temperature sensors, which communicate via a serial protocol (the Dallas button one, I think), where I can't put anything in between. I have one but on a 1m cable; the others will be up to 20m away.

jcreasey
Posts: 6
Joined: Sat Feb 07, 2015 11:09 pm
Location: Seattle, USA

Re: Need Advice on Max Length of GPIO Input Leads

Sat May 09, 2015 5:13 am

All of the GPIO is run at 3.5v and is very intimate to the SOC. You should not run this wiring more than a meter or so without protection. You should also never run the 3.5 or 5v from the motherboard out to remote locations, the risk is just too high.
Opto-isolation is one way to provide protection.
If you are planning on using 1-Wire peripherals then I'd suggest that the 1-Wire board from ABElectronics is a good buy. This board has 3.5-5v translation for the I2C and descent ESD protection (DS9503) on the 1-wire microlan. I wrote an article on getting this going that may help: https://www.packtpub.com/books/content/ ... and-1-wire I'd advise if you are going more than a couple of meters you use an external 5v supply for the 1-Wire (same advice about running motherboard supplies out to remote locations. The ESD protection will protect the level translator FETs and so the 'Pi.
You can run 1-Wire out to a couple of hundred meters so it's very flexible, and you can get chips to do digital I/O as well as using it for identity and temperature.

DaveSemm
Posts: 160
Joined: Thu Jun 21, 2012 1:16 pm

Re: Need Advice on Max Length of GPIO Input Leads

Sat May 09, 2015 7:14 am

jcreasey, thanks for that information. I'm very interested in the 1 wire bus, so I will try that board.

My thinking with interfacing to simple switches was that, in a matter of speaking, I'm not running the 3.3V directly out of the board: the switches go to 0V, and only go to 3.3V via the internal (10k?) pull up resistor. I thought that adding a small capacitor to filter out noise and an external resistor, as previously advised, to further protect the SoC might be enough. But I looked around for opto-isolators and found the KB847, a very cheap quad chip. I can now power the switches with the same external 12V supplies that runs the LED lights and other peripherals.

jcreasey
Posts: 6
Joined: Sat Feb 07, 2015 11:09 pm
Location: Seattle, USA

Re: Need Advice on Max Length of GPIO Input Leads

Sat May 09, 2015 2:20 pm

Optical isolation is a really good choice, just make sure you don't run ground from your 'Pi past the isolation. The typical 'Pi wiring is much more complex than most realize as the power supply is (if you are using 5v USB supplies) not grounded. This makes the ESD protection complex and almost wholly dependent on capacitor values used in the system. There are invariably clamping structures on the SOC inputs, but these typically are not good ESD protection, and certainly not viable for wiring fault protection since they clamp to the 3.5v supply.
It's also worth noting that even your ground structure potential in your house will vary considerably as you get further from your earth bond point in the power panel, so it's very difficult to get a solid ground. This is the main reason that optical isolation is so prevalent in industrial automation.

User avatar
mikronauts
Posts: 2732
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Need Advice on Max Length of GPIO Input Leads

Sat May 09, 2015 2:39 pm

Figure out your maximum distance.

Consider using RS485 or wireless (nRF24L01+) with a small microcontroller at remote drops.

Consider using more than one Pi, so "sensor clusters" are always <10m from a Pi, with WiFi or Ethernet between Pi's.

Others have mentioned opto isolators, which is a great idea - then you could use 12V for the switches, as 3v3 won't work too well over very long cables.

If the cables are not shielded, they will essentially act like antenna's - expect noise on the lines.
DaveSemm wrote:My home controller system is spreading all over the house...

The GPIO outputs all go via fairly short leads to driver boards, but the inputs come from buttons and other sensors up to 10m away, and now I need to go even further.

Most long cables go to simple buttons, or mechanical relays (e.g. in PIR motion detectors.) All are configured with an internal pull-up resistor. I am about to add some electronic PIR detectors that have a direct 3.3V output; they came without specs, so I don't know how far they can reliably go, but that is another issue.

So far everything seems to work ok. Is there anything I should be doing to protect the inputs from damage or to filter out noise? Should I be using opto-isolators?
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

Return to “Beginners”