yonubear
Posts: 90
Joined: Thu Sep 12, 2013 11:11 pm

multiple GPIO triggering issue

Sat Dec 28, 2013 9:46 pm

I am having a slight issue and I am hoping someone has an idea as I am lost Iif I only connect one switch it seems to work fine however if I have multiple switches hooked up on say pins 17, 23 and 24 if i short pin 23 to GND the others trigger as well. As best I can tell the only connection between the switches is the GND pin.

Any Ideas would be great.

Thanks,
Yonu

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: multiple GPIO triggering issue

Sun Dec 29, 2013 3:49 am

Hi Yonu,
yonubear wrote:if I only connect one switch it seems to work fine however if I have multiple switches
These switches are your inputs and you poll them in a loop ?
What are other elements present around one switch ?


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

yonubear
Posts: 90
Joined: Thu Sep 12, 2013 11:11 pm

Re: multiple GPIO triggering issue

Sun Dec 29, 2013 4:42 am

I am using gpio interrupts rather than a loop. as to elements are you refering to hardware or software?

thanks,
yonu

User avatar
joan
Posts: 15042
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: multiple GPIO triggering issue

Sun Dec 29, 2013 9:42 am

If you want help some details of your software and hardware set up are essential.

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: multiple GPIO triggering issue

Sun Dec 29, 2013 9:48 am

Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

yonubear
Posts: 90
Joined: Thu Sep 12, 2013 11:11 pm

Re: multiple GPIO triggering issue

Sun Dec 29, 2013 3:59 pm

ok thank I have used the tutorial and here is my code as that is easier than having to post sections as to hardware there are currently 2 magnetic door switches all connected using 1 cat3 cable and a 12c temp sensor the Pir sensor that is noted hasn't arrived yet

Code: Select all

import RPIO
import threading
import time
import subprocess
import sys, string, select
from socket import *
import RPi.GPIO as GPIO 
GPIO.setmode(GPIO.BCM)

# GPIO 23 & 17 set up as inputs, pulled up to avoid false detection.
# Both ports are wired to connect to GND on button press.
# So we'll be setting up falling edge detection for both
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# now we'll define two threaded callback functions
# these will run in another thread when our events are detected
doors = GPIO.input(17)
windows = GPIO.input(23)
dlight = GPIO.input(24)
temp = None
def read_onewire_temp():
    '''
    Read in the output of /sys/bus/w1/devices/28-*/w1_slave
    If the CRC check is bad, wait and try again (up to 20 times).
    Return the temp as a float, or None if reading failed.
    '''
    crc_ok = False
    tries = 0
    global temp
    temp = None
    while not crc_ok and tries < 20:
        # Bitbang the 1-wire interface.
        s = subprocess.check_output('cat /sys/bus/w1/devices/28-*/w1_slave', shell=True).strip()
        lines = s.split('\n')
        line0 = lines[0].split()
        if line0[-1] == 'YES':  # CRC check was good.
            crc_ok = True
            line1 = lines[1].split()
            rtemp = float(line1[-1][2:])/1000
            temp = rtemp * 9 / 5 + 32 #convert temp to F
        # Sleep approx 20ms between attempts.
        time.sleep(0.02)
        tries += 1
    return temp

def stat_update(): #status update every 5 min
 global doors
 global windows
 global temp
 global dlight

 read_onewire_temp()

 if doors == 1:
     hbdoors = "doorsclosed"
 else:
     hbdoors = "doorsopened"
 if windows == 1:
     hbwindows = "windowsclosed"
 else:
     hbwindows = "windowsopened"
 if dlight == 1:
     hbdlight = "dlighton"
 else:
     hbdlight = "dlightoff"

 print ("stats Sent " + time.strftime("%I:%M:%S") + " " + time.strftime("%d/%m/%Y"))
 statSock = socket(AF_INET,SOCK_DGRAM)
 statSock.setsockopt(SOL_SOCKET,SO_BROADCAST,1)
 msg = "xpl-trig\n{\nhop=1\nsource=storage-pi.cannon\ntarget=*\n}\nsensor.basic\n{\ndevice=storage-pi.cannon\ntype=input\ncurrent=" + hbdoors + "." + hbwindows + "." + str(temp) + "\n}\n"
 statSock.sendto(msg,("255.255.255.255",3865))

