Introduction: Build an Electronic Score Keeper/storage Box

About: He's just this guy, you know?
The instruction manual for each of the MANY munchkin series of card games always includes a phrase like "you will need a 10 sided die for each player or some other device to keep score."

10 sided dice are not hard to find in my house, but I took this as a challenge to make my own device to keep score.  I created this electronic score keeper that also doubles as a box for transporting a subset of my family's munchkin collection.  The box can keep track of each player's score and notify everyone when someone wins.

This device is not limited to keeping score in munchkin games of course.  It will keep score for 1 to 4 players (sitting anywhere they like around the box) ranging from a score of -9 to 99 for each one.




Even if you don't need a munchkin score keeper, this article might still be of value to anyone interested in:
  • How to use a max7219 chip to drive up to 8 seven segment LED displays with just a few pins of your microcontroller.
  • How to recover from minor flaws in a board.
  • Re-purposing parts of obsolete electronics, and make a virtue out of pack-rat-ery.
Of course, if I had my own laser cutter, the box would be much more ornate and even more munchkiny.  I would craft my own custom box and burn artwork both silly and terrifying in its sides. Players would be advised to keep their gaze fixed on the score lest they be driven mad by the terrible runes seared in its facets.*

Please vote for this this article in the laser challenge so that I can realize that ambition, and perhaps stop the dreams coming.

For more of my thoughts on what I would do if I won the epilog laser challenge, please see the notes at the end.

* Perhaps we play munchkin Cthulhu a bit too much.
 

Step 1: What You Need

This project was designed as component to fit into whatever framing device is desired.  Mine ended up being a sturdy cardboard box, but it could be any box, a board of some kind or even a table.  I'd probably upgrade to bigger displays in that last case.  The displays are modular and connected via ribbon cables, so your mounting options are extremely flexible.  Below is everything you need besides whatever you decide to mount it in.

You will need the following tools:
  • Soldering iron.
  • Dremel and/or other tools to cut and shape the enclosures if needed.  I used a hobby knife to cut my box.
  • Diagonal cutters.
  • Hot glue gun (optional).
  • Vice or Helping Hands to hold the board while soldering (optional, but highly recommended).
  • Multimeter for testing.
  • USBTinyISP or other AVR programmer to program the firmware.  See step 7 for other options.
Electronics (Prices in US $ from mouser.com)
1-MAX7219 8 Digit LED driver -- $10.50
1-24 pin dip socket -- $0.27 (for MAX7219)
1-AtTiny2313 microcontroller -- $1.91
1-20 pin dip socket -- $0.21 (for AtTiny 2313)
1-0.1 uF ceramic capacitor -- $0.05
1-10 uF Electrolytic capacitor -- $0.06
1-100 uF Electrolytic capacitor -- $0.06
3-Flat Cable .050 20 COND. 28AWG ROUND -- 3 X $0.58 = $1.74 (how many inches/feet you need depends on how far apart you are mounting the displays. I bought three feet but probably only needed one or two.)
8- 3M 10X2 socket (89120-0101) -- 8 X $1.23 = $9.84
8- 3M strain relief for socket (3448-89120) -- 8 X $0.19 = $1.52 (optional)
2-2 X 36 pin break off headers -- 2 X $1.88 = $3.76 (You are going to break these into 8 different 2X9 pieces)
2-9 volt battery connector --2 X $0.44 = $0.88
1-LM78L05 5v voltage regulator -- $0.23
1- 9 volt power supply -- $?? (any 9 volt power supply should work.  Optional, but it will save you a lot of 9 volt batteries)
1-2 X 3 break off pin header -- $0.14 (For ISP, same as the 9 row hears so if you buy extra, you can just snap 3 more rows off)
1-Munchkin counter circuit board -- ~4.6 square inches = $?? (Depends on how you get it printed)
4-Munchkin counter display daughter boards -- ~1 X 4 square inches = $?? (Depends on how you get it printed)
4- Common cathode 2 digit 7 segment displays (red) -- 4 X $1.76 = $7.04 (Also comes in Yellow, Green and Blue)
1-SPST Slide switch -- $0.79
Total = $38.99

All 5 boards from batchpcb with shipping and handling (setup fee) would be around $40.  See the next step for other options.

