lucas1
Posts: 6
Joined: Sun Jul 22, 2018 7:39 am

raspberry pi connect button problem

Sat Mar 30, 2019 5:48 pm

Hi, is it possible to connect such a button to the raspberry pi and read values from GPIO?
Image
Am I forced to connect all 5 pins from this button? I tried only with 3.3 v, GMD and pin "C" but I received unstable results. Something like 111111000000001111111


I tested using this code

Code: Select all

import RPi.GPIO as GPIO
import time


GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_UP)
for _ in range(100000):
    time.sleep(0.5)
    print(GPIO.input(7))

User avatar
B.Goode
Posts: 8906
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: raspberry pi connect button problem

Sat Mar 30, 2019 5:55 pm

Purely a guess - looking at the documentation or data sheet for the assembly would be more reliable - but my interpretation would be C = Common; NC = Normally Closed; NO = Normally Open.

So I would use C and whichever of the other 2 seems to match your needs.

PhatFil
Posts: 1424
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: raspberry pi connect button problem

Sat Mar 30, 2019 5:58 pm

connect either 3.3v or Gnd to C (common).

then connect either NC (Normally closed) or NO (Normally Open) to a gpio pin. NO for normal use...

you should also probably use a pull up/down resistor too

https://grantwinney.com/using-pullup-an ... pberry-pi/

If C (Common) is connected to +3v3 a 220ohm resistor between your button gpio and gnd will pull the signal down to gnd when the button is not pressed

if you connected gnd to common use the 220ohm resistor to connect the gpio to +3v3 to pull the signal high when not pressed.



edit ** disconnect the pi from power before touching the gpio and check everything 3 times before powering back up.

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

Re: raspberry pi connect button problem

Sat Mar 30, 2019 7:16 pm

At a guess, the other pins labelled + and - are for an in-built LED and can be ignored.

User avatar
ptimlin
Posts: 88
Joined: Tue Jan 08, 2019 7:44 pm

Re: raspberry pi connect button problem

Sun Mar 31, 2019 8:45 pm

Burngate wrote:
Sat Mar 30, 2019 7:16 pm
At a guess, the other pins labelled + and - are for an in-built LED and can be ignored.
Agreed. This is a lighted button and if the original poster wants to just use the switch then they need "C" and then at least one other of the NC or NO terminals. "C" all by itself, as in the original post, does nothing for you. Switch schematic should be...
8f7be652fd6897590ed8032fcd5a912eb0ed1233.jpg
8f7be652fd6897590ed8032fcd5a912eb0ed1233.jpg (7.75 KiB) Viewed 290 times
When the switch is not being pushed then C and NC (normally closed) are shorted together. When you push the button then C switches over to short with NO (normally open but now that you are pushing the button, you are no longer "normal" default state).

Return to “Automation, sensing and robotics”