Two 40-bit Shift Registers

Or: How I learned to read 74 individual keys using only 6 pins. This seemingly daunting task is actually pretty simple, thanks to an old friend from grade 11 digital electronics: the 74165 8-bit parallel-in, serial-out shift register IC.

The purpose of these things is simple: Each of the organ's manuals is 3 octaves, which means 37 keys. Were I to go 1 to 1, I'd need 74 GPIO pins before we even got to the pedals and preset switches and such. Since this isn't possible, we use the shift registers to multiplex the 40 bits of data (as we need to use 5 x 8-bit registers, which gives us 3 more bits than we actually need) using 3 pins on the BeagleBone.

Until the bus is latched, the input pins are free to move between high and low as they desire. While latched, however, they'll stick in their current state. In addition to latch, we'll use another pin on the BeagleBone to send the clock signal. When the bus is clocked (or banged), the shift registers shift in their indicated direction (for example, our 74165s are shift left registers, so they're going to shift from most significant byte to least significant byte) and the appropriate bit falls out.

With our registers, when the MSB is popped off, the LSB is assigned the value of the chip's Input pin. Multiple registers are chained together by connecting the Output (which is usually the MSB, in our case the chip's Qh) pin of one chip to the Input (or Serial) pin of another. By doing this, we can read both of the manuals independently using a grand total of 6 pins on the BeagleBone. I debated combining everything in to one huge bus but figured the ability to tweak the scan times of the various levels of input might come in handy in the future.

When it was all said and done, I wound up with something that looked like what's below. No schematic as I didn't actually draw out the circuit since it's very simple: Each chip shares the same load and clock lines. The Output (Qh) of one chip goes to the Input (Serial) of the next. The last chip's input should be connected to ground and the first chip's output becomes the data line we feed to the microcontroller.

Two 40-bit Shift Registers

As you can see, 5 chips per bus gives us 40 bits, which is the closest we can get to 37. I chose to use 2x20 headers so I'd be able to use the full bus if needed but didn't bother connecting the three rightmost to ground or anything because we're going to be unlatching the bus before we get to their data anyways. Naturally they'll work fine if something's connected.

A quick word...

Ahem: This is the most important part of this project. Everything, and I mean everything we're going to do from here on in relies on these things pushing out the right bits at the right times. It is very important that you test everything.

If you're playing along with me and using shift left registers, when testing the connections between the header and the pins of the chips, the leftmost pin on the header will be the lowest key on the manual, so it needs to be connected to the most significant (ie. largest) of our 40 bits. That way, the bits are coming off in the same order as the keys. If you're using shift right registers, everything will be backwards and the leftmost pin connected to the least significant of the 40 bits because they shift in the opposite direction.

Also, don't get ahead of your self and just start connecting things to your BeagleBone willy-nilly. The 74165s are TTL (5 volt) chips which cannot be connected directly to either model BeagleBone as they are 3.3 volt devices. We have some tricks up our sleeve for dealing with this, but for now the important part is that data pin outputting 5 volts when it should and 0 when it shouldn't.

If you're sure you're finished and you're happy with the results, I'll see you over on the software side of things, but don't come over until you're absolutely certain.


  • Ensure your bits are coming out in the correct order, first off being the leftmost C on the manual
  • Level converters are cheap and we'll need a lot of these chips, so suck it up and buy 5 volt chips so we don't have to worry about current drawn from the BeagleBone's 3.3v pin
  • This is a lot of soldering. A lot. It is also very important, so pay attention.
  • Remember to double check your work as you go