Level shifter pcb |
In case of the XBee which is driven by 3.3 Volt up to now I added a simple resistor divider to get the signals down to the lower supply level (see this older post ). But even if you feed the XBee without translating the different supply levels, I never got any problems (but I wouldn't recommend).
It might look slightly different with the Raspberry Pi, so to be on the safe side I built a simple 2-bit bidirectional voltage-level translator circuit for the alleged thin-skinned RasPi. You just need four 10k resistors, two BSS138 (N-Channel Logic Level Enhancement Mode Field Effect Transistor) and two four-pin headers.
I etched the board by myself but if you want to take the short way, there are already breakout boards and ICs available (e.g. Sparkfun Logic Level Converter, TXS0102 from Texas Instruments or ADuM1250/ ADuM1251 from Analog Devices).
Anyway I wanted to do some practice with my favourite pcb layout software Eagle and designed this simple pcb.
How does the level shifting work? If nothing happens on the bus (in this special case on the I2C-bus, thats what the pcb is labled for, but it also works with RX/ TX or any other 2-bit bidirectional digital purposes) all signals are pulled high by the 10k resistors. If either side goes low, the N-Channel MOSFET steps in and also pulls the signal line low, either because it turns on (low level side) or passes through the body diode (high level side).