Using a Logic-level Shifter with Raspberry Pi
When and why to use a logic-level shifter?
Written By: Cherie Tan
Difficulty
Easy
Steps
11
Many sensors provide a voltage level which informs the Raspberry Pi or a microcontroller such as the Arduino about their change of state. Now recall that the Raspberry Pi's GPIO pins are designed for use with 3.3V inputs and outputs. Some sensors operate on 5V, so feeding its output directly to the Raspberry Pi's GPIO pins runs the risk of damaging either the sensor or the Raspberry Pi. Imagine not knowing about this and wiring it up erroneously, you'd hope to see spectacular blow-ups and magic smoke! However, we usually see nothing, no fun at all - it just eventually stops working. Which can be frustrating when it comes to troubleshooting. Other times though, you need a voltage adjustment in both directions so that devices can communicate in both directions across the same wire.
In this guide, you'll learn about logic-level shifters, specifically the bi-directional logic level shifter.
Complete this guide to set up a Raspberry Pi with a Little Bird Uno R3, so they can communicate bi-directionally via the I2C protocol!
Many sensors provide a voltage level which informs the Raspberry Pi or a microcontroller such as the Arduino about their change of state. Now recall that the Raspberry Pi's GPIO pins are designed for use with 3.3V inputs and outputs.
Some sensors operate on 5V, so feeding its output directly to the Raspberry Pi's GPIO pins runs the risk of damaging either the sensor or the Raspberry Pi. Imagine not knowing about this and wiring it up erroneously, you'd hope to see spectacular blow-ups and magic smoke! However, we usually see nothing, no fun at all - it just eventually stops working. Which can be frustrating when it comes to troubleshooting.
Some sensors operate on 5V, so feeding its output directly to the Raspberry Pi's GPIO pins runs the risk of damaging either the sensor or the Raspberry Pi. Imagine not knowing about this and wiring it up erroneously, you'd hope to see spectacular blow-ups and magic smoke! However, we usually see nothing, no fun at all - it just eventually stops working. Which can be frustrating when it comes to troubleshooting.
On the other hand, sometimes you want to increase the 3.3V output from the Raspberry Pi so that it can drive another circuit that requires 5V input.
One example of this can be seen in the use of the TrinityPixel LED Strips with Raspberry Pi, where a 74AHCT125 logic level shifter was used. That said, if you're only powering a few TrinityPixels like in the case of building a mini Nanoleaf replica, you could do without a level-shifter or external power supply, and power them directly from the Raspberry Pi's 5V pin.
One example of this can be seen in the use of the TrinityPixel LED Strips with Raspberry Pi, where a 74AHCT125 logic level shifter was used. That said, if you're only powering a few TrinityPixels like in the case of building a mini Nanoleaf replica, you could do without a level-shifter or external power supply, and power them directly from the Raspberry Pi's 5V pin.
Other times though, you need a voltage adjustment in both directions so that devices can communicate in both directions across the same wire. For example, say we wanted to connect a Raspberry Pi to a Little Bird Uno R3. To do that, you'll need a bi-directional logic-level shifter. In this guide, we'll show you how to do just that by using the I2C communication protocol.
A logic level is a specific voltage used to determine whether a signal is HIGH or LOW. In the past, 5V used to be the standard logic level for most systems, recognised as a typical HIGH signal. These days, devices are getting smaller and more power-efficient, so many work on 3.3V to reduce power consumption or wastage.
Take a look and you should see a total of twelve pins on the bi-directional logic-level shifter. On the first row, you'd see the pins: HV1, HV2, HV, GND, HV3 and HV4. On the second row, you'd see the pins: LV1, LV2, LV, GND, LV3, and LV4.
What do all these mean? Here's a hint: This logic-level shifter is a 4-way level conversion module which has the capability of converting 4 pins on the high side to 4 pins on the low side, with two inputs and two outputs provided for each side.
What do all these mean? Here's a hint: This logic-level shifter is a 4-way level conversion module which has the capability of converting 4 pins on the high side to 4 pins on the low side, with two inputs and two outputs provided for each side.
The board needs to be powered from two voltage sources, a high voltage and a low voltage, that your system is using. In this case, the high voltage source would be 5V and the low voltage source would be 3.3V.
So, The high voltage source is to be connected to the 'HV' pin, while the low voltage source connected to 'LV', and ground from the system to 'GND' pins.
Now click on the second then third image. Here, we've drawn imaginary lines to separate the module into columns. Each column represents a channel, so there are four separate channels here and the number at the end designates the channel of the pin. So for example, LV1 and HV1 are on channel 1. For example, say we wanted to shift the logic level of the signal sent in LV1, up to a higher voltage, this would be shifted up and sent out to HV1.
If we wanted the signal sent in HV2 to be shifted down, this would be sent out of LV2. You may use as many channels as required, although it is not required to use every single one.
If we wanted the signal sent in HV2 to be shifted down, this would be sent out of LV2. You may use as many channels as required, although it is not required to use every single one.
Note: These logic level shifters will work on any pin that requires sending and receiving of digital data.
Insert the bi-directional level-shifter into the breadboard as shown. Here, we have inserted them so that the first row of pins are connected from F7 to F12. The second row of pins should be connected to D7 to D12.
Insert a F-M jumper wire from 3.3V on the Raspberry Pi 4 to LV on the bi-directional logic-level shifter.
Next, insert a F-M jumper wire from 5V on the Little Bird Uno R3 to HV on the bi-directional logic-level shifter.
Then, connect a F-M jumper wire from GND on the Little Bird Uno R3, to GND (row 1).
Next, connect another F-M jumper wire from GND on the Raspberry Pi 4 to GND (row 2)
Then, connect a F-M jumper wire from A4 (SDA) pin of the Little Bird Uno R3 to HV1.
Finally, connect a F-M jumper wire from A5 (SCL) pin of the Little Bird Uno R3 to HV2.