Other materials:
  • 3 (or 4) momentary contact push buttons.  They are not included in the list above because (a) I scrounged mine from an ancient control panel and (b) the choice should be an aesthetic one, to go with whatever you are mounting the displays on.  Mouser has 812 choices ranging from $0.21 each to $1,438.41.
    Personally, I'd stay away from buttons that look like a house payment.
    Arcade buttons would make a snazzy choice.
  • Solder.
  • Wire (for connecting buttons)
  • Velcro or other means of tidying up loose wires.
  • Glue (I prefer hot) to attach bits to your device.
  • Small bit of heat shrink tubing.
  • The box or other object you are mounting the displays in.
As always, a bit of scrounging can lower your costs.  A surprising $13.10 of the electronics cost (%35 percent!) is just for the custom ribbon cables.  If you have 4 ribbons cables with at least 9 rows you can save a bunch there.  It doesn't matter if there are extra rows to hang off the end, I used 10 row (20 connector) cables because I couldn't find 18 connector sockets.

I'll talk about options for getting the boards printed in the next step.

Step 2: Print the Circuit Boards

You will need one of the "motherboard" PCBs and 4 of the "daughterboard" PCBs.

The number of connections in this project (72 for the displays alone) makes wiring this by hand on a protoboard or breadboard unfeasible for all but the most masochistic.

You will want to get your circuits printed.

There are a number of options to do this.

Make your own.

If you wish to print the boards yourself there are lots of guides available at instructables and elsewhere.  The boards are fairly tight since I wanted to make them as small as possible without using surface mount components. Thus, if you do print your own you would probably want to make your own layouts from the schematic, to space things out a bit. Since you are no longer paying by the inch, you can make the boards a bit bigger.  I would also make some of the traces bigger.  The attached "munchkin-counter-eagle.zip" file has the schematic (and board layouts) in eagle cad format.  Again, there is a wealth of information about how to use eagle cad to view and modify schematics and boards. This article has excellent advice on making your board DIY friendly.

Have them printed.

To have them printed commercially, you will need to submit your boards to a board house via a gerber file. This is a zip file containing files that describe each of the layers that make up your printed circuit board. The two zip files attached to this step with "gerber" in their names are the versions I made to sparkfun's specifications for the BatchPCB service. BEWARE, The motherboard board file has not actually been tested, since I corrected a minor flaw after I printed mine.

Different board manufacturers may have different requirements on this file and may want you to create the gerber file yourself to their specifications.  This other instructables article describes the process of creating a gerber file from an eagle schematic.

Having individual boards printed has been an expensive proposition in the past.  This is because there are fixed costs associated with setting up a board and minimum sizes.  As a result, it costs as much to print a 1 inch square board as it does to print 160 square inches.  One-off boards often range $50 and up.

Fortunately, a number of services have been cropping up to allow you to pool your orders together with other people and only pay for your percentage of the total order.  You trade off time (you have to wait for a panel to be filled up) for cost, but these services are getting popular enough that the turn around is often days or weeks instead of months.

Here are a few I know of:

BatchPCB

BatchPCB is a service from sparkfun the completely automates the process.  You can upload a gerber file and the web page will validate it for you, give you a price quote and then let you put your design in a shopping cart to buy whenever you want.  And then you wait until they have enough orders to fill up a panel, it gets sent to china, and then returns.  It was about 4 weeks when I ordered these boards.  They charge $2.50 per square inch, rounded up, and a $10 handling fee.  About  $38 for 4 daughter boards and a motherboard plus shipping (it was about $5.50 for me).  You can order the original mother board at http://www.batchpcb.com/index.php/Products/19537 (complete with error that I show how to fix in step 4) or the untested fix at http://www.batchpcb.com/index.php/Products/69169.  The daughter boards (which worked the first time) can be ordered at http://www.batchpcb.com/index.php/Products/19190

This option is the simplest if you don't want to be bothered with formatting gerber files yourself.  Disclaimer:I make a couple of bucks if you buy from those links.

DorkbotPDX

DorkbotPDX is a portland hacker collective that has a batch pooling service with attractively straightforward pricing.  $5 per square inch, NO setup fee and free shipping.  You get three copies of the board for that price.  So you would have to get three copies of the mother board (two free coasters) for about $23 plus another $10 for two orders (6 boards, 2 more than you need) of the daughterboard. Best of all, they are a pretty purple which seems a very munchkiny color for circuit boards.  At $33 with free (US) shipping, this is a good deal and you get extras to practice on if you make a mistake.

