I will start out by noting that this instructable pertains only to TTL serial, and not RS232.
It should serve well for any 2 devices that you need to have serial communications between that have TTL serial capability.
Almost all the popular prototyping boards have TTL serial, but unfortunately, they don't all run at the same voltage.
The 5V device is safe, and can receive data from the 3.3V device without issue in almost all cases.
The problem comes when you have to send data to the 3.3V device from the 5V device. This is also useful for connecting the Pi to a 5V USB TTL serial cable - and may become the most popular use for it!
If you have seen my 8X8X8 LED Cube instructable
, you may have noticed there was one concern about hooking up the Raspberry Pi to the cube.
That problem is TTL Level shifting.
The ATmega chips can take 3.3V TTL serial, because 3.3V is still a "Logic 1" in the 5V world.
But if we want to send data back to the Raspberry Pi, we need to level shift that 5V signal or we'll
blow the input on the Raspberry Pi.
So I started looking at buying
a TTL Level Shifter.
2 problems. Ones like this one
cost $15 after shipping, and have way more than what I need.
Almost all the TTL level shifters I looked at were 8 bits wide, and many were bi-directional.
I only need 1 bit, and it only has to be uni-directional
So then I looked at my parts bin and thought "I should be able to just build what I need without spending anything"
At most, this will cost you the price of 2 to 3 resistors. Using the formula I put up here, you should be able to scrounge resistors from almost anywhere that will do - you don't have to use the values I use as examples. I just use 100 ohm resistors because I have over 4500 of them.
This instructable should actually work for most 5V to 3.3V TTL Serial communication between devices.
For instance, I included the pins for the Arduino, so you can see this would be a great way to communicate from Arduino to Pi.
CAUTION: ATTEMPTING ANY OF THIS IS ALWAYS DONE AT YOUR OWN RISK. I say this mostly because if you get the RX and TX backwards or mis-wire something and send 5V into a 3.3V input, you can damage the 3.3V device.
Double check everything, and then check it again before powering up. That said, let's continue!
If you saw my instructable on the Simplest iPhone/iPod/iPad charger
circuit, you know I like to break things down to the simplest of terms. Well, here it is. 3.3 is 2/3 of 5. So if we have 5V, then we need to make that 2/3 of that.
In this circuit, R1 is tied to the 5V signal. R2 is either 2 R1 resistors, or a resistor 2X the value of R1.
So if you have a bunch of 100 ohm resistors (or just about any other value, as long as they are the same) put one on the 5V signal, then put the other 2 in series from that point to ground. The junction of R1 and R2 will be 2/3 of the 5V, or 3.3V. Simple.