tony359
Posts: 33
Joined: Mon Dec 21, 2015 9:59 pm
Location: Swindon, UK

GPI triggered as soon as cables are in

Sun Mar 18, 2018 8:47 pm

Hi there,

A little help please. I'm sure this is basic electronics but nevertheless I need your help!
I fitted an OFF button on the Pi. I could not fit a "wake" as my GPO3 is being used.
I also have a two relays connected to GPO 20 and 21 (BCM).
I have selected GPI 27 for my shutdown routine. It works. However, as soon as I complete the wiring on my relay board, the shutdown routine is initiated. Vice versa, if I have the relay board connected first, as soon as I connect my button to GND and GPI27, the shutdown routine initiates.

The button is NO. I have measured with a meter and it reads infinite. I tried a different GPI, same result.

I am puzzled. Can you please help me?

Here is the code I'm using

Code: Select all

#!/usr/bin/env python


import RPi.GPIO as GPIO
import subprocess


GPIO.setmode(GPIO.BCM)
GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.wait_for_edge(27, GPIO.FALLING)

subprocess.call(['shutdown', '-h', 'now'], shell=False)

Thanks!
Tony

scotty101
Posts: 3720
Joined: Fri Jun 08, 2012 6:03 pm

Re: GPI triggered as soon as cables are in

Mon Mar 19, 2018 10:12 am

Are you plugging things in to the Pi when it is powered?
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

tony359
Posts: 33
Joined: Mon Dec 21, 2015 9:59 pm
Location: Swindon, UK

Re: GPI triggered as soon as cables are in

Mon Mar 19, 2018 9:18 pm

Hi,
No. As a test I plugged the button in while it was on - and the shutdown routine immediately started - but if I leave the button plugged in the Pi boots and immediately shuts down, via shutdown command.

pcmanbob
Posts: 6939
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: GPI triggered as soon as cables are in

Tue Mar 20, 2018 4:59 pm

Test this on my pi3B+ and it works correctly .

So I suspect your relay card is causing voltage dips on the pi which is what's triggering the shutdown, is your relay card being powered from the pi ?

have you tested it with the relay card disconnected to prove your switch is connected and working correctly.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

tony359
Posts: 33
Joined: Mon Dec 21, 2015 9:59 pm
Location: Swindon, UK

Re: GPI triggered as soon as cables are in

Tue Mar 20, 2018 10:36 pm

Thank you for taking the time to test this, appreciated!

Yes, the relay board is powered from the Pi. However, it's been in operation for months and I never had any issues.
I have to say I did not check WHAT causes the shutdown but I assume it is the shutdown routine as it does not happen if the button is not connected to the relevant GPIO's.

While I see your point, I fail to understand how connecting a normally open button can trigger an action. Electronically speaking, those are two pieces of wire. The button is NO so there is no connection between them. And I have checked with a meter and there is infinite resistance when the button is not pushed...

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

Re: GPI triggered as soon as cables are in

Tue Mar 20, 2018 11:04 pm

Bits of wire can pick up enough voltage though stray capacitance and magnetic induction to trigger a GPIO. Try putting an external 1K pull-up resistor on the GPIO.

tony359
Posts: 33
Joined: Mon Dec 21, 2015 9:59 pm
Location: Swindon, UK

Re: GPI triggered as soon as cables are in

Sat Mar 24, 2018 3:27 pm

HI there,

Thank you, it worked! As the Pi has internal pull-up resistors, how come that did not work with 5cm of wire connected to the GPIO?

Thank you again!
Tony

pcmanbob
Posts: 6939
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: GPI triggered as soon as cables are in

Sat Mar 24, 2018 3:37 pm

The internal pull ups are about 50K, which may not give a good enough pull up especially if you have a relay board in operation near by with all the magnetic fields being produce by the relay coils
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

tony359
Posts: 33
Joined: Mon Dec 21, 2015 9:59 pm
Location: Swindon, UK

Re: GPI triggered as soon as cables are in

Sat Mar 24, 2018 4:48 pm

Thanks for the explanation. Can I leave the internal pull-up enabled via software or better disable it?

pcmanbob
Posts: 6939
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: GPI triggered as soon as cables are in

Sat Mar 24, 2018 5:00 pm

Its not going to make much difference if you leave it enabled and use an external 1K resistor total resistance would be around 980 ohms compared to just the external 1K resistor
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

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

Re: GPI triggered as soon as cables are in

Sat Mar 24, 2018 5:01 pm

Doesn't really matter.

tony359
Posts: 33
Joined: Mon Dec 21, 2015 9:59 pm
Location: Swindon, UK

Re: GPI triggered as soon as cables are in

Sun Mar 25, 2018 8:42 am

Thanks again.

This morning I found the Pi switched off. I don't think there was a power cut as my oven's clock would have reset.
Do you know where I can check some logs to try and find out if the shutdown routine was initiated?

Thanks!

Edit: no apparently. I have added logging into the file myself. I'll now wait for next time it shuts down :)

tony359
Posts: 33
Joined: Mon Dec 21, 2015 9:59 pm
Location: Swindon, UK

Re: GPI triggered as soon as cables are in

Sun Mar 25, 2018 7:04 pm

The Pi switched off again and the logs confirmed the shutdown routine had been initiated.
I then found the culprit! It's the thermostat which sits by the Pi. It's on/off and mechanical type. Boiler line is, surprisingly, 240V.
I turned the dial back and forth a few times to engage/disengage the boiler and at some point the Pi switched off (via shutdown file).

I did not have a 1Kohm resistor, I only had a 1.6Kohm. Would that explain the issue?

Thanks
Tony

pcmanbob
Posts: 6939
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: GPI triggered as soon as cables are in

Sun Mar 25, 2018 7:10 pm

No 1.6K resistor will be just fine as a pull up , I normally use 10K for pull up/down with out any problems.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
davidcoton
Posts: 4143
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: GPI triggered as soon as cables are in

Sun Mar 25, 2018 7:15 pm

So you have positively identified a source of radio frequency interference (BTW the majority of boiler controls work at mains voltage).
Next attempt at suppression: put a 0.1 microFarad capacitor between the GPIO input and ground.
Signature retired

tony359
Posts: 33
Joined: Mon Dec 21, 2015 9:59 pm
Location: Swindon, UK

Re: GPI triggered as soon as cables are in

Sun Mar 25, 2018 11:03 pm

Thanks David,

Shall I leave the resistor in place too?

User avatar
davidcoton
Posts: 4143
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: GPI triggered as soon as cables are in

Mon Mar 26, 2018 8:33 am

Yes
Signature retired

tony359
Posts: 33
Joined: Mon Dec 21, 2015 9:59 pm
Location: Swindon, UK

Re: GPI triggered as soon as cables are in

Thu Mar 29, 2018 8:44 am

Hi David,

Capacitors have been in for a few days and the Pi has not shutdown anymore - thank you!

What happens from an electronic point of view? Why isn't pulling up the GPI enough and extra capacitors are required?

User avatar
davidcoton
Posts: 4143
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: GPI triggered as soon as cables are in

Fri Mar 30, 2018 11:41 am

The capacitor will filter out any high frequency signals, especially any radio frequency signals radiated by other equipment (even, sometimes, something as simple as a switch) when the GPIO wires act like an aerial.
Signature retired

tony359
Posts: 33
Joined: Mon Dec 21, 2015 9:59 pm
Location: Swindon, UK

Re: GPI triggered as soon as cables are in

Fri Mar 30, 2018 7:55 pm

Thank you!

Return to “Troubleshooting”