This is your cheapest option (of the ones I list) for a single set of boards, even if you have extras left over.

Or, you could order three whole sets ($23 for 3 motherboards and $20 for 4 X 3 daughterboards) and have two to make for your friends and family.  That's only $14.33 per purple set!
They ask that you use their cam job when submitting gerber files, so you will need to create new gerber files for them, but appear to be very helpful if you have any problems putting the board together.  The boards are made in the US, which probably helps turnaround time.
 

Seeedstudio and Iteadstudio

Seeedstudio and Iteadstudio both have ultra-low cost prototyping services.  They charge a fixed rate of $10 for anything up to 5x5 cm or $25 for anything up to 10x10cm.  But you get 10 copies of each one!  The motherboard is 2.55 inches wide which is a bit too big for the 5 centimeter option, but the daughter boards fit in that size.  So you can spend $35 for enough to make two $17.50 sets (two motherboards, 8 coasters, 8 daughterboards and 2 mini coasters) or spend $65 and get enough for 10 whole sets at  $6.50 each*.  An important caveat, they only guarantee (and test) half of the boards.   5 out of 10 of each set have no guarantee from defects.  That means your $65 order might only work out to be 5 workable sets, which puts the price right back up to the $13 range, and these boards are not purple.
They have custom cam and design rules you can use to create the gerber files.
Shipping starts around $3

* too bad each one would need $38 worth of electronics to go with it.

Once you get your boards, you are ready to start soldering.

Step 3: Populate the Motherboard

Soldering the electrical components to the mother board is fairly straightforward but there are a lot of connections to make. If you are new to soldering, check out "How-to-solder" for a good overview of soldering skills. This board would be a good thing to practice these skills on since it has lots* of easy joins.

If you have never soldered before, give yourself a few hours and take breaks as needed.
  1. Solder on the two sockets.  Make sure the notch on each socket lines up with the notch on the silkscreen.  I always bend each of the pins in the corners to hold it in place when the board is flipped over to solder.  Solder those 4 pins on each socket, and then hit the 38 other pins.
  2. Solder on the C2 and C3 capacitors.  Make sure the + on the capacitor lines up with the + on the silkscreen.  The values are labeled on the board, but make sure that C2 gets the 100uF capacitor and C3 gets the 10uF capacitor.  These two capacitors are used by the voltage regulator.  Cut the protruding leads off the capacitors on the back of the board.
  3. Solder on the voltage regulator, using the silkscreen as a guide for orientation.  The flat side will face away from the edge.
  4. Solder on the 9 volt battery cap.  Red goes on the side closest to the voltage regulator.  Note that you will be unsoldering this later to add the power switch.  If you already know how long the wires need to be, you can attach the switch described on page 11 now and save a step.
  5. Solder the diode onto the spot marked D1.  The black line on the diode MUST go on the side with the line on the silk screen.  Cut the protruding leads off of the diode.
  6. Now would be a good time to take a break and test the voltage circuit.  Plug in a 9 volt battery and use your multimeter to measure the voltage between pin 2 and pin 6 on on the place where the ISP header will go.  You should see 5 volts.  You should also be able to see 5 volts between pins 20 and 10 (top right and bottom left) of the 20 pin socket.  If not, go back and check all the connections.
  7. Solder on the resistor .  The orientation does not matter.  Trim the protruding leads off the back of the board.
  8. Solder the .01 uF ceramic capacitor onto the spot labled C1.  Unlike the other two capacitors, the orientation does not matter.
  9. Solder on the 2 X 6 pin header to the spot labeled "ISP".  This will be used for programming the chip later.
  10. Solder on the 4 strips of 2 X 9 headers to the spots labeled "display 1-4", snapping them off the longer stick first if you haven't already.  Since you can't bend the pins on these headers it can be a little tricky to start them.  For each one, hold them in place in the middle of the row with your finger or get someone else to hold them in place while you solder two opposite corners. Don't hold on by the pins directly on the other side you are soldering, as the pins can get hot.  After this is done, the headers will stay on their own and you can easily solder the other 16 pins.
  11. Insert the ATTiny2313 chip in the 20 pin socket.  Make sure that you line up pin 1 of the chip with pin 1 of the socket.  The chip will have a notch on one end that corresponds with the notch on the socket.  If you put the socket in right, the notch will also line up with the notch printed on the silk screen.  You may need to GENTLY bend the pins inward on the chip to make it fit.  Do this by laying the chip sideways on the table pressing down so all the pins bend inwards at once.
  12. Repeat this for the larger Max7219 and the 24 pin socket.
