kylerichards89
Posts: 98
Joined: Sun Aug 31, 2014 12:42 am

GPIO Cycle after button

Mon Sep 29, 2014 12:56 pm

I've tried several different ways to make sure it wasn't me, and all have failed. I just bought my 2 Pi and for some reason the wait_for_edge just does not work. Once you push the button once, it'll just get cycling like the button is being held down. I put a "debounce" pause and still no luck. I'm running the exact script on my other Pi. same pins and all, and it"s running just fine. Could the GPIO be faulty from factory to cause this?

MaxK1
Posts: 1043
Joined: Sun Aug 26, 2012 11:34 pm

Re: GPIO Cycle after button

Mon Sep 29, 2014 1:02 pm

You sure it's not an on/off switch? (as opposed to a momentary switch)
You are in a maze of twisty little passages, all alike.
When General Failure and Major Disaster get together, Private Parts usually suffers.

User avatar
croston
Posts: 702
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: GPIO Cycle after button

Mon Sep 29, 2014 1:03 pm

What version of RPI.GPIO are you using on each pi?

Code: Select all

import RPI.GPIO as GPIO
print(GPIO.VERSION)
will tell you.

kylerichards89
Posts: 98
Joined: Sun Aug 31, 2014 12:42 am

Re: GPIO Cycle after button

Mon Sep 29, 2014 10:39 pm

0.5.7, the newest one. It's just weird that it worked on my old one, and now it doesn't. I'm setting up the code like this:

Code: Select all

####other code####
led1 = 6                                                                       # LED 1
button1 = 4                                                                    # Pin For The Start Button(Red)
button2 = 17                                                                   # Pin For Button To Shutdown The Pi
button3 = 27                                                                   # Pin For Button To End The Program. Will Not Shutdown The Pi
pause = time.sleep                                                             # Variable for Pause Function
photodate = datetime.datetime.now().strftime("%m_%d_%Y_%H_%M_%S")              # Timestamp for file name
PICTURE=('/home/pi/photobooth/'+ photodate + '.jpg') 

GPIO.setmode(GPIO.BCM)
GPIO.setup(led1, GPIO.OUT)                                                        # LED 1
GPIO.setup(button1, GPIO.IN, GPIO.PUD_UP)                                            # Falling Edge Detection On Button 1
GPIO.setup(button2, GPIO.IN, GPIO.PUD_UP)                                           # Falling Edge Detection On Button 2
GPIO.setup(button3, GPIO.IN, GPIO.PUD_UP)                                           # Falling Edge Detection On Button 3

####bunch of other code#######
while True:
    with picamera.PiCamera() as camera:
        camera.hflip = True                                                        # Flip Camera. Not Mirriored
        camera.start_preview()                                                     # Start Displaying Camera
        camera.annotate_text = 'Press Red Button To Take Photo'
        GPIO.wait_for_edge(button1, GPIO.FALLING)                              # Wait For Button1 To Be Pushed
        time.sleep(0.1)                                                        # Debounce
        camera.stop_preview()                                                      # Stop Displaying Camera
        camera.close()
        Start_Photobooth()                                                     # Start Start_Photobooth Code
And my circuit is simply the pin from the GPIO to the switch with a 1k Ohm resistor in between and then the other side of the switch is to GND. When script starts, 3.3v is on the pin awaiting to be low when button is pressed. Even with the resistor out of the circuit, it stills continues to cycle through like I'm pushing the button every second.

kylerichards89
Posts: 98
Joined: Sun Aug 31, 2014 12:42 am

Re: GPIO Cycle after button

Tue Sep 30, 2014 4:51 pm

Also, it is a momentary switch and I've tried several just to be sure. I may be mistaken, but I'm almost positive the 0.5.7 GPIO is what broke it. The software pull up resistors are acting funny on two different boards. Thus cause the wait for edge to go crazy and think the button is being pushed repeatly.

After uninstalling 0.5.7 and installing 0.5.6 the issue is resolved.

User avatar
croston
Posts: 702
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: GPIO Cycle after button

Sun Oct 12, 2014 10:45 pm

