3

I want to connect a keypad. Can I use just the gpio pins without a protoboard? Will this work?

enter image description here

3

Yes, the keypad you linked to would work because it treats each individual button as a separate switch. This tutorial describes how to connect switches to raspberry pi GPIO pins. The keypad won't need any additional hardware because the GPIO pins (some of them, at least—I'm not sure if they all do) have pull-up resistors.

3
  • But I don't see any place explaning witch pin I should put this keypad. Like "you can use pins 1-5 or 21-26 to make it work". – Makah May 21 '14 at 12:43
  • Well, no, it wasn't designed with that in mind. You will have to determine which pins to attach it to, and they aren't likely to be all in a row. You would end up attaching each wire individually to a pin that works. It's probably that four of them can be together. – krs013 May 22 '14 at 8:24
  • If you want something that can be plugged in and just work, you're probably better off with a USB keypad of some sort. – krs013 May 22 '14 at 8:25
2

enter image description here

Pulling GPIO LOW - You set your GPIO HIGH

  • BLACK - Common, connect to to GND

Alternative pulling GPIO HIGH - You set your GPIO LOW

  • BLACK - VCC, Connect to 3v3

GPIO

  • PURPLE,BLUE,GREEN, ORANGE - Switches, connect to any 4 available GPIO Pins

Then you need to write code to detect the rising edge or falling edge for the GPIO. The Raspberry Pi already has built in resistors on the GPIO so you can connect directly to the GPIO but DO NOT EXCEED 3v3 In other words do not connect to the 5v0 PIN.

Say you connected the black to 3v3 then you would setup the GPIO pin to be LOW and detect on Rising Edge.

enter image description here

Some sample Python code for detecting Rising Edge

import RPi.GPIO as GPIO
import time
import os

#adjust for where your switch is connected
buttonPin = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(buttonPin,GPIO.IN)

while True:
  #assuming the script to call is long enough we can ignore bouncing
  if (GPIO.input(buttonPin)):
    #this is the script that will be called (as root)
    os.system("python /home/pi/start.py")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.