*At least 294 of them!

Take another break, you've just soldered at least 137 connections. Only 157 more to go after we take a little detour in the next step.

Step 4: Fix the Flaw on the Board (optional)

When I originally built this, I discovered a flaw in the circuit board.  One of the segments on display number four would light up when it shouldn't and wouldn't when it should.  Going back to the original schematic I discovered where a connection was misplaced and fixed it, but I didn't want to wait a month and pay another $25 to have it re-done, so I fixed it with a wire and a knife.

This step is marked as optional since you only would need to do this if you printed the original board for some reason.*   If you printed the newer version of the board, hopefully everything will work with no correction.

I've included this step to show how a small mistake with a board need not be a disaster, corrections can be made by removing connections that should not be there, and adding ones that should.

*Maybe you don't fancy the idea of being a guinea pig for an untested board, and would rather deal with a single known problem.

Finding the problem (theory, you can skip down to the next bit if you just want to fix it):
Figuring out which changes to make is the most difficult part and requires a thorough understanding of how the schematic works and what should connect to what.  This is obviously MUCH easier with something you design yourself.
.
In this case, I was able to see from the schematic that segment G on display 4 (the one acting up) should connect to pin 17 on the max7219. This works out to be pins 7 and 17 on the header.  Using a multimeter in continuity mode I tested pin 7 against every other pin on the header.  I discovered that it did not connect to pin 17 like it should.  I also discovered that it connected to pins 1 and 5.  Pins 1 and 5 were supposed to connect together, but not to pin 7.

This means we have to break the connection between pin 7 and 5, and add a connection between pin 7 and 17.

Fixing the problem (practical steps):

Double check your work against the picture, in case I have described the pins incorrectly or unclearly.
  1. Find where the changes need to be made.  See the attached picture and read the notes carefully.  The changes need to be made to the BACK of the board under "display 4" .  From the front, Pin 1 is the lower left hand side, pin 9 is the lower right, pin 10 the upper right and pin 18 the upper left.  That means when you flip it over, the pins are reversed. Pin 1 is on the lower right, pin 9 the lower left, pin 10 the upper left and pin 18 the upper right.
  2. Sever the connection between pin 7 and pin 5 using a hobby knife.  Work slowly and carefully, scratching in small amounts until your multimeter no longer shows continuity between 7 and 5.  Take care that you don't cut anything else.
  3. Solder a wire between pins 7 and 17.  There is not a lot of room to make this connection so a thin wire is easier to work with.
  4. Test with your multimeter.  Pin 7 should show connectivity with pin 17, but not pin 1 or pin 5.
Now that that little unpleasantness is dealt with, it's time to start repetitive soldering again.

Step 5: Populate the Daughter Boards

Now you need to mount the LEDs on the daughterboards so they can be connected with the ribbon cables.

This board is a little unusual in that components need to be mounted on BOTH sides.  This is to save costs and space by making the interface as small as possible.

There are only two components but you MUST add them in the right order.  If you don't the LED display will cover up where you need to solder the header and you will not be able to attach it.
  1. Solder two corners of row of 2 x 9 headers (snapping them off the longer stick if you haven't already) onto the BACK of a daughter board.  This is the means the pins will be sticking out the side without the writing, and the actual soldering will happen on the front where all the silkscreen is.  Take the same precautions you took when soldering the matching headers to the motherboard.
  2. Once the corners are set, it will be easier to hold the board and solder the remaining 16.  Do this now.
  3. Solder an LED display onto the FRONT of the board, straddling row you just soldered on.  The orientation of the display matters, so make it line up with the picture on the board.  The display is flat and wide so you can just rest the board upside down on a table while you tack down the corners.
  4. Solder the remaining 16 pins on the display.
  5. Repeat steps 1-4 for the remaining 3 displays.
Take a break if needed and then get ready to start making some cables in the next step.

Step 6: Build and Connect Ribbon Cables

It is now time to figure out roughly where the displays are going to be in relation to the motherboard on your box, so (if you are making your own) you can decide how long to make the ribbon cables.

Making the cable yourself allows it to be exactly as long as you need it.  It does however contribute significantly to the cost of the electronics.  If you happen to have similarly sized ribbon cables collecting dust, this would be an excellent scrounging opportunity. 

Alternately, you could forgo the cables AND the headers saving about $13, if you didn't mind managing and routing 72 wires and soldering them directly to where the headers go.  Good luck with that.

The cables do not have to be exactly the same, as long as there are at least 9 rows of 2 in each, and all the sockets are open.  i.e. not keyed.

As long as you have room and are consistent on how you plug them in, you can let any extra sockets hang off the side of each header row.  In fact, I was unable to find 18 pin (2 X 9) cables or connectors anywhere, so one row of sockets hangs out on every connection from my 20 pin cables.
  1. Lay your board and displays on your box and decide how long the cables will have to be to reach.* 
  2. Cut the 20 wire ribbon cable to the desired lengths, leaving enough length reach from wherever you put the motherboard to where you will put each of the displays, plus a little extra. It's possible you will need different lengths for different displays, depending on placement.  Make sure you provide room for any folding or twisting you might need to do to the cable.  If you are stripping wires off of a wider cable, make sure you leave the colored wire on your cable if possible, you will use it to know which side is which later on.
  3. Place the ribbon cable in the socket and squeeze it shut with a vise. It is possible to crimp it with pliers, but it's also very easy to ruin the socket that way. If available, a vise is greatly preferred.
  4. Repeat with the other end of the cable.  Make sure that the key tab on the socket points the same way as the other end, using the colored wire on the cable to make sure you are consistent.
  5. (optional) Fold the cables over and snap the strain relief clips on to the socket.
  6. Repeat steps 3-5 for the other three cables.
  7. Plug the cables into the the motherboard and into each of the daughter boards.  Use the colored wire on the edge of the cable to make sure that pin 1 on each header matches up with pin 1 on each of the daughter boards.  Let any extra rows hang off consistently.
*It was during this step that I changed my mind about the original wooden box I had purchased and moved to a larger box. I realized I didn't like how crowded it was going to be with the buttons.

Now you are ready to program the micro-controller and see it in action!

Step 7: Program ATtiny

The AtTiny2313 microcontroller now needs to be programed with the firmware to tell it how to behave as a counter, and how to control the other chip.

There are a number of ways to do this, most of which are beyond the scope of this article, but I'll list a few of them and outline the steps I took.

Ways to get the chip programmed:

  • Purchase and build an inexpensive USBtinyISP programmer kit from adafruit. -- This is my preferred method and the one I outline below.  If you are ever going to do anything else with AVR chips (like program your own arduino bootloaders) or might ever want to hack the firmware, this is an excellent investment.  The kit is relatively easy to put together and the process is documented very well.
  • Use a minipov -- A wacky untried option... If you just happen to own another adafuit product, a minipov, you may be able to use it to program the chip.  This fun toy was my first exposure to the AVR microcontrollers and uses the exact same chip.  An innovative feature of this kit is that it includes a jack to plug into a serial port and is its own programmer.  I haven't tried it, but I suspect you could substitute the "counter.hex" file you are going to create below in programming step 5 for the minipov firmware.  Then you can pop that chip out and swap it with the one on this board.
  • Use an arduino -- How-to-program-a-AVR-arduino-with-another-arduino describes how to wire up an arduino to act as an AVR programmer.  Along those lines, the evil mad scientists labs has an ISP shield that turns your arduino into an AVR programmer.  It looks neat.
  • Have a friend do it for you.
Programming it my way (with the USBtinyISP):
  1. Follow the instructions provided for setting up the AVRdude software and using the USBtinyISP.
  2. Plug the 6 pin cable from the USBtinyISP into the ISP header on the board.
  3. Download and unzip the attached "munchkin-counter-firmware-v1.zip" file.
  4. In a dos prompt (I use cygwin instead) navigate to the directory you just created with the firmware source code.
  5. type "make" and watch the code compile.  If AVRDude is set up correctly you should now have a file called "counter.hex" which contains the firmware image for the chip.
  6. type "make burn-fuse".  This will configure the chip with the right parameters to accept and run the firmware.
  7. type "make program".  This will load the counter.hex file onto the chip.
  8. Unplug the USBtinyISP from the board.
Now you should be able to stick a 9 volt battery in the clip and see all the displays light up with 1!  Even though the buttons are not yet attached, you can test out the functionality by simulating button presses.  Just connect the two pads of each of the pairs that say "sw1", "sw2", etc. with a screwdriver or length of wire.  These pads are where the buttons will be connected and shorting them out is what will happen when a button is pressed.

You should see the score on one of the displays increment every time switch 1 in pressed.

Now that you know the circuit works, take the battery out and move on to preparing to mount the circuit into the box.

Step 8: Prepare Box

Now that the circuit is built, you can assess again how it will be mounted.  You will need to decide exactly where each of the displays will go, where the buttons will go and where the on switch will be mounted.

In my case, I completely changed my mind about the box to use, how the buttons would work (eliminating one of them) and decided to put the on switch inside.

So a few moments of introspection on the final look is warranted.  Put the components on the box where you think you will want them and get a feel how they will look and how the buttons will feel.

Once you know exactly how you want it all to look, it's time to start modifying the box and running the final wires.

Step 9: Attach Buttons and Displays to Lid

Attach the displays

Attaching the displays is pretty straightforward.  Cut a square hole the size of the displays for each one.  On this box, I was able to use a hobby knife to cut along pencil lines I traced around the displays, making sure the cuts were slightly inside the lines.

The daughter boards have holes drilled for mounting screws if needed, but I discovered friction was enough to keep the displays in place.  Obviously different boxes will have different mounting options.

Button it up

You will need to do the same thing for the buttons, cutting/drilling holes in your box and mounting them in the box.  Unlike the displays, the buttons are going to constantly have downward force applied to them as they are mashed, so just holding them in by friction will not be enough.  If you are using arcade buttons the outer rings will probably provide enough support but if your box is at all flimsy and your buttons small, you may need to consider some sort of support to go inside the box to mount them on.

The reason this discussion of button mounting is vague is because my solution was unique.  For 10 years I've been lugging around an old mini-computer (about 5 feet tall) that I rescued from a dumpster.  With every move it gets smaller as I throw bits of it away, but I hung onto the control panel because I was sure I could use it for something.   With this project that day finally came.  This control panel had three buttons, one with an arrow pointing up, one with an arrow pointing down, and a button with an equal sign in the middle.

I had originally planned to de-solder the buttons but as I contemplated the problem of how to insure these small buttons didn't just poke through the box, I realized that the buttons were already nicely mounted on a solid board.

So I left them on the board, cut it down to a more manageable size, and soldered wires right onto the board.  To mount them I just cut holes in the lid of the box the size of the buttons, glued the board to the lid, and was done.

For each button, you will need to run a pair of wires to the pads labelled "SW1", "SW2", etc.  In the default firmware, SW1 (switch 1) will increment the score, SW2 will advance to the next player, SW3 will decrement the score and SW4 will put the device into "configuration mode" where you can set up the game.

Notice that my design only has three buttons.  That's because I was so enamored with this control panel that I decided to forgo the fourth button. That's the beauty of using a microcontroller, you can change how your circuit works with software.  The fourth button still works and you can install one (maybe hidden somewhere) but pushing all three of the other buttons at the same time does the same thing in software as pushing the fourth button.

The project is almost complete, there is just a little cleanup left in the next few steps.

Step 10: Wire Up the On/off Switch

Figure out where you are going to have the on/off switch and where you will keep the battery. Once you know that you can figure out how much wire you will need to insert the switch in the power circuit. What you will be doing is putting the switch in line with the power cords, so that turning the switch off will interrupt the power. If you plan to mount the battery close enough to the board, you may only need to disconnect one of the wires to add the switch.
  1. Unsolder one or both of the power connectors from the board.
  2. (optional) If needed, run a wire from the positive power pad to the positive wire to extend it. Solder this wire to the pad and then slip a short (half inch) bit of the heat shrink tubing on the wire. Solder the other end of the wire the the negative wire of the battery clip. Slip the heat shrink tubing over the join and shrink it by applying heat to it.
  3. Solder a wire to the negative power pad.
  4. Solder the other end of the wire to one of the poles of the switch.
  5. Solder the negative wire to the other pole of the switch.
  6. Plug in the battery and test the switch.
Now that you can turn the device on and off, proceed to the next step to optionally eliminate the battery.

Step 11: Create Optional Power Adapter

Running off the battery is great for showing off the box, but it would be a huge bummer if it ran out of juice in the middle of the game.  And there are only so many times you can steal a nine volt batteries out of your smoke detectors before you exhaust that option*
  1. Take a 9 volt power adapter you don't need for anything else (like from a broken toy) and cut off the end.  Please don't do this with it plugged in.
  2. Separate the wires.
  3. Using your multimeter, figure out which wire is positive.
  4. Slip some heat shrink tubing on that wire and solder it to the NEGATIVE (black) wire of the unused battery clip.  This is because the adapter is going to plug into the battery clip connected to the board BACKWARDS.
  5. Slide the heat shrink tubing over the join and shrink to fit.
  6. Do the same thing again, connecting the negative wire to the POSITIVE wire of the battery clip.
  7. Plug the adapter in and use your multimeter to insure that the smaller, round terminal has positive 9 volts.
Now you can choose to EITHER plug a 9 volt battery into the board or replace the battery with this adapter.

NEVERNEVERNEVER plug a battery in this adapter, or leave it anywhere where a kid could do it.  It would probably make the battery explode.

In fact, maybe you should just throw this adapter away and pretend you never saw this step.  A more responsible way to do this would be to wire a jack into the box that the transformer can be plugged into without having cut its tip off.  You should probably do that instead.

* Not that I will ever admit to doing such an irresponsible  thing for a game.

Let's move on from this bad idea and onto the final mounting step...

Step 12: Secure All Components to Lid

At this point, all that is left for the build is to secure everything to the lid.

As shown in the attached photos, I used liberal amounts of hot glue and velcro to secure all the components.

Things that never needed to move again, I glued directly to the box.  Things like cables and batteries I wrapped in velcro, and then glued the velcro to the box.  The allows me to undo the velcro strap whenever I need to replace the battery.

Hot glue is also useful for providing strain relief.  For example, where wires were attached to the buttons, I used liberal amounts of glue to insure that the wires will not be bent there and wear out.

Just glue down everything as neatly as possible.

That's it, your box is finished.  Now it's time to use it...

Step 13: Use It!

Using the device is pretty simple, as shown in the opening video.

Two dots (the decimal points) light up on the display corresponding to the current player.  One button makes the score go up for the current player, one makes it go down, and the other moves onto the next player.

Hold down all three buttons, or push the forth one if you installed it, to enter setup mode.

From setup mode, the up and down buttons will cycle through 11 possible variations you can have of 4 players positions.  That is, 4 different 1 player positions, 2 different 2 player positions, 4 different 3 player positions and all 4 players being scored.

Pressing the "next player" button will select the number of players and move onto the second part of the setup mode where you can choose scoring style.

The up and down buttons will now cycle through the three different scoring modes:
  1. Normal mode - Display each score without making any judgements.  Scores can range from -9 to 99.
  2. Munchkin mode - Scores can still be -9 to 99, but if anyone reaches 10 or more, the other scores will be shown as "L" for "Loser".
  3. Epic Munchkin mode - Same as munchkin mode, but the winning score is 20, and the other displays show "EL" for "Epic Loser".
Push the "next player" button again to exit setup mode and start playing.

Read on to learn more about what's going on inside the device.

Step 14: How It Works (theory)

Click the "i" on the upper left corner of the image to see the full sized version of the schematic.

The brains of the device are packed into an ATTiny2313 micro-controller.  This chip is part of the same family of devices as the ATMega328 used in the arduino platform.  Like it's bigger cousin, the ATTiny2313 has pins that can be used as input to read things like button presses or output to control things like LEDs.  A small amount of non-volitile memory stores code that it will automatically run whenever the chip is powered on.

The difference is the AtTiny has less pins and memory than the AtMega328.

An AtTiny is easily able to drive a seven segment LED display, but there are 8 in this project, two digits for each player position.  Since each display has 8 LEDs (7 segments plus a decimal point) that means it needs to be able to separately control 64 different LEDs!  It's do-able with advanced techniques, but the wiring is complicated and requires a number of extra transistors and resistors.  These techniques also require the micro-controller to spend most of it's time updating the displays, rapidly flashing them on and off faster than the human eye can see.

This is where the Max7219 comes in.  This chip is designed to do all the work of driving up to 64 LEDs which is exactly the number needed by this circuit.  The Max7219 has a set of 8 pins that are wired to each of the segments of all the displays, and another set to apply power to each display separately.  That way, it can set (for example) all the leds that correspond with the number 8, turn on display 1 briefly and then move on to setting the LEDs for display 2.  If it changed the LEDs to display a 2 and rapidly switched it on and off, alternating with display 1, a "28" would be displayed.  It does this for all 8 displays (2 X 4 players) so fast that it looks like the are all on at the same time.

The Max7219 keeps track of which number goes on which display and keeps repeating that cycle until it receives a command from the micro-controller to change one of them.  The ATTiny2313 is connected by 3 lines and can send commands via serial data like "change digit 4 to display an 'E', change digit 3 to display an 'L'".

With all that work of controlling the LEDs offloaded to the Max7219, all the ATtiny2313 has to do is watch for buttons to be pressed and send commands to the Max7219 whenever it needs to change what is displayed.  In this case, the ATtiny2313 is actually a little overpowered for what it needs to do.

That's all the boring theory out of the way, next see my thoughts and musings on this project.

Step 15: Notes

Laser challenge

All kidding about etching of eldritch runes aside, if I had a laser cutter I would used it to expand the sorts of things I make, focusing less on pure electronics.  Examples include:
  • Cut wood to make boxes from scratch.  My grandfather was an artist and carved me boxes often.  I'd like to start making my own.
  • Engrave designs on those boxes.
  • Try my hand at marquetry, carving veneers of different kinds of woods to decorate those boxes.
  • Carve pieces for wooden models.
  • Too much papercraft to contemplate.
  • Everything else listed at my "web server stoplight" article notes.
  • Everything else listed at my "electronic polyhedral die" article notes.
  • Make many beautiful and useful things.
  • Make many beautiful and useless things.

Improvements

This was my second ATtiny project, and the first circuit board of any complexity I had made. As soon as I finished this project, I immediately starting thinking about thinks I might have done differently.  In particular, battery life is an issue. I don't know how long the battery will last but occasionally I've had the box shut down spontaneously, possibly because of a brown-out state. This never happens when plugged in.
If I ever make another, or even get around to re-visiting the code, here are some of the things I might consider changing:

Software
  • To extend battery life, the firmware could be modified to dim the displays after a few minutes of activity, perhaps slowly fading down to almost nothingness.  It would, of course, fully brighten the LEDs when a button is pushed.
  • To save battery life even more, the chip could put itself to sleep after a certain amount of activity.  The ATTiny has interrups that can be used to do stuff (like wake up) when pins change state, so it could wake itself up after a button press.  Unfortunately, only two of the pins I chose for the buttons (SW3 and SW4) have that capability, so if I wanted all the buttons to be able to wake it up, I would have to change which pins are used.
  • It would be nice if there was an option to "roll a die" and generate a random number on the displays.  That could easily be done in software.
  • Also to help with the sting of losing power for some reason, the ATtiny could periodically save the scores to non-volatile memory.  That way you could turn it off, turn it back on and still have your running total.  This memory is only rated for 100,000 erase/write cycles, so it would be important not to abuse it by constantly updating the saved score.  Maybe saving the score only after 20 seconds after a change would be ok.
Hardware
  • Instead of an ATtiny, an ATMega328 could be used instead.  This could make the box arduino compatible and it could be called something stupid like "munckinduino."  The ATMega328 has a lot more pins and all the work done by the MAX7219 could be done by it instead, saving about $8.  Without funky charlieplexing techniques, this would use EVERY pin and limit the device to 3 buttons.
  • Are 4 player positions enough?  It is for my small family, but you can string 2 or more MAX7219 chips together to control more.  Two of them could control 8 displays (128 LEDs!).  This would add about $30 to the cost of the electronics and make the board bigger which also adds to the cost.
  • The power adapter suboptimal. When I first made this, I thought I would always be running on battery power.  A better design would be to have a power jack on the board, that automatically switches to and from the battery input.