1

I have recently bought a Raspberry Pi 3B, for a project where I require a program to recognize a pressed button and do something after that. It seems a common and pretty easy task for a Pi, however I am starting by creating minimal examples to get acquainted with GPIO and electrical stuff (I am a developer, not an electrical engineer).

Gathered from various examples across the internet I have done the following:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.IN)

while True:
    if not GPIO.input(11):
        print("Button pressed")
        time.sleep(0.2)

My circuit can be seen on the following screen: Circuit

The resistor between blue and red is 10k Ohm, the one to the ground is 1k Ohm.

I start the program using sudo python test.py

I use standard raspbian (freshly flashed, everything updated)

Can somebody see what I am doing wrong? The print statement is not issued if connect the green and red wire at the bottom manually.

  • Your code prints something if the two wires are NOT connected. To the Pi, 3V3 is a logic high and GPIO.input() will return True. not True evaluates to False and it doesn't print anything when pressed. But when it's not pressed, GPIO.input() returns False, and not False evaluates to True and it does print something. Remove the not and try again. – anonymoose Apr 22 '17 at 16:07
  • If that doesn't work, then here's the hardware troubleshooting list: Try connecting the blue wire directly to 3V3 to see if that triggers it. If it doesn't, then you have either: (1) Bad jumper wires/breakout/ribbon cable (2) Broken Pi. If you have a multimeter, check all your wires for continuity. – anonymoose Apr 22 '17 at 16:09
  • 1
    The circuit appears correct as far as can be told. A common error is to connect the ribbon cable between the Pi and cobbler the wrong way around. – joan Apr 22 '17 at 16:13
  • @joan: The brown cable on the left side of the ribbon is connected to the left side on the board (opposite of usb, towards the lcd connector) – Crumar Apr 22 '17 at 16:16
  • @anonymoose can i safely connect just 3V3 and GPIO 17? – Crumar Apr 22 '17 at 16:17

Your Answer

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

Browse other questions tagged or ask your own question.