Part three grew steadily and finally was no fun to read because of its length, so I split it again. Only to avoid “tl;dr”…
I have been talking a lot about level shifting without explaining it. This is about to change…
For a very long time electronic components like ICs, sensors etc. were working on TTL-level, meaning that they were operated by 5 Volts. As parts became more and more integrated, smaller and needed to be even more energy efficient, they began designing electronic components that were operated by 3.3 Volts, which is called CMOS-level. This did not only affect the operating voltage, but also the levels on which logical components could detect HIGH/LOW levels. It is clear that a device that is designed to run on 3.3 V will not tolerate a voltage of 5V on any of its connections. So what to do if you want to use 5V and 3.3V parts together? Right, level shifting.
Unidirectional level shifting
The most basic form of a level shifter from a high voltage to a lower voltage would be a “voltage divider”:
The voltage between the two resistors which goes to “CMOS-LEVEL”, can be calculated with the formula:
CMOS_Voltage = (R1 * TTL_Voltage) / (R1 + R2)
More on this calculations and how to devise the formulae can be found on the Wikipedia pages (Germans go here).
This schematic only works from higher to lower voltage. To convert from a lower voltage to a higher voltage we need something that can act a little bit like a switch or relay. And luckily, we have Transistors (Germans) nowadays. To understand the basics, “transistor as switch” is a good search term, as I won’t go into all the nifty details. But here is a schematic for level shifting to a higher voltage:
This has to be “read” from left to right (I forgot to draw an arrow…) as this shifts the voltage level from CMOS (3.3V) to TTL (5V). OK, here is what happens: When CMOS-LEVEL is LOW (0 Volts) then T1 is said to be “open”. This means no current can flow through the transistor from the direction of R6 (wich connects to the Collector of T1) through the thingie with the arrow (the Emitter) to ground. It is as if the transistor weren’t there. So on the left side of T2 (the Base) we have roughly 5 Volts.
These 5 Volts are on the Base of T2 which cause it to be “saturated”. That means current flows between its Collector and its Emitter. As the Emitter is connected to GND, TTL-LEVEL also is grounded, ie. 0 Volts. Imagine the saturated transistor as an switch that is ON.
So finally, 0 Volt on the CMOS side is leading to 0 V on the TTL side. That’s good.
When the base of T1 (CMOS-LEVEL) gets HIGH, 3.3V are on T1’s base and now T1 gets saturated. So current flows directly between its Collector and Emitter (T1 as a switch would be ON). So the Base of T2 is now on 0V level (T1 is in fact shorting between R4 and GND). With its Base on 0V, T2 is now open. There is no electrical connection between its Collector and Emitter. Which finally leads to “TTL-LEVEL” having 5 Volts.
A short side note: Perhaps you have noticed this. If we had used only one transistor the signal would have been inverted. So a schematic like the on above with only one transistor is the easiest from of an actual “Inverter”.
That was easy. Sort of. But these level shifting only works in one direction. That is fine with RS232 where we have designated lines for transmitting and receiving. But what about bidirectional protocols such as I2C? This is where things get a little more complicated. But luckily there is a reference design from NXP (PDF version here). This also is the base for all those bidirectional level-shifters that can be bought from Adafruit or Watterott (in Germany). If you think about buying one make sure you chose a bi-directional one that is safe for I2C. This is important as the level-shifter needs to work at the speed of the I2C communication. This is what the reference design looks like (and it is the design I used for the board):
The Raspberry Pi is just too valuable too risk damaging it while tinkering around. So I decided to buffer the I/O pins. Essentially “buffering” means that there is something between the GPIO pin and the “outside” that shields both sides from currents or voltages that are too high. If something is connected the wrong way, the blue magic smoke that is trapped inside the integrated circuit – being responsible for making it work-, will come out and the circuit will stop working. (Of course this is completely rubbish, but a classic electronics joke that has been around for a very long time. See a reference here.)
I am using the 74HC244 “octal buffer” in my design. The technical specification can be found here. This chip has 8 lines that can be buffered. As I wanted to have the GPIO pins operate as either input or output, one of these chips can manage 4 lines. This is the schematic:
So what does that all mean? On the left “PI0-3” is the header for the jumpers that set a GPIO pin as output or input. You see that “GEN0” for example is connected to two of the leftmost pins on the jumper header. These two connections go to “1A1” and “2Y4”. The corresponding, then buffered, pins are on the right side, named “1Y1” and “2A4” and go to the second jumper header.
Ok, perhaps explaining what the pin names mean would shed some light on the (after reading it again) strange last paragraph:
“A” stands for input direction, “Y” for output direction. The 8 inputs/outputs are combined in two “banks”, that is the number before the letter. The last number is simply the number of the input. Example:
1A1: bank 1, input number one. This then corresponds to 1Y1 on the output side (bank 1, output number one).
The 10E and 20E pins are for operating the chip in high-impedance mode. We do not want that, therefore he pins are connected to GND.
The left side GENx are connected directly to the GPIO pins, Bx on the right side go to the IO-header on the rightmost side of the board (and the LEDs, of course).
And that pretty is all about the All-Out Board. It works, the PCB looks cool in blue and despite minor design errors, I like it. Now I need to think of some cool projects that make use of it. Apparently that would force me to buy another Raspberry Pi. One for tinkering and one for operations. I do have the light suspicion that The Girlfriend (I adapted this expression from Nerd Dad. Thank you…) won’t like it as she was utterly surprised the other day when she discovered that there were no free power outlets in the study where she could plug in her Macbook 🙂 (I need to tell her that we are slowly running out of IP addresses at home at some later time…)