So on all sites that have tutorials on attaching a led to gpio, they use a resistor. Could I wire a led to a input/output pin and use an internal pull-up or pull-down resistor?
This can be done for very low power indicators that are specifically for this purpose and usually quite dim. But generally speaking No, this is not possible.
Note: Some LED manufacturers can provide an LED with a built in current limiting resistor. This is often seen in illuminated buttons or indicator LED's integrated into connectors (e.g. ethernet port LED)
There are a few things that are problematic here.
- The Internal PU/PD is not precise and is usually quite large, for the BCM I believe it is approximately 50Kohm
- 50K Ohm resistance will provide 20-100uA into a typical diode, this is a safe value for GPIO but not nearly enough to drive a typical indicator LED (2mA-200mA)
- Configuring the GPIO as output without an external resistor will immediately fry the GPIO port and likely the whole CPU
- GPIO state can be changed inadvertently or during bootup by default scripts.
If you do find a low power LED that provides sufficient lighting at 10-100uA current for your purposes, extreme care must be taken that pins are configured only as
INPUT and the PU/PD state used to toggle the LED. This is an inherently unsafe situation in case of bug or crash.
When one designs a custom board, an extra 0603 or 0402 resistor comes at a small footprint cost and less than 1 US cent per board. Usually this trade-off is worth doing if you prevent even one fried CPU during testing or in the field.
In another word no. Your RPi GPIO pins can only source or sink 16mA. If you run an LED without a resistor you're risking letting the magic blue smoke escape. Once that happens it costs £35 to refill an new RPi with new magic blue smoke.
In a word No. An led needs a resistor in series to limit the current, pull up and pull down resistors aren't wired that way.