def SendHeartbeat():
# your interrupt 'call-back'
 print "Wait, I need you to do this"
# Sub routine for sending a heartbeat
 print ("HB Sent " + time.strftime("%I:%M:%S") + " " + time.strftime("%d/%m/%Y"))
 hbSock = socket(AF_INET,SOCK_DGRAM)
 hbSock.setsockopt(SOL_SOCKET,SO_BROADCAST,1)
 msg = "xpl-stat\n{\nhop=1\nsource=storage-pi.cannon\ntarget=*\n}\nhbeat.app\n{\ninterval=5\nport=" + str(port) + "\n}\n"
 hbSock.sendto(msg,("255.255.255.255",3865))
 time.sleep(10) #not sure if need to slow xpl sending
 stat_update()

  # restart the timer
 timerAgain = threading.Timer(300, SendHeartbeat)
 timerAgain.start()

def my_callback(channel): #Doors
 global doors
 if GPIO.input(17):
	print ("pin 17 Door open " + time.strftime("%I:%M:%S") + " " + time.strftime("%d/%m/%Y"))
	sndSock = socket(AF_INET,SOCK_DGRAM)
	sndSock.setsockopt(SOL_SOCKET,SO_BROADCAST,1)
	msg = "xpl-trig\n{\nhop=1\nsource=storagepi.cannon\ntarget=*\n}\nDoorOpen\n{\ninterval=5\nport=" + str(port) + "\n}\n"
	sndSock.sendto(msg,("255.255.255.255",3865))
 else:
	print ("pin 17 Door close " + time.strftime("%I:%M:%S") + " " + time.strftime("%d/%m/%Y"))
	sndSock = socket(AF_INET,SOCK_DGRAM)
	sndSock.setsockopt(SOL_SOCKET,SO_BROADCAST,1)
	msg = "xpl-trig\n{\nhop=1\nsource=storagepi.cannon\ntarget=*\n}\nDoorClosed\n{\ninterval=5\nport=" + str(port) + "\n}\n"
	sndSock.sendto(msg,("255.255.255.255",3865))

def my_callback2(channel): #Windows
 global windows
# windows = GPIO.input(23)
 if GPIO.input(23):
	print ("pin 23 Windows open " + time.strftime("%I:%M:%S") + " " + time.strftime("%d/%m/%Y"))
	sndSock = socket(AF_INET,SOCK_DGRAM)
	sndSock.setsockopt(SOL_SOCKET,SO_BROADCAST,1)
	msg = "xpl-trig\n{\nhop=1\nsource=storagepi.cannon\ntarget=*\n}\nWindowOpen\n{\ninterval=5\nport=" + str(port) + "\n}\n"
	sndSock.sendto(msg,("255.255.255.255",3865))
 else:
	print ("pin 23 Windows close " + time.strftime("%I:%M:%S") + " " + time.strftime("%d/%m/%Y"))
	sndSock = socket(AF_INET,SOCK_DGRAM)
	sndSock.setsockopt(SOL_SOCKET,SO_BROADCAST,1)
	msg = "xpl-trig\n{\nhop=1\nsource=storagepi.cannon\ntarget=*\n}\nWindowClosed\n{\ninterval=5\nport=" + str(port) + "\n}\n"
	sndSock.sendto(msg,("255.255.255.255",3865))

def drive_motion(channel):
 global windows
# Driveway Motion Sensor/Light = GPIO.input(24)
 if GPIO.input(24):
	print ("pin 24 motion Light alert " + time.strftime("%I:%M:%S") + " " + time.strftime("%d/%m/%Y"))
	sndSock = socket(AF_INET,SOCK_DGRAM)
	sndSock.setsockopt(SOL_SOCKET,SO_BROADCAST,1)
	msg = "xpl-trig\n{\nhop=1\nsource=storagepi.cannon\ntarget=*\n}\ndrivealert\n{\ninterval=5\nport=" + str(port) + "\n}\n"
	sndSock.sendto(msg,("255.255.255.255",3865))
 else:
	print ("pin 24 motion Light normal " + time.strftime("%I:%M:%S") + " " + time.strftime("%d/%m/%Y"))

# when a falling edge is detected on port 17, regardless of whatever 
# else is happening in the program, the function my_callback will be run
GPIO.add_event_detect(17, GPIO.BOTH, callback=my_callback, bouncetime=300)
# when a falling edge is detected on port 23, regardless of whatever 
# else is happening in the program, the function my_callback2 will be run
# 'bouncetime=300' includes the bounce control written into interrupts2a.py
GPIO.add_event_detect(23, GPIO.BOTH, callback=my_callback2, bouncetime=300)
GPIO.add_event_detect(24, GPIO.BOTH, callback=drive_motion, bouncetime=300)
# Define maximum xPL message size
buff = 1500
# Define xPL base port
port = 3865

# Initialise the socket
UDPSock = socket(AF_INET,SOCK_DGRAM)
addr = ("0.0.0.0",port)

print "xPL Monitor for Python, bound to port " + str(port)
#SendHeartbeat()

# start your timer
timerStart = threading.Timer(1, SendHeartbeat)
timerStart.start()

while True:
    #print "Doing something, dum dee dum"
    time.sleep(1)

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: multiple GPIO triggering issue

Sun Dec 29, 2013 5:22 pm

Hi Yonu,
yonubear wrote:as to hardware there are currently 2 magnetic door switches all connected using 1 cat3 cable
The following message might give you the solution:
http://www.raspberrypi.org/forum/viewto ... 99#p465699

Nevertheless, if the issue is (also) somewhere else, this circuit should definitely be used to increase the "quality" of your alarm system.


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

yonubear
Posts: 90
Joined: Thu Sep 12, 2013 11:11 pm

Re: multiple GPIO triggering issue

Sun Dec 29, 2013 6:06 pm

thanks I will look at using optocouplers hadden't really thought about that part yet since I am only using about 3 feet of wire at the moment for testing I am gonna recheck the PCB in a few to make sure I didn't merge any traces just for good measure.

Thanks,
Yonu

yonubear
Posts: 90
Joined: Thu Sep 12, 2013 11:11 pm

Re: multiple GPIO triggering issue

Sun Dec 29, 2013 8:30 pm

Ok I plan to wire in optocouplers however I just finished rechecking my wiring and I am getting a 1400ohm reading between each pi I assume I should have used an external pull up resistor. Or is this something the optocoupler will solve on its own?

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: multiple GPIO triggering issue

Sun Dec 29, 2013 10:36 pm

Hi,
yonubear wrote:I am getting a 1400ohm reading between each pi
Between each pin ???


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

yonubear
Posts: 90
Joined: Thu Sep 12, 2013 11:11 pm

Re: multiple GPIO triggering issue

Mon Dec 30, 2013 12:29 am

yes each pin sorry was typing from my cell phone I am currently in the process of wiring in the optocouplers

Thanks,
Yonu

yonubear
Posts: 90
Joined: Thu Sep 12, 2013 11:11 pm

Re: multiple GPIO triggering issue

Mon Dec 30, 2013 12:48 am

well I got smart I installed webiopi so I could see what the pins were doing in realtime easier and apparently I have an issue in the PCB I made for all my connection as the pins are going nuts until I disconnect the board then they quit guess I am gonna start from scratch.

Thanks,
Yonu

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: multiple GPIO triggering issue

Mon Dec 30, 2013 1:40 am

Hi Yonu,
yonubear wrote:yes each pin sorry was typing from my cell phone
My question marks were not because of the typo, but were related to resistance measurement... I definitelly advise you not to take an instrument and measure resistance between pins on the RasPi ever again.


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

yonubear
Posts: 90
Joined: Thu Sep 12, 2013 11:11 pm

Re: multiple GPIO triggering issue

Mon Dec 30, 2013 3:07 am

ok now just so I know how this was meant is this due to the facet that it is a pointless endeavor on the Pi or is it because of damaging the Pi

yonu

User avatar
joan
Posts: 15042
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: multiple GPIO triggering issue

Mon Dec 30, 2013 8:26 am

If the gpios are going nuts it's probably mains hum. Set the internal pull-up/downs on the gpios and they should settle.

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: multiple GPIO triggering issue

Mon Dec 30, 2013 12:08 pm

Hi,
yonubear wrote:is this due to the facet that it is a pointless endeavor on the Pi or is it because of damaging the Pi
You probably didn't damage the RasPi, although some other circuits could easily be damaged...
(Fatal could be to try to measure how much current can provide GPIO pin by attaching A-meter between the pin and +3.3V or GND) .

It is definitelly pointless, because you're not sure know what you measure... It makes sense to measure resistance directly with ohmmeter only for resistors (potentiometers, trimmers), when all instrument's current flows just through the element (eg. when at least one resistor's pin is not connected to any other element).


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

yonubear
Posts: 90
Joined: Thu Sep 12, 2013 11:11 pm

Re: multiple GPIO triggering issue

Thu Jan 02, 2014 2:07 am

ok all sorry to ask again I have narrowed it down that it isn't code related and I have put together a new board accept this time I used single pins instead of a ribbon cable so I could narrow it down I rebuild with optocouplers as suggested however I get the same effect as soon as I connect any Gpio pins they start going nuts well they start flashing on and off I am using webiopi to see what they are doing to eliminate any coding issues while I test the board. I am including nice image of what I put together in hopes of my issue making more sense.
BB.jpg
BB.jpg (42.68 KiB) Viewed 3833 times
Thanks,
Yonu

yonubear
Posts: 90
Joined: Thu Sep 12, 2013 11:11 pm

Re: multiple GPIO triggering issue

Thu Jan 02, 2014 2:37 am

ok I got it to behave at least to stop multi triggering the problem I have now is this I can't get the optocouplers to trigger as you can see from the diagram i posted I am pulling the current from the 3.3v to the switches and passing it through a 220ohm resister IC before it hits the optocouplers now according to my math 220Ohm is the correct resister for the optocouplers I am using thich are 1.4v at 10ma I essentially used the circuit found here http://www.raspberrypi.org/forum/viewto ... 99#p465699

any ideas would be great

Thanks,
yonu

User avatar
joan
Posts: 15042
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: multiple GPIO triggering issue

Thu Jan 02, 2014 10:15 am

I'm confused.

An earlier post mentioned a couple of reed switches and a PIR sensor. I've seen nothing which requires optocouplers or frankly anything more than a resistor or two.

It might help if we knew the overall goal of your project.

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: multiple GPIO triggering issue

Thu Jan 02, 2014 11:47 am

Hi Yonu,
yonubear wrote:I essentially used the circuit found here
Not quite... because there are pull-up resistors missing (connection between each opto-coupler output and GPIO pin).


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

yonubear
Posts: 90
Joined: Thu Sep 12, 2013 11:11 pm

Re: multiple GPIO triggering issue

Thu Jan 02, 2014 4:03 pm

Ok I take it using the internal pull-up resisters just doesn't cut it

yonubear
Posts: 90
Joined: Thu Sep 12, 2013 11:11 pm

Re: multiple GPIO triggering issue

Thu Jan 02, 2014 7:39 pm

question

since they will all pull off the same 3.3v rail anyway can I simply pull the pull up current for each pin from the gpio side of my 1wire or is that a stupid idea?

yonubear
Posts: 90
Joined: Thu Sep 12, 2013 11:11 pm

Re: multiple GPIO triggering issue

Thu Jan 02, 2014 7:47 pm

Something along the lines of this diagram
BB.jpg
BB.jpg (39.3 KiB) Viewed 3724 times

yonubear
Posts: 90
Joined: Thu Sep 12, 2013 11:11 pm

Re: multiple GPIO triggering issue

Fri Jan 03, 2014 12:03 am

well I just got done some testing with an LED ground hooked up to the optocouplers and I am thinking I actually may have a bad batch no matter how I connect the LED I can't get it to light when I power the couplers anyone happen to have a pinout for a PC123 optocoupler just wondering if they sent me the wrong info with them.

yonu

yonubear
Posts: 90
Joined: Thu Sep 12, 2013 11:11 pm

Re: multiple GPIO triggering issue

Fri Jan 03, 2014 8:48 pm

anychance I can get a bit of help on these optocouplers turns out the ones I have are fine but it appears they have to have to sink current in order to work as best I can tell I pulled one of them and wired an old x10 ds10 door transmitter to the collector and emitters and it will trigger it when power is applied to the isolator however it will not turn on a LED it I connect the gnd line to the collector and the LEDs gnd to the emitter I get nothing from the LED and yes I do have the LED pos leg hooked to proper voltage.

and yes apparently I am a dumb@#$,

yonu

Return to “Automation, sensing and robotics”