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.

6
  • 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? Jun 12 at 13:21
  • @ElliotAlderson True, my bad. And no, I don't think so, at least, I don't plan to. Jun 12 at 13:35
  • Here's a useful application note 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 at 22:26
  • 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 at 23:21
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.
10
  • 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 at 0: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 at 2:23
  • Thank you for this answer @Seamus. Upvote for the intellectual stimulation :D Jun 15 at 9: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? Jun 15 at 9:08
  • 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 at 17:49
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.

2
  • 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. Jun 14 at 12:33
  • This is a New Question, but if you search you will find an Answer.
    – Milliways
    Jun 15 at 0:30

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.