0

I'd like to power a few sensors I'm adding to my RPi (Zero W) using a battery with maximal voltage 4.1V (coincidentally, the same battery used to power the RPi, except that there's a voltage amplifier between the RPi and battery). I wonder whether I should use a voltage divider when connecting my sensor output pins to RPi GPIOs (such as SDA, SCL, TX, RX, or general GPIO), or if 4.1V VCC is okay.

  • https://raspberrypi.stackexchange.com/questions/3209/what-are-the-min-max-voltage-current-values-the-gpio-pins-can-handle – Jaromanda X Jun 12 '21 at 12:00
  • 4
    You should not think about the **nominal** battery voltage, you should think about the **maximum** battery voltage. Will you ever charge the battery while it is connected to the Pi? – Elliot Alderson Jun 12 '21 at 13:21
  • @ElliotAlderson True, my bad. And no, I don't think so, at least, I don't plan to. – Captain Trojan Jun 12 '21 at 13:35
  • Here's a [useful application note](https://www.digikey.com/en/articles/protecting-inputs-in-digital-electronics) that provides several techniques for protecting the RPi's *fragile* GPIO pins. FWIW, I feel that a Zener diode is a **much better** solution than a voltage divider, and an external Schottky clamping diode (e.g. BAT41) is good insurance for the rather flimsy clamps built into the GPIO pin. – Seamus Jun 13 '21 at 22:26
  • @Seamus Thank you for your insight! I will definitely read that. Well, unless I can find the answer in the link, can you please explain why do you feel like the voltage divider is a worse solution than using a Zener diode? If I reduce the voltage by a factor of 41/33 and assume the minimal voltage is around 3.4V, my minimal output voltage should be ~2.4V, which is way above the 1.8V threshold for logic distinction on the GPIO, correct? – Captain Trojan Jun 14 '21 at 08:55
  • 1
    I couldn't answer your "Zener v. Voltage Divider" question in a comment, so I added an answer here. Wrt the 1.8V logic threshold: I'd prefer to avoid splitting hairs if at all possible. – Seamus Jun 14 '21 at 23:21

2 Answers2

3

Provided you don't exceed 3.3V plus a diode forward drop (0.7V) it is unlikely to cause damage.

If you use a series resistor to limit current in the event the substrate diodes conduct it is less likely to cause damage.

You could combine this with a clamp to 3.3V (preferably with a Shottky diode) for complete safety.

You could use a voltage divider. This should make allowance for voltage variations. Any value over 1.3V is HIGH. I normally design for 2.2V, which provides an adequate noise margin.

NOTE that the battery is likely to exceed its nominal voltage when fully charged.

Milliways
  • 54,718
  • 26
  • 92
  • 182
  • What about I2C? If I connect a device, such as an MPU-6050, to the RPi and put 4.1V on the device's VCC, the problem still occurs, right? Or can I just connect SDA/SCL to the respective pins without worries about voltage control? The thing is, I found multiple tutorials about connecting said particular device to the RPi, and some used the RPi's 3.3V pin for MPU's VCC while others used the RPi's 5V (!) pin for the MPU's VCC. I tested both methods, both worked, but I'm unsure whether I'm exposing my RPi's SDA/SCL to any danger while doing that. – Captain Trojan Jun 14 '21 at 12:33
  • This is a New Question, but if you search you will find an Answer. – Milliways Jun 15 '21 at 00:30
2

I generally agree with @Milliways answer for protecting your GPIO pins from damage. This answer focuses on an item in your question which was not addressed in that answer - the voltage divider. We'll make a brief comparison between a voltage divider and the zener diode in an effort to show why the zener diode is superior to the voltage divider in some cases for limiting the voltage input to a GPIO.

Consider the following circuits:

  • VS is a nominal 5 volt signal, but its voltage may reach as high as 8 volts depending upon conditions which we cannot forecast or control.
  • VS is an input to a RPi GPIO pin, and we must limit this input to 3.3V through our interface circuitry.
  • We have identified two choices for the interface as shown below.

schematic

simulate this circuit – Schematic created using CircuitLab

A simplistic experiment on the two circuits above reveals the following:

VS VOUT-1 VOUT-2
5 3.3V 3.3 V
6 4.0V 3.3 V
7 4.6V 3.3 V
8 5.3V 3.3 V

The table above represents one obvious advantage of the "Zener Divider" over the resistive voltage divider: The output voltage is independent* of the input voltage. *Within limits of course.

But this isn't the only advantage; consider the following:

  • Simpler: Calculating resistor values is much easier
  • Lower Cost: A zener diode costs less than many resistors
  • Intellectual stimulation: (saving the best for last) - Adding a Zener diode to your project is a rare opportunity to escape the surly bonds of classical physics by employing quantum tunneling to protect your old-technology Raspberry Pi. It may also give you the final word in discussions on protecting GPIO pins - you can legitimately disparage your debate opponent as a luddite for using resistive voltage dividers. You can even impress the ladies by explaining to them how Heisenberg's Uncertainty Principle has changed your outlook on life.
Seamus
  • 18,728
  • 2
  • 27
  • 57
  • If you are recommending this you should use a lower voltage Zener. Most have a wide tolerance (and require a minimum current flow), and you DO NOT, and shouldn't aim to put foreign 3.3V on a GPIO (however it is derived). As for simplicity, aiming for 2.5V makes the calculation of a resistive divider simpler. – Milliways Jun 15 '21 at 00:37
  • @Milliways: That's not the way I do it - because I don't feel it's necessary to use a lower voltage Zener. Think about it this way: anything over 3.3V will be taken care of with the clamping diodes, and you get more noise immunity with 3.3 than 2.5. – Seamus Jun 15 '21 at 02:23
  • Thank you for this answer @Seamus. Upvote for the intellectual stimulation :D – Captain Trojan Jun 15 '21 at 09:01
  • But can you please add what are those unforcastable, uncontrollable conditions which may cause the input voltage to rise from 5v up to 8v, and how did you come up with 8v? Was that just an argument of type "zener diode better - you never know" or is this a phenomenon which can occur with high enough probability for a long enough time for it to matter? Does this concern general voltage sources, or have you somehow inferred from the information I made available to you that my battery is a LiPo, for whose this phenomenon is common? – Captain Trojan Jun 15 '21 at 09:08
  • Also @Seamus, when you responded to Milliways, what did you mean by *"Anything over 3.3V will be taken care of by the clamping diodes."*? Your table shows that, whatever the input voltage, the voltage across the ZD will always be 3.3V, correct? This is also what I've learned from ZD searches on google the last 20 minutes. – Captain Trojan Jun 15 '21 at 09:24
  • @CaptainTrojan: `unforcastable, uncontrollable conditions` is only a "catch-all" to cover any of the numerous "things" that may happen to temporarily spike or sustainably increase an input voltage; e.g. [back emf](https://en.wikipedia.org/wiki/Counter-electromotive_force) from a relay coil turn-off, or accidentally mis-adjusting the output of your lab power supply. [MOS devices](https://en.wikipedia.org/wiki/MOSFET) with small geometries and high input impedance are very susceptible to over-voltage - meaning they fail almost instantaneously. – Seamus Jun 15 '21 at 17:41
  • @Seamus Alright, I understand, thank you very much, I'm getting myself a zener diode. However, could you also please adress the other two questions I posed for you, namely "8V?" and "anything over 3.3V...", thanks. – Captain Trojan Jun 15 '21 at 17:45
  • 1
    @CaptainTrojan: This is why the RPi GPIO pins have *built-in* clamping diodes. However, they are not "robust" enough to protect your inputs in all cases. This is why the *built-in* clamping diodes are sometimes augmented with external clamping diodes. In the case of the 3.3 V Zener, Milliways point was well taken, but in my own analyses and experience, a 3.3V Zener won't be "off" enough to present a risk. Still, "risk" is a largely personal concept. I would never tell someone they are "wrong" by adding external clamps, but I don't feel in most cases they're needed. – Seamus Jun 15 '21 at 17:49
  • The particular zener that you linked to at Arrow has been discontinued and I don't think that is a representative price for a zener that you can actually purchase in small quantities. – Elliot Alderson Jul 06 '21 at 14:49
  • @ElliotAlderson: Thanks for the heads-up. I'll find another one when I've some time, but nothing special about that one - it's just a 3.3V Zener. And you won't get a good price from the Raspberry Pi vendor community. And here you go: [a 3.3V Zener less than USD$0.02](https://www.arrow.com/en/products/bzx79-c3v3133/nexperia), and Arrow reports over 14,000 in stock w/ a min order of 1. – Seamus Jul 06 '21 at 16:10