-1

I have project requiring several simple LEDs and buttons, MORE that the number of ‘simple’ GPIO pins. Can I turn the LED TOTALLY OFF and on using a IC2, SPI, or UART pin? Can those pins be programed to respond to button pushes?

I did a test with such a pin, GPIO2 (Pin 3). The result was when wired up initially, the LED was on. When I ran a simple blink program, setting the LED to on would brighten the LED. Setting the LED to off would dim, but not turn off, the LED.

I have a simple circuit: GPIO2 to LED to 1K resistor to ground.

Is it possible to fully turn off an LED connected to a IC2, SPI, or UART Pin?

I know this is similar this question. However, that one does not address turning the LED completely off.

Howto: Power on/off for GPIO3 (Pin 5)

My code is

import time
import sys
from gpiozero import LED

green = LED(2)
green.off()
green.on()
time.sleep(3)
green.off()
3
  • The GPIO pins are not intended to be used to drive LED's directly. Instead use the GPIO to operate a transistor. There are many, many examples of this. Then you will be able to turn the LED off.
    – Wendall
    Commented Mar 6, 2022 at 22:12
  • @Wendall: That's not strictly true. Many low-current LEDs can easily be driven from a GPIO pin (don't forget the series current-limiting resistor,
    – Seamus
    Commented Mar 8, 2022 at 1:57
  • Seamus, I agree, but you won't get them to turn all the way OFF.
    – Wendall
    Commented Mar 8, 2022 at 13:43

1 Answer 1

1

All the GPIO can be used as "ordinary" inputs and outputs regardless of any special modes they might have.

There are a couple of things to note:

  1. GPIO 2 and 3 (pins 3 and 5) have hard wired 1k8 pull-ups to 3V3 fitted.
  2. All the GPIO have weak internal pulls. These may be set to up, down, or off. GPIO 0-8 default to pull-ups, other GPIO to pull-downs.

These pulls will mean the GPIO have a default voltage of 3V3 for those with pull-ups and 0V for those with pull-downs. This will affect connected circuitry (e.g. LEDs may light, a relay may operate, a motor might be set to run).

2
  • Thanks, but I still do not see how I can turn on an LED via GPIO2 using gpiozero library. I understand that GPIO 0-8 default to pull-up. Can that be overridden with gpiozero? I know it can be overidden with RPi.GPIO GPIO.setup(gpio_number, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) But how do I make LED.off() in the gpiozero library turn off the led? Can I not do it using gpiozero? My multi-meter tells the the off state is 2.56V and my on state is 3.19V Commented Mar 7, 2022 at 0:17
  • I answered the question as given. If you have a new question you need to post a new question.
    – joan
    Commented Mar 7, 2022 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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