I've fixed the bug in RPI.GPIO with wait_for_edge(). To pick up the fix, install the latest development version:

https://sourceforge.net/p/raspberry-gpi ... i/install/

kylerichards89
Posts: 98
Joined: Sun Aug 31, 2014 12:42 am

Re: GPIO Cycle after button

Mon Oct 27, 2014 2:58 am

croston wrote:I've fixed the bug in RPI.GPIO with wait_for_edge(). To pick up the fix, install the latest development version:

https://sourceforge.net/p/raspberry-gpi ... i/install/
I tried this and it wasn't successful. I keep getting the following error:

Code: Select all

cc1: error: unrecognized command line option ‘-fstack-protector-strong’

error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/RPi.GPIO/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-c9JNfW-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/RPi.GPIO
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 235, in main
    return command.main(cmd_args)
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 161, in main
    text = '\n'.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 49: ordinal not in range(128)

kylerichards89
Posts: 98
Joined: Sun Aug 31, 2014 12:42 am

Re: GPIO Cycle after button

Fri Oct 31, 2014 3:22 pm

I did get it to install, but the issue is still there. I know it has to be in the module, because the minute I downgrade back to 0.5.6, the issue is gone!

GeofP
Posts: 28
Joined: Fri Jan 31, 2014 9:59 am
Location: NE Hampshire UK

Re: GPIO Cycle after button

Tue Nov 18, 2014 11:54 am

I have the same problem. I use a switch to trigger a camera when a garden gate is opened. This has been working for many months but after updating my Pi yesterday from 3.12.21+ #689 to 3.12.28+ #709, one edge trigger causes the camera trigger code to loop non-stop. I have tried adding a bouncetime = 1000 but this made no difference.

My RPi.GPIO is now at version 0.5.8. My code as as follows, the variable 'counter' keeps incrementing until I stop the script with Ctl C. Another problem is that when the script is re-run, sometimes the LED on pin 25 comes on straight away instead of after the edge trigger.

Code: Select all

# gate-trigger.py

# Ver 1  10/6/2014  from interrupt1.py
# Ver 2  21/6/2014 changed subprocess to call using user pi, dirs are now created with pi permissions not root.
#__________________________________________________________________________________________
#setup

import RPi.GPIO as GPIO
import subprocess
import time
GPIO.setmode(GPIO.BCM)

# GPIO 23 set up as input. It is pulled up and decoupled with 100nF capacitor to stop false signals
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# GPIO 25 set as output to control LED
GPIO.setup(25, GPIO.OUT)

#__________________________________________________________________________________________

print "Waiting for gate to trigger with falling edge on port 23"

counter = 1
try:
    while True:
      GPIO.wait_for_edge(23, GPIO.FALLING)
      print "\nGate trigger detected.", counter
      # turn on LED
      GPIO.output(25,GPIO.HIGH)
      counter = counter + 1
      print "Call camera and email routine and wait for another one."
      subprocess.call(["sudo", "-u", "pi", "/home/pi/bin/camera", "record", "2"])
      # turn off LED
      GPIO.output(25,GPIO.LOW)
      time.sleep(1)

except KeyboardInterrupt:
    GPIO.cleanup()       # clean up GPIO on CTRL+C exit
GPIO.cleanup()           # clean up GPIO on normal exit
I will find out how to use an older version of RPi.GPIO and check the result.
Has anyone else had this problem?

GeofP
Posts: 28
Joined: Fri Jan 31, 2014 9:59 am
Location: NE Hampshire UK

Re: GPIO Cycle after button

Tue Nov 18, 2014 12:55 pm

Hi kylerichards89.
Could you (or someone else) please show me how to uninstall RPi.GPIO 0.5.8 and install 0.5.6. I Tried the method given in http://www.raspberrypi-spy.co.uk/2012/0 ... n-library/, but when I do the install step 4, I get a fatel error.

kylerichards89
Posts: 98
Joined: Sun Aug 31, 2014 12:42 am

Re: GPIO Cycle after button

Wed Nov 19, 2014 3:12 am

To uninstall use

Code: Select all

