bswin821
Posts: 10
Joined: Sat Mar 24, 2018 9:53 pm

Remote GPIO button input

Sat Mar 24, 2018 10:09 pm

Good Evening,

I have been working on a raspberry pi custom built Dr. Who doorbell for some time. I would like to use a raspberry pi zero that i will install behind the front doorbell to activate my program. I have successfully run the script that will communicate with the correct pin and run my program which selects random mp3's from the show and plays them via my other RPI. However for the life of me i cannot ascertain why the button I have wired cannot be used as reliable input. What i mean is the program starts and loops continuously. I am trying to have the script run and await input so when i press what will be the front doorbell (my button) then the audio will play. Ive done this successfully before. Just not using remote GPIO. It was wired and i used RPi.GPIO. My script is as follows.

Code: Select all

from gpiozero import *
from gpiozero.pins.pigpio import PiGPIOFactory
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP)

factory = PiGPIOFactory(host='192.168.1.13')
led = LED(18, pin_factory=factory)

while True:
        input_state = GPIO.input(3)
        if input_state == False:
             led.on()
             time.sleep(1)
             led.off()
Right now when run, My other script on my other RPI runs in a loop instead of awaiting input. Any help is greatly appreciated.

User avatar
Z80 Refugee
Posts: 61
Joined: Sun Feb 09, 2014 1:53 pm

Re: Remote GPIO button input

Sun Mar 25, 2018 8:00 am

First of all you need to check the switch is wired correctly. See HERE and skim down to the section on Hardware Interfacing.

(I apologise if this is below your level, but it is not possible to tell from your post)

I appreciate the problem may well be in the software accessing the remote unit, but a poor switch input circuit may work in some circumstances and not in others. It will be a bugger to sort out a software problem if the hardware isn't reliable.
Last edited by Z80 Refugee on Sun Mar 25, 2018 9:23 am, edited 1 time in total.

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

Re: Remote GPIO button input

Sun Mar 25, 2018 8:43 am

You are reading the button (GPIO3) with RPi.GPIO. That means the button is connected to the Pi running the script. Is that what you intended?

The LED appears to be connected to a remote Pi at 192.168.1.13.

bswin821
Posts: 10
Joined: Sat Mar 24, 2018 9:53 pm

Re: Remote GPIO button input

Sun Mar 25, 2018 12:41 pm

Yes, I have a push button connected to the RPI zero and I’m attempting to use RPI.GPIO to push that button which will then connect to my RPI 3 and run my other script. I know that the remote GPIO works bc it connects and runs my other script. I just can’t seem to get it to wait for a button press. It just runs and runs.

bswin821
Posts: 10
Joined: Sat Mar 24, 2018 9:53 pm

Re: Remote GPIO button input

Sun Mar 25, 2018 12:46 pm

I’m using LED on pin 18 to send the signal on the RPI 3 to run that pin high which runs my script. However it seems to send that signal and run high and stay that way almost simulating as if I was holding a physical button down that was connected to pin 18 on the RPI 3. I want to send the signal to turn it on then off. Like a physical button would

bswin821
Posts: 10
Joined: Sat Mar 24, 2018 9:53 pm

Re: Remote GPIO button input

Sun Mar 25, 2018 12:49 pm

There may be a better way to do this than to use LED. I only used it bc I knew that would turn that pin on and that is where my other button was attached to the RPI 3

User avatar
Z80 Refugee
Posts: 61
Joined: Sun Feb 09, 2014 1:53 pm

Re: Remote GPIO button input

Sun Mar 25, 2018 9:27 pm

I'm having difficulty understanding what you mean. Draw a diagram of what you have wired up, take a photo of it, and post it up.

bswin821
Posts: 10
Joined: Sat Mar 24, 2018 9:53 pm

Re: Remote GPIO button input

Sun Mar 25, 2018 10:43 pm

File was too large to attach. RPI 1 is an RPI zero with a button attached. RPI 2 has a script that plays MP3’s. That currently runs via the button attached to pin 18 on RPI 2. When I run the script on RPI 1 it does not wait until the attached button is pressed. It just runs and connects to RPI 2 pin 18 and plays the mp3’s In an endless loop. I need it to wait for the button press on RPI 1.

User avatar
Z80 Refugee
Posts: 61
Joined: Sun Feb 09, 2014 1:53 pm

Re: Remote GPIO button input

Mon Mar 26, 2018 7:03 am

If the photo is too large a file you can either reduce its resolution or post it on a photo hosting site (even Facebook) and post a link to it.

You talked about a LED, and that confused me. Where does that come into it exactly? Your posts don't read properly (presumably because of typos) so I find them hard to follow.

