I have a bunch of stuff set up on my pi (RPI 3 for the record), but one of the things I want to run is an RGB LED which is common anode. I have successfully gotten it working by connecting the common anode to the 5V rail (board pin 2) and then connecting the other 3 pins of the LED to 3 separate GPIO pins (GPIO pin 9, 10 and 11) also using resisters. In my code, I set the GPIO pins as outputs and then set them to low when I want the led to turn on. My question is, is it safe to have this connected when the RPI starts up, my code does not run automatically so i just have the pins connected with out telling the RPI what to do with the GPIO pins. The LED lights up softly when the RPI starts so the pi is allowing current into the GPIO pins.

I can provide code if needed. thanks

  • Most LEDs will happily work with 3.3V (you'll have to use smaller resistors to achieve the brightness you had with 5V), and 3.3V is safe for GPIO. – Dmitry Grigoryev Mar 24 '17 at 10:35

It is unsafe to connect GPIO to 5V at any time.

GPIO are 3.3V tolerant.

You can get away with this if you use a high enough resistor, but you run a risk of damaging the SOC.

The Pi is NOT " allowing current into the GPIO pins" the current is flowing through the substrate diodes to 3.3V, and once this leakage current exceeds a safe value will destroy the SOC.

You should use MOSFET or transistor drivers if you need 5V. Alternatively you could try running your LED from the 3.3V supply (pin 1).

| improve this answer | |
  • I am using resisters that drop the voltage to 3.5 volts. Perhaps i should use higher resisters to bring the voltage down to 3.3v but i dont understand why this is unsafe? i can certainly understand that using no resisters is unsafe, but not if the voltage is correct. – user3708579 Mar 24 '17 at 0:46
  • on a separate note. can you explain the difference between the GPIO pins allowing current in and the current flowing though the substrate, i am unfamiliar with how this works on the pi – user3708579 Mar 24 '17 at 0:48
  • You cannot use "resisters that drop the voltage to 3.5 volts". You would need a voltage divider, which is not feasible with common anode LEDs. When the LED is off you ideally have NO current, so resistors CANNOT drop voltage. It is not possible to explain substrate diodes in a few words, it requires a knowledge of the manufacturing process for semiconductors. Try Wiki if you want to read more. – Milliways Mar 24 '17 at 0:58
  • I see. This makes more sense now – user3708579 Mar 24 '17 at 1:05
  • The alternative option to use the 3.3v supply seems like the simplest option. This brings me back to the original question. is it safe to have the 3 GPIO pins connected though the led and resisters to the 3.3v supply (pin 1) on startup? – user3708579 Mar 24 '17 at 1:17

The LED lights up softly when the RPI starts

What happens here is a current flowing from 5V supply, through the LEDs, into the GPIO pins and into the 3.3V supply. This is a protection mechanism which prevents a short voltage spike to instantly blow up the pins, by limiting the overvoltage to 3.5V as you have seen.

Should this mechanism fail for some reason (like an actual voltage spike coming in addition to the current from the LEDs), you will damage the CPU chip. If you're lucky, you'll only lose the pins, but more often that not you'll lose the whole board. So no, it's not safe.

Sometimes this situation is hard to avoid (the device you connect requires 5V and won't work well with voltage shifters), so this is being done in some DIY projects. In your case however, I expect the LEDs to work from 3.3V supply just as well, so it's best to avoid it.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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