yeahitwasme
Posts: 13
Joined: Thu Jul 04, 2013 4:48 pm
Location: Germany

[Solved] Increase GPIO cable length

Fri Jul 12, 2013 11:54 am

Hi, I hope this is the right place for my question.

I want to make a wireless doorbell with a pi and its gpio interface. The idea is to press a button, the raspi will notice it and send a signal to an android app which will alert me on my Android phone.

I'm nearly done with everything, but now I need to connect the doorbell button to the pi which is roughly 10 to 15 meters cable length away. There is not much room beneath my door and I cannot place the raspi there, so I need to wire the doorbell to the pi.

Now I'm not an expert on electrics, but I think the 3.3v of the gpio pins will not make it through 10 meters of telecommunications cable, am I right ?

My question is simple: How can I wire the doorbell button + an lcd for showing whether I'm in my garden or not over a distance of ~10 meters so the gpio signal still makes it through ?

Edit: Also consider I will need 12 or 13 leads and therefore it should be as easy as possible.

Thanks in advance!
Last edited by yeahitwasme on Sun Jul 21, 2013 1:50 pm, edited 1 time in total.

User avatar
DeeJay
Posts: 2026
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: Increase GPIO cable length

Fri Jul 12, 2013 1:51 pm

yeahitwasme wrote: Now I'm not an expert on electrics, but I think the 3.3v of the gpio pins will not make it through 10 meters of telecommunications cable, am I right ?
I'm not an expert either, but I can say that in a different (not RPi) setting I have run 5v signals over some 100s of meters.

So my suggestion is - try it and see before worrying about designing more complex solutions. (You don't have to install the cable to the door, just a spool of cable on the bench will do for a rough test.)
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

yeahitwasme
Posts: 13
Joined: Thu Jul 04, 2013 4:48 pm
Location: Germany

Re: Increase GPIO cable length

Fri Jul 12, 2013 2:06 pm

Thank you for your reply!

I will try it this evening with some nice speaker cables. Just to see if it works.

Until then, I would appreciate other's opinions too, though.

yeahitwasme
Posts: 13
Joined: Thu Jul 04, 2013 4:48 pm
Location: Germany

Re: Increase GPIO cable length

Fri Jul 12, 2013 3:44 pm

Okay,

I just tried it with a ~2 meter very thin copper wire and it worked.

Unfortunately I do not have a longer thin cable yet that I could use to test.

So I took a 6 meter speaker cable (copper, 4 or 6 mm^2, not sure, but it's very thick) and the signal didn't come through anymore.

How does it work in general? Could a thinner wire carry the signal further or is a thicker wire better for the job?

User avatar
Burngate
Posts: 6501
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Increase GPIO cable length

Fri Jul 12, 2013 6:28 pm

It should have worked.

Thinner cable means higher resistance, so less current for the same voltage
So the thicker speaker cable should have worked just as well

Think of it like a hose pipe - turn the tap on at the far end, you'll get water out this end, but you'll get more water with a thicker pipe.
Or what Isambard Kingdom Brunell did - he laid a cable across the atlantic, and got a signal at the far end (for a short time, before the cable corroded)
If he could, you can. :)

So either:
You wired it wrong
The cable is actually broken somewhere
Your program is faulty

What is your program like, and how did you wire it?

yeahitwasme
Posts: 13
Joined: Thu Jul 04, 2013 4:48 pm
Location: Germany

Re: Increase GPIO cable length

Fri Jul 12, 2013 7:01 pm

Burngate wrote: Thinner cable means higher resistance, so less current for the same voltage
So the thicker speaker cable should have worked just as well
Okay, that's what I thought. My dad thought differently, so I asked here to be sure.
Burngate wrote: Or what Isambard Kingdom Brunell did - he laid a cable across the atlantic, and got a signal at the far end (for a short time, before the cable corroded)
By that, do you mean that the length of the cable is not relevant (keep in mind the thin wire was only a third as long as the thick wire!) ?
Burngate wrote: So either:
You wired it wrong
The cable is actually broken somewhere
Your program is faulty
What is your program like, and how did you wire it?
The cable: It's not broken, it's a speaker cable with dozens of single intertwined wires, also extremely flexible.

I'll first explain the wiring, then the program:

To test my program, I connected gpio pin 4 to ground while the program ran. I just took a short wire (few cm) and physically connected both pins. Program worked like a charm and noticed the connection. Also did that with a 2m long thin copper wire and it worked too.

For the speaker cable I did the same thing, I took a small part of the wires (one fifth of the whole strand) and connected both ends to the pins. No change was detected by my program.
Here I see two possible problems: I did not connect the whole strand to the pins AND the cable is three times as long as the other one.

My program: I wrote it in node.js and use the gpio module to read the pins. It's totally simple and pretty straightforward. Also I'm a professional coder :)

