Uncategorized

GpioZero LED blinking problem

Asked 
Viewed 9 times

This post has been deleted and is no longer viewable

0

I am trying turn to an LED on and off on my breadboard with my Pi. I’m using the Adafruit T-Cobbler Plus to connect to my Pi 4 Model B’s GPIO pins. Im trying to use the sample code from the raspberrypi website to test the functionality but nothing happens when I run the code.

from gpiozero import LED

from time import sleep

led = LED(17)

while True:

    led.on()
    sleep(1)
    led.off()
    sleep(1)

When I run the program it does nothing and no error messages. I have tried changing the GPIO number in the “led” variable to different pins and I’ve tried connecting my wire to different GPIOs on the cobbler. Nothing seems to happen and I don’t get any error messages. The program seems to run fine .

Is there a difference between the Pi 3 and Pi 4 pinouts that make my cobbler incompatible? Is there a different program I need to use? I have no idea what to do.

 New contributor
  • What makes you think it doesn’t work? You have provided no detail of what you did. There should be no difference in pinout although Pi4 has more configuration options. – Milliways 1 hour ago
  • It isn’t working because the LED isn’t doing anything on the board. I tried using the wiringpi pin number and then the physical pin number, when defining the “led” variable and it still hasn’t worked.(The 17 in LED(17) is referring to the BCM number) If it’s necessary I can also provide a picture of my wiring. – jarzuaga3 52 mins ago
  • I am not that interested in pictures (most are unreadable). You should describe your setup in the question. You should learn to debug your hardware and software separately. Does the LED light if you connect to 3.3V? If you write a code which toggles the pin slowly you can use other code to see if it changes. – Milliways 45 mins ago
  • You used to be able to observe pin states with gpio readall but this no longer works on the Pi4 I have written a program to report pin states raspberrypi.stackexchange.com/a/106099/8697 but there are other options. – Milliways 43 mins ago

Your Answer

 jarzuaga3 is a new contributor. Be nice, and check out our Code of Conduct.
community wiki

Answer V0.1

There are 101 reasons that your little LED is not blinking as you expect:

(1) You have not used a resistor to limit the current passing through the LED (Note 1). Without this current limiting resistor, too big current would pass through the LED and fry it.

(2) You have not connected the LED in the correct polarity. The wiring should be something like this:

(a) 3.3V (Note 1) to either end of the current limiting resistor.

(b) The other, now dangling, end of resister connected to the long leg (Note 2) of LED.

(c) The short leg of the LED connected to GPIO 17 (Note 3).


Notes

Note 1 – You can use the 3.3V power pin of the Rpi’s 40 pin connector for the LED

Note 2 – Current limiting resistor is usually from 330 Ohms up to 1,200 Ohms.

Note 2 – GpioZero uses BCM numbering for GPIO pins. See Reference 3 below for more details.

Note 4 – For a LED, the long leg is the positive, anode terminal to where current comes in from positive 3.3V; the short leg is the negative, cathode terminal from which current goes out, to the GPIO pin.


References

(1) GpioZero Doc

(2) GpioZero Doc > LED > 14.1.1. LED

(3) GpioZero Doc > 2.2. Pin Numbering

This library uses Broadcom (BCM) pin numbering for the GPIO pins, as opposed to physical (BOARD) numbering. Unlike in the RPi.GPIO library, this is not configurable, …

Any pin marked “GPIO” in the diagram below can be used as a pin number. For example, if an LED was attached to “GPIO17” you would specify the pin number as 17 rather than 11.


End of answer


Post Your Answer Discard
.END

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: