1

I have tried connecting a LED with a button like this (from "Adventures in RPi"), but with the far end of the button plugged at G (instead of F). breadboard

And I ran it with the following Python program (by following instructions from the said book):

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.OUT)
GPIO.setup(24, GPIO.IN)
while True:
    if GPIO.input(24):
        GPIO.output(23, True)
    else:
        GPIO.output(23, False)
        time.sleep(0.1)

But when I tried running the program it didn't work. To debugg it I changed the if code block to this:

    print("button")
    ##GPIO.output(23, True)

And it resulted in many prints of "button"...

  • How can I fix the program (or wiring?) so that the button will turn the LED on?

Thx in advance! :)

EDIT: Here are photos of the actual wiring: photo of wiring 1

  • Yes if you tell Python to print something, it will do so indefinitely unless you've written code to tell it otherwise. – Darth Vader Apr 25 '16 at 19:02
  • 2
    There only a few things to go wrong. 1) the LED is the wrong way around, 2) the LED is not connected to GPIO 23. Can you post a photo of your set-up? Diagrams may show your intent - they do not show what you have done. – joan Apr 25 '16 at 19:18
  • @Joan do you mind if I steal your phrasing above re: intent vs done? I like your wording better than mine. – Steve Robillard Apr 25 '16 at 19:56
  • @SteveRobillard Not at all, it'a a bit of a cliche. :-) – joan Apr 25 '16 at 20:07
  • @SteveRobillard If you could steal Joan's sentence then she wouldn't be able to remember it anymore, right? Splitting hairs, I know... – user29510 Apr 25 '16 at 20:41

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.