Hardware Reference
In-Depth Information
Shift Registers
Now you have your LCD ready to use and you've got your breadboard out and your Raspberry Pi on. So what's next,
you ask? It should be simple: just connect all the data lines to the GPIO. Yeah, but not quite. That will work but you
need to write your own driver and that defeats one of the key points of the HD44780 and its clones. Let's keep this
simple and make use of years of work done by other people for these LCDs. I will talk more about the software after we
connect the LCD to the Raspberry Pi. There is no use in having software when your hardware is not even connected.
You may wonder how you are going to connect all the data lines to the Raspberry Pi. If so, that's a good thing; you
won't be connecting any of the data lines to the Raspberry Pi directly.
Wait, what? How can you drive the LCD if it's not connected to the Raspberry Pi? Well, the LCD will be connected
to another chip called a shift register. Why use this magic shift register? Because you have very few GPIO pins on the
Raspberry Pi. If you were to connect this LCD and use all the data lines you would not have much room for any other
projects that need access to the GPIO pins. You want to save as many of the GPIO pins as possible. This is where your
new friend, the shift register, will come in.
Shift register? This all sounds a little shifty. What exactly is a shift register? Shift registers, or serial in parallel out
(SIPO) or parallel in serial out (PISO) as they are also known, are a handy way of turning a serial data stream into a
parallel data stream or the other way around. I will use a SIPO shift register to drive the LCD.
Let me explain how they work. In our case the shift register will take an input of serial data and output that into
parallel data. How this works is the Raspberry Pi will send bits of data across the I2C bus (explained in detail in the
next section). Each bit of data will be separated by a clock pulse. When the shift register receives this data, it will shift
each bit of data into one of the data output lines. As soon as it receives another string of data the previous bits of data
will be shifted out of the data output lines. This cycle will keep going as long as the shift register receives data input.
Take a look at Figure 4-7 . On the left you have the serial data input from the I2C bus and also the clock signal from the
I2C bus; these are the inputs. Data will be clocked in via the serial data input line. In this example the shift register is
four bits wide. So when you clock the four bits of serial data into the shift register you will have the same four bits of
data available on the four parallel data outputs.
Serial
Data In
Stage 1
Stage 2
Stage 3
Stage 4
Clock
Parallel
Data out
Parallel
Data out
Parallel
Data out
1
Parallel
Data out
2
3
4
Figure 4-7. A logic diagram of a shift register
Pretty cool stuff! Now exactly how will the shift register get its data?
The I2C Bus
That's where the I2C bus comes in. I will use the I2C bus to feed the shift register. What's this I2C bus? It sounds like a
bad instant messaging client. Well, not quite, but it will transfer messages. The I2C bus is used to exchange messages
between low-speed devices. I2C was invented by Philips in 1982 and its main goal was to link low-speed computer
peripherals together with a common bus and protocol. Because the I2C bus has been around for some time now,
there are a few versions of it. The version on the Raspberry Pi is version 2.1, which is pretty much just a bug fix for
 
 
Search WWH ::




Custom Search