sudo apt-get remove RPi.GPIO
And following the link you posted gives you a step-by-step on how to download and install an earlier version. Use

Code: Select all

wget https://pypi.python.org/packages/source/R/RPi.GPIO/RPi.GPIO-0.5.6.tar.gz
to get the latest version without the wait.for.edge error. If you get an error downloading and extracting the .tar.gz, try downloading it on a flash drive and copying the .tar.gz to the /home/pi directory. Remember, everything in the step-by-step guide refers to 0.5.5, you will need to change it to 0.5.6 for each step. Please post any errors you get if you still get a fatal error.

GeofP
Posts: 28
Joined: Fri Jan 31, 2014 9:59 am
Location: NE Hampshire UK

Re: GPIO Cycle after button

Wed Nov 19, 2014 9:53 am

Thanks for the reply, kylerichards89.
That was the procedure I carried out, using 0.5.6.
At step 4 I received the following errors after entering the command: sudo python setup.py install.

Code: Select all

running install
running build
running build_py
creating build
creating build/lib.linux-armv6l-2.7
creating build/lib.linux-armv6l-2.7/RPi
copying RPi/__init__.py -> build/lib.linux-armv6l-2.7/RPi
running build_ext
building 'RPi.GPIO' extension
creating build/temp.linux-armv6l-2.7
creating build/temp.linux-armv6l-2.7/source
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c source/py_gpio.c -o build/temp.linux-armv6l-2.7/source/py_gpio.o
source/py_gpio.c:23:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1

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

Re: GPIO Cycle after button

Wed Nov 19, 2014 10:17 am

sudo apt-get install python-dev

kylerichards89
Posts: 98
Joined: Sun Aug 31, 2014 12:42 am

Re: GPIO Cycle after button

Fri Nov 21, 2014 1:54 am

GeofP wrote:Thanks for the reply, kylerichards89.
That was the procedure I carried out, using 0.5.6.
At step 4 I received the following errors after entering the command: sudo python setup.py install.

Code: Select all

running install
running build
running build_py
creating build
creating build/lib.linux-armv6l-2.7
creating build/lib.linux-armv6l-2.7/RPi
copying RPi/__init__.py -> build/lib.linux-armv6l-2.7/RPi
running build_ext
building 'RPi.GPIO' extension
creating build/temp.linux-armv6l-2.7
creating build/temp.linux-armv6l-2.7/source
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c source/py_gpio.c -o build/temp.linux-armv6l-2.7/source/py_gpio.o
source/py_gpio.c:23:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
Have you resolved this issue yet? Let me know if you still need help. I have another solution for you to try if you still need help!

GeofP
Posts: 28
Joined: Fri Jan 31, 2014 9:59 am
Location: NE Hampshire UK

Re: GPIO Cycle after button

Sat Nov 22, 2014 7:28 am

I have a work-around for the problem.

I did not pursue rolling back the RPi.GPIO module because next time I were to do a general software update, the module would get replaced with the later faulty one.

Since I only need a slow repeat rate for the GPIO.wait_for_edge, after executing the code following the edge detection, I reset the function with GPIO.cleanup() at the end of the "while True" loop and moved setting up the GPIO pins at the start of the loop.

How do we initiate getting the RPI.GPIO code fixed?

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

Re: GPIO Cycle after button

Sat Nov 22, 2014 8:44 am

GeofP wrote: ...
How do we initiate getting the RPI.GPIO code fixed?
See http://sourceforge.net/p/raspberry-gpio-python/tickets/

You'll need to be registered/logged-in to open a new ticket.

GeofP
Posts: 28
Joined: Fri Jan 31, 2014 9:59 am
Location: NE Hampshire UK

Re: GPIO Cycle after button

Mon Nov 24, 2014 7:55 am

OK, I have raised ticket 86 against raspberry-gpio-python on sourceforge.net

GeofP
Posts: 28
Joined: Fri Jan 31, 2014 9:59 am
Location: NE Hampshire UK

Re: GPIO Cycle after button

Fri Feb 06, 2015 9:43 am

Just confirming that the code now works fine in version 0.5.9. Thank you Ben Croston!

Return to “Troubleshooting”