Education – Breadboard

A breadboard is a convenient way to prototype electronics projects.  It’s essentially a plastic board with a ton of holes in it.  You stick electronic components into those holes to build circuits without the need for soldering things together (most of the time).  On a breadboard, the holes are also interconnected in a couple of different ways, and that helps to make electrical connections without having to run a wire for every little thing.

Basic Layout

Sometimes they are taller (more rows), other times they are wider (more center groups), but they almost always look something like what is shown here.  In general though, a breadboard looks a bit like this.

Sometimes there are letters or numbers to identify the rows and columns a lot like a chessboard, but I haven’t bothered putting those labels on my diagram.  Some very small breadboards do not have the vertical power rails.

Connection Patterns

A breadboard wouldn’t be much use if they just had holes in a plastic board with nothing else going on.  After all it would be impossible to make a circuit if there were no electrical connections being made.  Nearly all breadboards, regardless of what color, size or shape they are, have the same basic connection layout.  Along the sides of the board you have the power rails.  These connect the whole way from the top to the bottom and are typically used to provide easy access to power and ground no matter where you are on the breadboard.  In the middle you have groups of connected holes.  These are usually two groups of five holes per row.  Large breadboards can have several groups of five holes.  Here is a diagram to explain how the holes are connected inside the breadboard.

Sample Circuit.

Here is a simple example circuit where an LED has a power switch to turn it on and off.  In this case, the power comes from a battery that we’re pretending has enough voltage for what we are trying to do.  The battery is plugged into the power rails on the breadboard, which means we now have a way to get positive and ground any where we want.  Next, positive power goes through a switch that straddles the gap down the middle.  We get the positive from the output side of the switch and run it over to an LED.  On the other side, we use a resistor to get ground over to the LED.  Now when we turn on the switch, the LED comes on and when we flip the switch again the LED turns back off.

While this may be one of the easiest ways to make a circuit, and it may be a simple device to use, if you didn’t know how the holes are connected together, well, it could be a bit like some crazy magic and not terribly useful for you.  Hopefully now you know what’s going on and are already imagining all the things you can do with them.  If you want to buy one or six, head over to the Shopping Recommendations page for my suggestion.

Education – NES and SNES Joypads

If you haven’t already, I recommend you start with the education article on the 4021 Chip to learn how they work.  Once you are done with that, you can come back here to learn how they are used in the NES and SNES joypads.

NES and SNES Joypad Connectors

Even though the plugs for NES and SNES joypads look very different, they actually house the exact same number of wires with the same purposes.  Oddly enough, both connectors have 7 holes and only 5 wires in use.  I guess they left the other 2 spots for some sort of future expansion that never happened.  Here is a diagram to explain how the wires are arranged and what they all do:

NES and SNES Joypad Buttons

Joypad buttons in both the NES and the SNES are set up in a “pull down” arrangement.  That means that when you aren’t pressing a button it is represented by a “1” bit instead of the “0” you might expect.  When you press a button it pulls the value down to a “0” to indicate that it is pressed.

At first glance, this is backwards from the way that makes sense, but they had an ulterior motive when they did it this way.  They wanted to be able to tell when a joystick is plugged into the NES or SNES.  If you think about it for a moment, you will probably realize that if the buttons sent back in “0” when they aren’t pressed, and a “1” when pressed, then there is no way to know that a joystick is plugged in because there would be no difference between not being plugged in (which would result in a ton of “0”s) and simply not pressing anything on it.  That means you’d only be able to tell that something is connected if the player was actually pressing something.

By flipping it around, all the buttons are suddenly sending “1”s even when the player isn’t pressing anything, just by having the joystick plugged in.  Viola, you can tell that it’s plugged in whether or not a player is pressing anything.

NES Joypad 4021 Layout

There is a single 4021 chip in a NES joypad.  It has its buttons connected to pins in the following arrangement:

  • Input 1 – Pin 7 – D-Pad Right
  • Input 2 – Pin 6 – D-Pad Left
  • Input 3 – Pin 5 – D-Pad Down
  • Input 4 – Pin 4 – D-Pad Up
  • Input 5 – Pin 13 – Start Button
  • Input 6 – Pin 14 – Select Button
  • Input 7 – Pin 15 – B Button
  • Input 8 – Pin 1 – A Button

SNES Joypad 4021 Layout

There are two 4021 chips chained together in a SNES joypad.  One of them is the primary chip and has its data output (pin 3) connected to the SNES console.  The other is the secondary chip and has its data output (pin 3) connected to the data input (pin 11) on the primary chip.  The buttons connected to pins in the following arrangement:

Primary Chip

  • Input 1 – Pin 7 – D-Pad Right
  • Input 2 – Pin 6 – D-Pad Left
  • Input 3 – Pin 5 – D-Pad Down
  • Input 4 – Pin 4 – D-Pad Up
  • Input 5 – Pin 13 – Start Button
  • Input 6 – Pin 14 – Select Button
  • Input 7 – Pin 15 – Y Button
  • Input 8 – Pin 1 – B Button

Secondary Chip

  • Input 1 – Pin 7 – No Joypad Button (see note below)
  • Input 2 – Pin 6 – No Joypad Button (see note below)
  • Input 3 – Pin 5 – No Joypad Button (see note below)
  • Input 4 – Pin 4 – No Joypad Button (see note below)
  • Input 5 – Pin 13 – Right Shoulder Button
  • Input 6 – Pin 14 – Left Shoulder Button
  • Input 7 – Pin 15 – X Button
  • Input 8 – Pin 1 – A Button

Note:  Pins on the secondary 4021 chip that are not connected to any button on the joypad (Pins 4, 5, 6, and 7) are instead connected to +5V DC through a 10K ohm resistor.

NES Joypad Wiring Diagram

This diagram looks worse than it really is, honest.  When a lot of the wires are inside a breadboard or some other prototype perfboard, it’s vastly less complicated to build.  All of the resistors are 10K ohm 1/4 watt resistors.  The buttons are any momentary switch you like.

(You can click on this image to view it larger.)

SNES Joypad Wiring Diagram

This diagram is a bit worse than the NES one above, but it still isn’t really evil.  There is a second 4021, four extra buttons and eight extra resistors.  Once again, when a lot of the wires are inside a breadboard or some other prototype perfboard, it’s less complicated to build than it seems.  All of the resistors are 10K ohm 1/4 watt resistors.  The buttons are any momentary switch you like.

(You can click on this image to view it larger.)

Education – 4021 Chip

The 4021 chip is a parallel in, serial out, 8-bit shift register.  That’s a lot of words to describe a single chip, so we’ll take them a little at a time.

Parallel In

This means that the chip connects to some number sources of information in parallel.  In most cases, these sources are switches or buttons of some sort.   That should make it fairly obvious why these chips are often found in joysticks.  A joystick is just a device full of buttons that you want to know the individual states of while someone is playing a game.

Serial Out

This means that the information collected from lots of buttons is transmitted out of the chip in single file.  This is handy because it means that the information from all of those buttons doesn’t need a lot of wires to send it to a video game console.

8-bit

This is the amount of storage in the chip for holding the data that came from all the buttons.  The data is arranged as one bit per parallel input on the chip and has nothing to do with how many bits the console system CPU has.

Shift Register

This describes how the data is moved inside the chip as it is requested by the connected system.  In this case, each time the data is requested the front bit is sent on its way and the remaining bits all shift one spot over toward the front.  The back is filled in with zeros.  Eventually all of the data space inside is filled with zeros and there is nothing else to retrieve.

Chaining Chips Together

In most situations, 8 bits isn’t enough.  The original NES controller has 8 buttons, so it will work perfectly, but a SNES controller has 12 buttons.  You can’t connect 12 parallel inputs (buttons) to a chip that only knows how to deal with 8, there just aren’t enough places to solder things to.  Fortunately the folks that designed this chip knew that might be a problem and made sure there was a way to chain more than one of them together.  There is a pin on the chip that can be connected to the output on another chip.  When data is read from the chip and normally the register would fill in the back of the data with zeros, it uses the output data from the next chip in line instead.  There is theoretically no limit to how many you can chain together in this way, but I’ve never tried more than two.

Latch Signal

Buttons are being pressed and released all the time on the joystick when someone is playing a game.  Logically that could have a very confusing effect on the data coming out of the register unless there is a way to prevent button state changes from screwing things up.  The way this is achieved is what is called a latch.  Essentially when a latch signal gets to the chip, it means “remember everything as it is right now, and ignore all other button presses until we are done reading all the data.”

Data Output

There is a single pin on the chip that is used to send data out from the chip.  First a latch signal is received, and then data is sent out once per clock pulse received on the clock pin.

Pin Layout

We have now covered the basic flow of information for this chip and we’ve talked about a lot of inputs and outputs, so it will now be helpful to know how they are laid out on the chip itself.  The best way to do that is with a diagram.

I consider it to be a somewhat unfortunate layout for the pins due to the inputs being all over the place, but as long as you have a map handy like the one above, you shouldn’t have any trouble connecting things to the right places.  The two pins without labels (2 and 12) don’t have anything connected to them, and in situations where you are not chaining multiple chips together, Data Input (pin 11) should be connected to ground.

This concludes our discussion about the 4021 chip and how it works, hopefully you now understand their uses and why they are often found in joysticks.