Anyway, here's the code: http://pastebin.com/2Nin9uuX

I also noticed another strange thing: After I did the things explained above, I connected a breakout cable with breakout board (especially made for raspi) to my pi, and my program would start to notice button presses (low on gpio 4) just by moving the breakout cable. What could be possible error sources here ?

I really appreciate your help!

User avatar
Burngate
Posts: 6501
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Increase GPIO cable length

Sat Jul 13, 2013 9:03 am

yeahitwasme wrote:
Burngate wrote: Or what Isambard Kingdom Brunell did - he laid a cable across the atlantic, and got a signal at the far end (for a short time, before the cable corroded)
By that, do you mean that the length of the cable is not relevant (keep in mind the thin wire was only a third as long as the thick wire!) ?
Well, sort of.
In Brunell's Atlantic cable, he was sending quite a large current (to light a lamp I believe) and so he needed quite thick cable - meaning low resistance - for there still to be voltage at the far end.
For your doorbell, there isn't much of a load - assuming you've put a pull-up or pull-down resistor of a few kΩ, so a mA of current or less - and so there won't be much voltage dropped by the cable.
It's the ratio of the resistances of the cable compared to the load that matters, and it would need the cable to be very thin to have an appreciable effect.

You will get other effects with a longer cable. For a start, it will act like an aerial and pick up interference, and the longer it is the more pick-up
Also capacitance in the cable will reduce the frequency at which you can switch - though you would have to be looking at thousands of changes per second.
The cable: It's not broken, it's a speaker cable with dozens of single intertwined wires, also extremely flexible. I took a small part of the wires (one fifth of the whole strand) and connected both ends to the pins. No change was detected by my program.
Ah. Is that cable made of green and red strands (or other colours) by any chance? If so, then all of them are insulated with laquer, so you will need to choose the same strands at each end. Not an easy job, given the number of strands to choose from.
I also noticed another strange thing: After I did the things explained above, I connected a breakout cable with breakout board (especially made for raspi) to my pi, and my program would start to notice button presses (low on gpio 4) just by moving the breakout cable. What could be possible error sources here ?
I'm guessing you haven't got any pull-ups activated?

