6

I'm trying to do a pretty basic 'get an LED' to blink tutorial with a Raspberry Pi Zero. Following this guide:

Blink: Making An LED Blink On A Raspberry Pi

I'm able to get the LED to turn on and off with the gpio command line utility, and the sample code for using RPi.GPIO works fine as well, but I can not get the GPIO Zero example to work.

from gpiozero import LED
from time import sleep

redLED = LED(21)

print "Press CTRL-C to exit."
try:
   while True:
      redLED.on()
      sleep(0.5)
      redLED.off()
      sleep(0.5)

finally:
   redLED.close()
   print "\nCompleted cleanup of GPIO resources."

The code executes with no errors, but the LED doesn't blink. What things can I try to troubleshoot likely problems?

Since the command line and the RPi.GPIO examples work, I'm sure the LED and resistor are wired up correctly, so I'm not sure what to try next.

Lorin
  • 1,022
  • 1
  • 8
  • 14
  • `while True` ?? Isn't this an infinite loop? – Black Sep 19 '18 at 17:51
  • yeah, it's an infinite loop that should just blink the LED on and off forever. But nothing happens. – Lorin Sep 19 '18 at 17:54
  • Does `redLED.on()` and `redLED.off()` work on their own in a REPL/shell? If you can't independently turn it on and off with those functions you might not have it wired up right. – ben_nuttall Jan 14 '19 at 22:06
  • It's probably that you're using BOARD numbering not BCM. See https://pinout.xyz - GPIO Zero uses BCM numbering. – ben_nuttall Feb 24 '19 at 18:48

0 Answers0