
2 More Images
So now our microcontroller can send data to the dot matrix LED but it's using eight I/O ports. That excludes using an ATtiny in an 8-pin DIP package, and even with a newer Arduino sporting an ATmega328p that's a lot of I/O ports for one LED. We can get around this, however, by using an IC called a shift register.
A moment to "shift" gears...A shift register can be understood best by thinking about the two words that make up its name: "shift" and "register." The word shift refers to how the data is moving through the register. Here (as in our Arduino and microcontrollers, in general) a register is a location that holds data. It does this by implementsing a linear chain of digital logic circuits called "flip flops" that has two stable states that can be represented by either a 1 or 0. So, by putting eight flip flops together you have a device that is capable of holding and representing an 8-bit byte.
Just as there are several types of flip flops, and several variations on a theme of shift registers (think up/down counters and Johnson counters), there are also several types of shift registers based on how data is latched into the register and how that data is output. Based on this, consider the following types of shift registers:
- Serial In / Parallel Out (SIPO)
- Serial In / Serial Out (SISO)
- Parallel In/ Serial Out (PISO)
- Parallel In / Parallel Out (PIPO)
Two of note are SIPO and PISO. SIPO registers take data serially, that is, one bit after another, shifting the previously input bit over to the next flip flop and sending the data out on all inputs at once. This makes a nice serial to parallel converter. PISO shift registers, conversely, have parallel inputs, so all bits are entered at once, but are output one at a time. And you guessed it, this makes for a nice parallel to serial converter. The shift register we want to use to reduce the number of I/O pins would allow us to take those 8 IO pins we used earlier and reduce them down to one, or maybe just a couple, considering we may need to control how we input the bits. Therefore, the shift register we'll use is a Serial In / Parallel Out.
Wire up the shift register between the LED and ArduinoUsing a shift register is easy. The hardest part is just visualizing the data output pins and how the binary digits will end up in the IC, and how they will eventually show up on the LED. Take a moment to plan this out.
1. Attach 5V to pin 14 (top right) and take pin 7 (bottom left) down to ground.
2. The shift register has two serial inputs but we'll only be using one, so connect pin two to 5V
3. We won't be using the clear pin (used to zero out all outputs) so leave it floating or attack it to 5V
4. Connect one digital IO port to pin one of the shift register. This is the serial input pin.
5. Connect one digital IO port to pin 8 (bottom right). This is the clock pin.
6. Connect your data lines from Q0 to Q6. We're only using 7 bits because the ASCII character set only uses seven bits.
I used PD2 for outputting my serial data and PD3 for the clock signal. For the data pins, I connected Q0 to D6 on the LED and continuing that way (Q1 to D5, Q2 to D4, etc). Since we're sending out data serially we will have to examine the binary representation of each character we want to send, looking at 1's and 0's, and outputting each bit on the serial line. I've included a second version of the dotmatrixled.c source along with a Makefile below. It cycles through the character set and displays all even characters (if it's weird thinking that a letter could be odd or even, think about the binary representation for a moment). Try to figure out how to make it cycle through displaying all odd characters. You can further experiment with the connections between the shift register, the dot matrix LED, and your Arduino. There are several control features between the LED and the register that can allow you to fine-tune your control about when data is displayed.
So....we've gone from having to use eight I/O ports to only using two!
Attachments