Your program looks good to me, but then it would look good to me however many mistakes you made. We need someone else to look it over.
Does it have any de-bouncing built in? (that means looking several times to make sure it's really pressed to avoid false triggering. I can see it waits after triggering to avoid false releases)

yeahitwasme
Posts: 13
Joined: Thu Jul 04, 2013 4:48 pm
Location: Germany

Re: Increase GPIO cable length

Sat Jul 13, 2013 9:44 am

Burngate wrote: assuming you've put a pull-up or pull-down resistor of a few kΩ, so a mA of current or less - and so there won't be much voltage dropped by the cable.
It's the ratio of the resistances of the cable compared to the load that matters, and it would need the cable to be very thin to have an appreciable effect.
Ah okay, and no, I did not put a transistor in there. That sounds like I should? How would that look like?

Also is my wiring/concept okay? For "button not pressed" there is nothing connected with each other. For "button pressed" it's just a simple wire connection from ground to gpio 4.
Is the following correct? There is voltage on gpio 4 and it returns 1 (high, whatever) if I read it, and as soon as I connect it to ground it will drain the voltage and reading gpio 4 will return 0 (low) ?
Burngate wrote: Ah. Is that cable made of green and red strands (or other colours) by any chance? If so, then all of them are insulated with laquer, so you will need to choose the same strands at each end. Not an easy job, given the number of strands to choose from.
Nope. They are not insulated individually. It's just a strand of plain copper wires inside the insulation (sorry for the simple terms, English is, like electronics, not my native language ;) ).
Burngate wrote: I'm guessing you haven't got any pull-ups activated?
Correct.
Burngate wrote: Your program looks good to me, but then it would look good to me however many mistakes you made. We need someone else to look it over.
Does it have any de-bouncing built in? (that means looking several times to make sure it's really pressed to avoid false triggering. I can see it waits after triggering to avoid false releases)
I don't think so. I am using an external module for actually reading the pins. It works like that:
I tell the module which pin to read and how often. I chose 200 ms as checking interval. Now I'm not sure whether it will read the pin only once every 200ms, but I think so. Maybe I should instead try another module which works with interrupts and just notifies me when the pins are connected. I guess it would be better anyway because no one will hold the doorbell button for 200ms.

In case that doesn't change anything, what would I need to do? Find and try another long cable which consists of only one strand?

It sounds like I need to use transistors to increase the signal. If so, what are collector and emitter ?

User avatar
jojopi
Posts: 3586
Joined: Tue Oct 11, 2011 8:38 pm

Re: Increase GPIO cable length

Sat Jul 13, 2013 10:32 am

What first made transatlantic cables practical was the use of Kelvin's very sensitive mirror galvanometer as a detector, allowing transmissions at around one volt. Earlier attempts to drive regular telegraphy equipment required transmission at hundreds or thousands of volts to overcome the high cable resistance, which greatly accelerated the failure of the insulation.

Even with the mirror galvanometer solving the problem of resistance, the huge capacitance of the cable to the ocean distorted the signals and reduced the usable bandwidth to almost nothing. It was decades later that transmission line theory was understood and Heaviside loading coils introduced.

User avatar
DeeJay
Posts: 2026
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: Increase GPIO cable length

Sat Jul 13, 2013 10:37 am

yeahitwasme wrote: I did not put a transistor in there. That sounds like I should? How would that look like?
It sounds like I need to use transistors to increase the signal. If so, what are collector and emitter ?
I think you are the only person to mention 'transistor'.

The advice given was that you might need a 'resistor' - not the same thing.
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

KenT
Posts: 758
Joined: Tue Jan 24, 2012 9:30 am
Location: Hertfordshire, UK
Contact: Website

Re: Increase GPIO cable length

Sat Jul 13, 2013 11:06 am

I have many buttons on my test box for Pi Presents and all have a 330 ohm resistor wired in series with the button (to stop me blowing up the PI should an input be accidentally programmed as an output). I would have thought that you should have no problems with the thinnest of cable for your application as the resistance should be well below 330 ohms.

I suspect noise problems caused by RF pickup. You definitely need a pull-up resistor, either a 10K resistor between the GPIO pin and the 3.3 volts or alternatively use software to turn on the Pi's internal pullups. Also a 10 nF capacitor between the pin and the ground at the Pi end of the wire will reduce any RF noise.

You also mention that you want 10 long leads to a LCD. That might be more problematic as I suspect there will be high frequency signals present and there could be problems with capacitance on the lines, noise pickup, and maybe skew. This type of device is designed for local connection to a computer.
Pi Presents - A toolkit to produce multi-media interactive display applications for museums, visitor centres, and more
Download from http://pipresents.wordpress.com

yeahitwasme
Posts: 13
Joined: Thu Jul 04, 2013 4:48 pm
Location: Germany

Re: Increase GPIO cable length

Sat Jul 13, 2013 12:56 pm

DeeJay wrote:
yeahitwasme wrote: I did not put a transistor in there. That sounds like I should? How would that look like?
It sounds like I need to use transistors to increase the signal. If so, what are collector and emitter ?
I think you are the only person to mention 'transistor'.

The advice given was that you might need a 'resistor' - not the same thing.
Woops, I misread that. Thanks for pointing that out!
KenT wrote:I suspect noise problems caused by RF pickup. You definitely need a pull-up resistor, either a 10K resistor between the GPIO pin and the 3.3 volts or alternatively use software to turn on the Pi's internal pullups.
Does that mean my wiring GND -> io pin 4 was incorrect and I should use 3.3v pin instead of the GND pin ?
KenT wrote:Also a 10 nF capacitor between the pin and the ground at the Pi end of the wire will reduce any RF noise.
Now here you're speaking of ground again. Please clarify which pins need to be connected.

So the next things I will do are:
- get a long thin wire for the button
- get a 10kOhm pull-up resistor
- get a 10nF capacitor

and wire:
GND -> capacitor -> resistor -> long wire -> button -> long wire -> IO pin.

Is that correct ?

Edit: The LCD is not that important. The doorbell functionality would suffice.

Also thank you all for the useful advice!

Snigelson
Posts: 30
Joined: Tue Jul 02, 2013 8:10 am

Re: Increase GPIO cable length

Sat Jul 13, 2013 1:18 pm

yeahitwasme wrote:
KenT wrote:Also a 10 nF capacitor between the pin and the ground at the Pi end of the wire will reduce any RF noise.
Now here you're speaking of ground again. Please clarify which pins need to be connected.
[...]
GND -> capacitor -> resistor -> long wire -> button -> long wire -> IO pin.

Is that correct ?
No. Simply put, a capacitor does not allow for DC current to pass. Therefore, if you put it in parallel from GND to IO pin it will "eat" noise induced in the cable.

Also I do not understand the function of the resistor here. If it supposed to be a pull-up, why not use the ones built into the RPi?
dpc06+t1wG0S/P6frt6iR6fQODFsMCPrXr0+vbVYLzghsro5BpyK61/qRyqLvIQ1

yeahitwasme
Posts: 13
Joined: Thu Jul 04, 2013 4:48 pm
Location: Germany

Re: Increase GPIO cable length

Sat Jul 13, 2013 1:26 pm

Snigelson wrote:
yeahitwasme wrote:
KenT wrote:Also a 10 nF capacitor between the pin and the ground at the Pi end of the wire will reduce any RF noise.
Now here you're speaking of ground again. Please clarify which pins need to be connected.
[...]
GND -> capacitor -> resistor -> long wire -> button -> long wire -> IO pin.

Is that correct ?
No. Simply put, a capacitor does not allow for DC current to pass. Therefore, if you put it in parallel from GND to IO pin it will "eat" noise induced in the cable.

Also I do not understand the function of the resistor here. If it supposed to be a pull-up, why not use the ones built into the RPi?
Okay, so instead I do: GND -> long wire -> button -> long wire -> io 4
And the capacitor as a separate connection between the same two pins ?

Of course I can use the resistors which are built into the pi. I will look up how to do that. Many thanks!

KenT
Posts: 758
Joined: Tue Jan 24, 2012 9:30 am
Location: Hertfordshire, UK
Contact: Website

Re: Increase GPIO cable length

Sat Jul 13, 2013 3:32 pm

KenT wrote:Also a 10 nF capacitor between the pin and the ground at the Pi end of the wire will reduce any RF noise.
Now here you're speaking of ground again. Please clarify which pins need to be connected.

So the next things I will do are:
- get a long thin wire for the button
- get a 10kOhm pull-up resistor
- get a 10nF capacitor

and wire:
GND -> capacitor -> resistor -> long wire -> button -> long wire -> IO pin.

Is that correct ?

[/quote]

Not sure, here is a diagram

------------------------------+3.3 volts pin on Pi
|
|
10 K pull-up resistor
|
-----330 ohm resistor-----+------------------------------ GPIO Pin on Pi
| |
switch |
| 10 nF capacitor
| |
+---------------------------+-------------------------------- 0 volts = GND = Ground, pin on Pi

The 10 K resistor is essential but could be removed and you could use the Pi's internal pull-up resistor instead
The 330 ohm resistor is not essential, it is just to stop you blowing up the Pi
The 10nF capacitor is desirable. It is a high resistance to DC but a low resistance to RF signals at high frequencies.

Oh for a schematic diagram drawing add-on on to this forum!
Pi Presents - A toolkit to produce multi-media interactive display applications for museums, visitor centres, and more
Download from http://pipresents.wordpress.com

Snigelson
Posts: 30
Joined: Tue Jul 02, 2013 8:10 am

Re: Increase GPIO cable length

Sat Jul 13, 2013 7:17 pm

yeahitwasme wrote:Okay, so instead I do: GND -> long wire -> button -> long wire -> io 4
And the capacitor as a separate connection between the same two pins ?

Of course I can use the resistors which are built into the pi. I will look up how to do that. Many thanks!
Simplest possible solution.

KenT, Is there any particular reason you insist on a discrete pull-up resistor? Only reason I can think of is if the resistance in the cable becomes comparable of that of the pull-up, but those are about 50 kiloohms.
dpc06+t1wG0S/P6frt6iR6fQODFsMCPrXr0+vbVYLzghsro5BpyK61/qRyqLvIQ1

KenT
Posts: 758
Joined: Tue Jan 24, 2012 9:30 am
Location: Hertfordshire, UK
Contact: Website

Re: Increase GPIO cable length

Sat Jul 13, 2013 8:21 pm

Snigelson wrote:
yeahitwasme wrote:Okay, so instead I do: GND -> long wire -> button -> long wire -> io 4
And the capacitor as a separate connection between the same two pins ?

Of course I can use the resistors which are built into the pi. I will look up how to do that. Many thanks!
Simplest possible solution.

KenT, Is there any particular reason you insist on a discrete pull-up resistor? Only reason I can think of is if the resistance in the cable becomes comparable of that of the pull-up, but those are about 50 kiloohms.
I didn't insist on a discrete pull-up, you can use the internal one instead, but you must have one or other.

Redraw of diagram properly formatted:

Code: Select all


                                               ------------------------------+3.3 volts pin on Pi
                                             |
                                             |
                                10 K pull-up resistor (or internal)
                                             |
        -----330 ohm resistor-----+------------------------------ GPIO Pin on Pi
        |                                   |
     switch                                 |
        |                        10 nF capacitor
        |                                   |
          +---------------------------+-------------------------------- 0 volts = GND = Ground, pin on Pi

Pi Presents - A toolkit to produce multi-media interactive display applications for museums, visitor centres, and more
Download from http://pipresents.wordpress.com

yeahitwasme
Posts: 13
Joined: Thu Jul 04, 2013 4:48 pm
Location: Germany

Re: Increase GPIO cable length

Sun Jul 14, 2013 6:15 am

I now understood what I need to do. I will first try it without external resistors though, because I do not have any resistors. I will enable the internal pull ups and then wire like KenT explained.

Many thanks for all of the comments! I will come back and tell you if everything worked out.

yeahitwasme
Posts: 13
Joined: Thu Jul 04, 2013 4:48 pm
Location: Germany

Re: Increase GPIO cable length

Sun Jul 21, 2013 1:49 pm

My doorbell is now working. Many thanks to everyone who helped. In case anyone else needs a wireless doorbell, here's how I did it:

I am using two 10 meter long copper wires which I soldered to my old wireless-doorbell button. One wire goes to gpio4 (pin 7) and one to the GND pin. I enabled the internal pull ups for gpio 4 using the command "sudo gpio mode 7 up" after installing wiringPi on raspbian wheezy. Then I ran my nodejs program which now looks like this (see below) and utilized the nodejs module "onoff" which allows for gpio interrupt handling. It also listens on TCP port 5000 for incoming connections from android clients which get notified as soon as someone is pushing the doorbell button.

Code: Select all

var Gpio = require('onoff').Gpio;
var net = require('net');
var host = '192.168.1.101';
var port = 5000;
var clients = [];
var canRing = true;

// this is gpio4:
var pinNumber = 4;
var button = new Gpio(pinNumber, 'in', 'both');

// handles button press interrupts:
var gpioHandler = function(err, value) {
  if (value === 0 && canRing) {
    console.log('Button pressed');
    canRing = false;
    onDoorbellPress();
    // only treat interrupts as a new event if there are
    // at least 20 seconds between them:
    setTimeout(function onTimeout() {
      canRing = true;
    }, 20000);
  }
  // resume waiting for interrupts:
  button.watch(gpioHandler);
}

// initialize server socket and interrupt handling:
function initialize() {
  console.log('In case of erroneous behavior make sure to enable ' + 
    'the internal pull-up resistor for the appropriate gpio pin!');
    net.createServer(function (sock) {
      console.log('Client connected!');
      clients.push(sock);
      sock.on('close', function(hadError) {
        console.log('Client socket closed!');
        var pos = clients.indexOf(sock);
        if (pos != -1) {
          // remove this socket from the list of clients:
          clients.splice(pos, 1);
        }
      });
    }).listen(port, host);
    console.log('Server listening on address ' + host + ":" + port);
    button.watch(gpioHandler);
}

initialize();

// notify all connected clients that someone is at the door:
function alertClients() {
  // copy clients array to iterate over it:
  var itClients = clients.slice(0);
  for (var i = 0; i < itClients.length; i++) {
    var client = itClients[i];
    console.log('Alerting client.');
    client.on('error', function (err) {
      // Only log the error.
      // The socket will be removed from the list during the 
      // onClose event following this one.
      console.log('Error alerting client ' + client.remoteAddress + ': ' + err);
      socket.destroy();
    });
    // alert this client:
    client.write('RINGRING\n');
  }
  console.log('All clients have been notified.');
}

// handler for an interrupt that has been identified as an individual button press:
function onDoorbellPress() {
  console.log("Doorbell pressed!");
  if (clients.length > 0) {
    alertClients(); 
  }
}
Many thanks again to everyone involved! You are a great community :)

Return to “Interfacing (DSI, CSI, I2C, etc.)”