3

One of my experiments has lead to two seemingly dead GPIO pins on my Raspberry Pi Zero WH. I'll explain what I did to seemingly cause this; please help me understand what happened.

The goal: Have a 12V power source convert to a 3V3 signal, plugged in to a GPIO pin that is set as an input. When the 12V is present, the converted 3v3 will bring the GPIO pin high.

Background: This is for a car project. Essentially when I press the brake pedal, a certain wire (brake lights, cruise control override, etc) has 12V. I want my Raspberry Pi to be able to sense when I press the brake, so I need to lower the 12V from the brake light wire to a 3v3 converter that signals a GPIO input pin.

Application: I picked up this 3V3 converter and as a test, I set GPIO pin 17 as an input pulled down. The Raspberry Pi was plugged in to a USB 12V to 5V converter and plugged into a 12V battery. The 3V3 converter was fed by the same 12V battery, and was outputting about 3.2 Volts when I tested the output leads with my multimeter, so far so good. Because they all share the same ground, I just plugged the positive 3v3 lead from the converter into GPIO pin 17.

What went wrong?: For some reason, instead of pulling GPIO 17 high as it should have, and giving me a high signal, it was still calling GPIO 17 "Low". Hm? Then I tried again on GPIO 21 and the same thing happened. Now coincidentally, both GPIO 17 and 21 not only don't seem to read inputs correctly anymore, but they don't output either, so it seems like the pins are just dead now. Why?

A little more background: What's more confusing to me is I have done this same exact concept before on a different RPi Zero WH, and it seems to work flawlessly. In my other application, I have a 3V3 signal that I tapped directly from my PC's power supply, and I plugged the 3v3 OUTPUT from my PSU directly to GPIO pin 21 on the RPi. In Python, I pull GPIO 21 LOW, and when I turn the computer on and the PSU is outputting 3v3, GPIO will read HIGH. When the computer is off and the PSU is not outputting 3v3, GPIO 21 stays LOW. Perfect.

I'm basically doing the same exact thing here, so why did it fry the pins in the other case?

The only difference in the way I wired these was, because the PSU 3v3 was a completely separate circuit, I plugged both the positive and ground from the PSU to the RPi header board, 3v3 + to GPIO 21 as an input, and the PSU ground to Rpi ground.

In the other case, both the 5V and 3V3 sources from the converters, as well as the 12V battery powering those converters, already all share the same ground. So logically I figured the ground from the 3v3 converter was not necessary to tie into the Rpi ground because there would already be continuity, so only the positive 3v3 lead from the converter was necessary. Am I correct here, or could this possibly have something to do with it? That is the only difference I can think of between the way I wired the two, otherwise the scripts and fundamentals seem identical.

Analog vs Digital Voltage?: One final detail, I have seen people refer to analog vs digital signals before, but as far as I know, the voltage is what it is, any 3v3 signal should trigger a high signal on a GPIO input right? Is there such thing as digital and analog 3.3 volt signals? The only reason I ask is because my power supply is advertised as a "digital power" supply, so I wonder if somehow the 3V3 being output by my PSU is somehow different than the 3.2V created by the converter coming from the 12V source.

cornerpocket
  • 63
  • 1
  • 7

2 Answers2

5

Your question is too vague and imprecise to answer definitively, but contains a number of misconceptions.

I need to lower the 12V from the brake light wire to a 3v3 converter that signals a GPIO input pin.

You are using a 12v Step Down to 3.3v 3a Power Supply Module - these are designed to supply power - NOT to convert logic levels. They often work poorly if unloaded, and are unstable on startup!

There are logic level converters, but there is no need; a simple resistive voltage divider would suffice (and be safer) - although I would use a diode clamp in addition to prevent transient damage.

schematic

simulate this circuit – Schematic created using CircuitLab

The resistors form a voltage divider giving 120/(120+680) * 12 => 1.8V (2.25V from 15V) which should be a safe and reliable signal over the expected input range (12-15V).

The diode (diode clamp) should be non-conducting, but will turn on if a transient exceeds 3.3V. This is a standard technique for working in noisy environments, but is not strictly necessary.

Similarly the capacitor provides filtering to further limit induced transients - not strictly necessary but a common technique to prevent false triggering.

I would NOT directly connect a foreign voltage source to a Pi (or any other logic circuit) without protection. NOTE you do NOT need 3.3V - indeed an engineer would use a circuit designed to safely exceed the logic threshold. See https://raspberrypi.stackexchange.com/a/104897/8697 (I normally aim to supply 2.2V to a Pi GPIO input). I wouldn't even connect the Pi 3.3V power to a GPIO without protection.

Finally you seem to be working in an automotive environment; these are a hostile environment for electronics, and require special design for safety - especially the routing of ground cabling. I would aim for an isolated circuit, either an opto-isolator or relay.

Milliways
  • 62,573
  • 32
  • 113
  • 225
4

What went wrong?

The most likely reason is that the 3.3V converter you used for 12V sensing via GPIO got powered while the SoC was still down. RPi doesn't start immediately once you feed it with 5v, it takes tens of milliseconds to start which is an eternity in electronics' time.

As a result, you applied 3.3V to a pin of an unpowered SoC, which you shouldn't do. What's worse, your 3.3V signal coming from a converter has a very high current limit (3A!), which is enough to destroy a pin. The circuit from @Milliways' answer would have limited that current to <20mA, which is still too high for my likings but it would likely have been enough to protect the pin.

What to do?

What you should know is that 12V in a car is by no means stable. If you accidentally go from 5th gear to the 2nd gear while driving, you can create a spike as high as 80V on the 12V bus. This event will be short enough not to blow the light bulbs, but again, it takes milliseconds to fry silicon.

If I were you, I'd buy an opto-isolator board such as this one and routed all your input signals through it. Unused channels can be used for output signals, but remember that you'll likely need a relay board if those output signals need to carry any measurable amount of power.

Dmitry Grigoryev
  • 28,277
  • 6
  • 54
  • 147