Does your program work correctly if you run it on the actual RPi that has the switch fitted (not move the switch to the "near" RPi but run the program on the "far" RPi? Have you looked at my article (linked in post 2) to check your circuit is correct? I'm trying to help but you need to provide some feedback.

Other people are trying to help with observations about the software, but again you need to enter into a discussion about it and show what changes you have made to your code in response to their suggestions. I know hardware inside out, I'll leave the software to people who know better than me.

As a general comment: running two RPi's 24/7 just to provide a fancy doorbell sounds very expensive to run compared with (for example) putting a programmable sound chip into an off-the-shelf musical doorbell. I appreciate you may be just trying to see if you can do it, but I wouldn't recommend it as a permanent installation.

bswin821
Posts: 10
Joined: Sat Mar 24, 2018 9:53 pm

Re: Remote GPIO button input

Mon Mar 26, 2018 11:13 am

joan wrote:
Sun Mar 25, 2018 8:43 am
You are reading the button (GPIO3) with RPi.GPIO. That means the button is connected to the Pi running the script. Is that what you intended?

The LED appears to be connected to a remote Pi at 192.168.1.13.
Yes, I have a physical button connected to the first RPI and I’m trying to remotely trigger pin 18 on the RPI at 192.168.1.13. I cant get it to wait for my button press. It connects and runs in a loop for some reason.

bswin821
Posts: 10
Joined: Sat Mar 24, 2018 9:53 pm

Re: Remote GPIO button input

Mon Mar 26, 2018 11:19 am

Z80 Refugee wrote:
Mon Mar 26, 2018 7:03 am
If the photo is too large a file you can either reduce its resolution or post it on a photo hosting site (even Facebook) and post a link to it.

You talked about a LED, and that confused me. Where does that come into it exactly? Your posts don't read properly (presumably because of typos) so I find them hard to follow.


The thing is I don’t believe it’s a hardware issue. The RPI with the MP3’s runs fine on its own if a button is connected and the RPI with the button connected using the script is able to use remote GPIO to access and run those MP3s. It just won’t wait for the press of the button before running and runs in a loop. I’ll post my updates to my script tonight. I was an using LED not to light an led but to just trigger that pin. The goal is to trigger the pin with the button on the first RPI and have it remotely connect and trigger the pin on the second RPI.
Does your program work correctly if you run it on the actual RPi that has the switch fitted (not move the switch to the "near" RPi but run the program on the "far" RPi? Have you looked at my article (linked in post 2) to check your circuit is correct? I'm trying to help but you need to provide some feedback.

Other people are trying to help with observations about the software, but again you need to enter into a discussion about it and show what changes you have made to your code in response to their suggestions. I know hardware inside out, I'll leave the software to people who know better than me.

As a general comment: running two RPi's 24/7 just to provide a fancy doorbell sounds very expensive to run compared with (for example) putting a programmable sound chip into an off-the-shelf musical doorbell. I appreciate you may be just trying to see if you can do it, but I wouldn't recommend it as a permanent installation.

User avatar
Z80 Refugee
Posts: 61
Joined: Sun Feb 09, 2014 1:53 pm

Re: Remote GPIO button input

Tue Mar 27, 2018 8:45 am

bswin821 wrote:
Mon Mar 26, 2018 11:19 am
The thing is I don’t believe it’s a hardware issue. The RPI with the MP3’s runs fine on its own if a button is connected and the RPI with the button connected using the script is able to use remote GPIO to access and run those MP3s. It just won’t wait for the press of the button before running and runs in a loop. I’ll post my updates to my script tonight. I was an using LED not to light an led but to just trigger that pin. The goal is to trigger the pin with the button on the first RPI and have it remotely connect and trigger the pin on the second RPI.
It might not be a hardware issue, but I am trying to explain that if you take liberties with how you connect the hardware, it may work as expected sometimes and not others. I'm sure there are software issues too, but before you focus on those it would be best to ensure the hardware has no chance of not working the way you intend. Trigger a pin using a LED? Whatever gave you the idea that will work?

Sorry, but until I see the circuit you want to use, I can't help.

(Your post above is, again, hard to read - take a look and see what I mean. You can go back and edit posts - use the pen icon button top right of the post.)

bswin821
Posts: 10
Joined: Sat Mar 24, 2018 9:53 pm

Re: Remote GPIO button input

Tue Mar 27, 2018 9:00 am

You were right and it was actually both hardware and software. I am horrible at soldering. After your reply yesterday I tested the button with a print statement and realized the joint was loose. I also realized through research that RPI.GPIO is the default for gpiozero so the syntax is wrong and it’s built in. Also the led function being used to turn that pin off and on is backwards. The PUD is up by default in my other script so led.off runs it and on stops it. By having it backwards when it doesn’t read the button push which it isn’t it runs. I’m going to hold the pins flush and re solder then make those changes and it should work. It’s always what you think it can’t be. Thank you for your help and input.

Forris
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 214
Joined: Fri Jan 06, 2012 7:46 pm

Re: Remote GPIO button input

Thu Mar 29, 2018 3:44 pm

I realise that you've solved this now, but my concern was that you are using gpiozero and RPI.GPIO at the same time. If you just stuck with one or the other (I would suggest gpiozero as that is where the remote functionality is) you would make it so much simpler and if you check the excellent gpiozero documentation, you will find a example to to pretty much what you are trying - https://gpiozero.readthedocs.io/en/stab ... _gpio.html

bswin821
Posts: 10
Joined: Sat Mar 24, 2018 9:53 pm

Re: Remote GPIO button input

Thu Mar 29, 2018 5:29 pm

I’m using gpiozero. RPI is built in so the syntax is different. I got it working with gpiozero using LED and Button.

factory = GPIOFactory(host=‘192.168.1.13’)
Led = LED(18, pin_factory=factory)
button =Button(3)

while True:
If button.is_pressed:
led.off()
led.on()
else:
led.on()

Return to “Python”

Who is online

Users browsing this forum: lmarmisa and 6 guests