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.

  • Hi @cornerpocket, Ah let me see. I am 80% sure that it is this DC/DC 12v Step Down to 3.3v 3A Power Supply Module that fried your two GPIO pins: amazon.com/dp/B00H2CKFXQ. Reasons: (1) This DC/DC 12V to 3V step down power module is a "switching power supply unit" which has a high frequency (of the order of 100 kHz) oscillator used to switch the 12VDC source to charge up a capacitor to 3V. When 3V is reached, oscillator stops. And when 3V drops because drawing current out, oscillator starts again, and so on. / to continue, ... – tlfong01 Nov 4 at 14:53
  • Now let me dig deeper into the oscillator circuit which, non stop, at a high frequency, switches current on and off from 12V battery to charge up a capacitor to 3V. What cause trouble is the that the oscillator itself is switching on/off an inductor and this switching inductor current on/off causes "Back EMF“ which causes big current in a short time, causing voltage spikes which might be many times higher than 3V. And this spike might "radiate" outside the oscillator circuit to the Rpi GPIO pin circuit. Sorry for the electronics circuit analysis which I think might be too hard for you. – tlfong01 Nov 4 at 15:04
  • I am just thinking aloud, to help finding the culprit. Never mind the above boring electronic "lecture". What I want to say is (2) You made a mistake of using a switching mode DC/DC step down 12V supply unit, to convert a 12V "power" to a 3V "power." What you should use instead is a logical signal step down converter, to convert 12V logical signal (OK, I know it is from a 12V battery, but you can see it as a "signal" which draws very very little current, not like a power supply) to 3V logical signal. – tlfong01 Nov 4 at 15:15
  • 1
    Now let me suggest a couple of circuits to replace the switching power supply. (1) A simple 2 resistor voltage/potential divider, say 9kR + 3 kR in series, with 9k end connected to 12V, 3kR end to ground. Then the 9k 3k connection point would be 12V * (3K / (9K + 3K)) = 12V * (3/12) = 3V. This is the signal you can connect to the Rpi GPIO pin to read. BUT there is a 5% chance that this simple voltage divider will still fry the GPIO pin. Since you already have fried two pins, you still got a lot more spare GPIO pins to fry. (2) Using a voltage divider with a optical isolation buffer, – tlfong01 Nov 4 at 15:30
  • 1
    (3) Using a CMOS NAND gate with open drain (sort of pull down) output HC03A to convert (12V voltage divided to) 5V input signal to 3V3 output signal. This is safer than the simple two resistor voltage divider, but not that safe as the optical isolation circuit. And coming back to your question of why one Rpi survives but not the other. One possible reason is that one Rpi is "stronger" than the other! :) PS - I am making a quick and dirty explanation and suggestion. There should be better explanations and suggestions. But bed time for me now. So see you tomorrow. Cheers. – tlfong01 Nov 4 at 15:48
2

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.

  • Thank for this in depth answer, can you please explain what the 3.3V and the Diode are doing in the circuit above? I was under the impression that a positive voltage exceeding the logic threshold you mentioned, wired directly to a GPIO, and then Pi GND to GND was sufficient. I'm also curious about the C1 and the R2 (ground resistor), I assume the 6.8k resisitor is lowering the 12V to a safe voltage, but what does the 120 ohm resistor do here? – cornerpocket Nov 9 at 20:14
  • @cornerpocket See edited Answer. NOTE the series resistor (R1) by itself does nothing, without R2 you would blow up the Pi! – Milliways Nov 9 at 22:18
0

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.

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.