# Logic level converter for H-bridge and UART for Raspberry Pi

Here is my situation:

I'm using a raspberry Pi to control a H-Bridge. The H-Bridge is not tolerant of both it's inputs being high logic value, which causes a short through the transistors, bypassing the motor. Because the H-bridge requires a 5V input, I slapped together this disaster:

Getting rid of floating input in a logic level converter

Now, as i understand, that circuit sinks current to the RPi, which is not only dangerous, but also crashes the Pi. Not only that, but the RPi boots with the output pins floating, which causes the logic level converter to output 5V, shorting the H-bridge as mentioned.

At, first I got around the issue with having a manual switch disconnect the H-bridge until I could set the RPi pins as outputs, the current sinking was tolerated. Now, I connected UART also through this converter(TX) and a voltage divider(RX) and it just crashes the Pi-s UART, I think it is because the RPi cannot handle sinking that much current. (UART works fine if motors inputs from the RPi are disconnected)

I need a schematic for a 3.3V to 5V logic level converter that acts like this:

1. on floating input, outputs 0V
2. does not sink to input
3. uses PNP and NPN transistors
4. is relatively easy to build


I'm assuming a voltage divider is fine for dropping the RX line from 5 to 3.3

Uh, I'm not entirely clear on the issue here. You do know you can simply apply a static pull-down directly on the raspberry pi IO pins? The rPi can easily drive a few kilo-ohms load.

Just tie the output pin to ground with a ~5-50K resistor. That way, when the pi isn't set as an output, the pin will be pulled to ground, and when you do set the pins as an output, the output driver can just overpower the pull-down, and it'll work as normal.

For that matter, what H-Bridge are you using? The common L298 will work fine with 3.3V logic-level inputs, it's probable that the bridge-driver you're using will probably also be fine.

• I tried that with several resistors, I think the NPN transistor I used to convert the logic level to 5V pulls the RPi pin up to around 3V when its floating ,regardless of the pulldown resistor at the input. also Isn't it bad for the RPi to sink all that current? I built my own H-bridge following this design pocketmagic.net/2009/03/a-simple-h-bridge-design/#.UqjoLFXxteW – Ollosaurus rex Dec 19 '13 at 10:07
• 1. Why are you building your own h-bridge out of discretes? Unless this is for educational purposes, it's not worth it. 2. You need buffers to drive that thing anyways. The rPi can only source/sink 4 mA. 3. You definitely need level-shifting for that to work properly. – Connor Wolf Dec 19 '13 at 10:46
• You need a totem-pole output buffer. You could build one yourself, but that's silly, considering how cheap they are. Just buy a non-inverting buffer, and use that. – Connor Wolf Dec 19 '13 at 10:48

You probably want a 74HCT125 buffer circuit. It has a separate "enable" from the "data" value. Thus, you can make it so that it doesn't go "enable" until you decide it should do that, with a weak pull-up for example. The HCT version accepts anything over 2V as "high" even when you feed it a 5V VCC.

This does not directly answer the question, but you could avoid the dangerous input configuration that shorts the battery contacts through the transistors by using the control logic from this H-Bridge.

The trick in this h-brigde is that it cleverly uses 3 control signals to turn on the diagonal transistors (to move the motor forward and in reverse) without ever letting you turn both vertical transistors (both left, both right or all four transistors) at once, preventing you from shorting the battery contacts.

The h-bridge I mentioned also uses optocouplers between the logic and bridge circuits, which might also help with the level logic conversion.