Ever since I saw the dragon bone electronic die wand advertised in the back pages of Dragon magazine when I was a kid, I wanted an electronic device to act as a substitute for all my dice.
This device won't substitute for the tactile feel of rolling a handful of funny dice, but its great for traveling games and is a fun project as an introduction to soldering and micro controllers. Having one of these proclaims to all your geek friends that you are another kind of geek entirely.
If you like this, please vote for it in the laser challenge. The box is pretty enough, but if I had a laser cutter I would make my own in the shape of a 12 sided die, cutting the sides out of acrylic with a precision that I could never achieve on my own.
Please see the notes in step 15 for more of my thoughts on what I would do with a laser cutter if I were to win the contest.
Step 1: What You Need
- Soldering iron.
- Dremel and/or other tools to cut and shape the enclosure if needed.
- 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 10 for other options.
|1-||AtTiny2313 microcontroller||-- $1.85|
|1-||20 pin dip socket||-- $0.17 (optional, for AtTiny 2313)|
|1-||tilt switch||-- $1.51|
|1-||Pushbutton switch||-- $0.91 (Use any momentary pushbutton you like).|
|1-||20 mm battery holder||-- $0.91 (for cr2032 battery)|
|2-||33 ohm resistor||-- 2 X $0.10 = $0.20|
|1||cr2032 20 mm 3 V coin cell battery||-- $0.45 (these are ridiculously expensive in stores)|
|1-||2 X 3 break off pin header||-- $0.10 (For ISP)|
|1-||eDice printed circuit board||-- ~1.6 square inches = $?? (Depends on how you get it printed)|
|1-||Common cathode 2 digit 7 segment displays (red)||-- $1.57 (Also comes in Yellow, Green and Blue)|
- Wire (for connecting button and battery)
- Glue (I prefer hot) to attach device in optional enclosure.
- Small bit of heat shrink tubing.
- The optional box or other object you are mounting the die in.
Step 2: Print the Board
Unless you got the board as part of a kit (not yet available, but maybe someday) you will need to have it printed.
For a long and wordy description of how to get a board printed (along with links to even more articles on the subject) see step two of my other article "Build an electronic score keeper".
The board file in eagle format is included in the attached "eDie-1.2.zip" file.
If you don't want to bother with the hassle of formatting the board for printing, you can order it right from BatchPCB for $5. Unfortunately there is a $10 setup fee per order and a shipping charge, so unless you are ordering other boards at the same time, this is a bit pricy.
I have three copies on order from dorkbotpdx in purple for $8.05, I'm excited to see how it turns out.
This board is small enough to qualify for the 10 (5 of tested for printing errors) for $10 deal from seedstudio.com. I am also waiting for those to arrive from china for evaluation.
Do you have to print the board? No, the board is technically optional, you could wire all this by hand. But it's not easy or pretty. See the pictures in the notes step for the original hand wired prototype.
Step 3: Solder the Chip
Start by soldering the ATTINY2313 micro-processor to the TOP of the board. This is the side with most of the writing and where everything except the display will go.
The chip will have a notch on one end that should be lined up with the notch in the outline printed on the board. It is very important to not put it in backwards, or else you will find yourself having to unsolder 20 connections at once which is not fun.
The pins on the chip will probably be spread too wide to fit in the holes. If this is the case, lay the chip on it's side on a flat surface and GENTLY press down to bend all the pins uniformly a degree or two. Flip over and repeat on the side.
Odds are the chip will stick in the board by friction when you flip the board over to solder the contacts. If not, just bend pins from two opposite corners where they stick out of the bottom of the board. This will hold the board in place while you solder all twenty pins.
Excessive heat can damage the chip so try not to leave the soldering iron on any of the pins for more than three seconds or so.
If soldering the chip makes you nervous you can instead solder on a 20 pin socket to put the chip in later. This can make it difficult to program the chip later since the socket may interfere with the programming pins.
The chip is the microprocessor that runs the software to turn the device into a die. It controls each of the LEDs that make up the display and turns them on accordingly. It also reads the state of the buttons to know when to change to a new number.
Step 4: Solder the Resistors
Splay the leads out on the bottom so the resistors don't fall out when you flip over the board.
Turn the board over and solder the four leads where they stick out of the bottom.
After you have soldered them all use the cutters to cut off the excess leads. These little bits of wire will tend to fly off at supersonic speeds right into your eye when you cut them, so be sure to hold onto the ends with your other hand when cutting them.
The resistors control the brightness of the display and protect each of the LEDs from burning out by limiting the amount of current that can flow through them. There is one for each digit.
Step 5: Solder the ISP Header (potentially Optional)
You will probably have to hold the pins in with your finger (or third hand) while you solder the first one. If you do, make sure you don't apply the soldering iron for more than a few seconds or the pin might heat up and burn you or your helper.
Once you have one pin soldered on you can let go and solder the other five without support.
The ISP (In System Programmer) header is used to program the chip. If your chip is pre-programmed and you never intend to change it, this part could be left off. Some people leave ISP headers off anyway and just press them temporarily in with their fingers whenever they want to reprogram.
Step 6: Solder the Display
Note that once you do this, it will be impossible to solder in or change the orientation of the chip, so it's very important to do this step in the proper order, AFTER the chip has been added. This is because the display will actually cover up the bottom of the chip.
Like the chip, the display has two ways it can fit, but only one way it MUST go. Printed on the bottom of the board is a picture of the display which can be used to line it up properly. One corner is marked differently than the others and it is this corner that the pin marked 1 on the display must go. This pin is the lower left one when looking at the display from the front.
The pins on the display will not hold it into board by friction, and the pins are too stiff to bend. Fortunately the display is wide and flat, so you can just lay the display on its back on your table and let gravity pull the board onto it while you solder. As before, solder two opposite corners to hold it in place. After that you can put it back into your vice to finish soldering the other 16 pins.
* When you are done, this will actually be the top of the device, but it's called the bottom since it's where the bottom of all of the other components are soldered.
Obviously, the display is what shows the results of the die roll. By putting it on the bottom of the board, the entire device can be smaller and the display is not surrounded by distracting components. This also helps with mounting the display flush in an enclosure.
Step 7: Solder the Power Connections
Solder the other ends of the wires to the place on the board marked JP1. Make sure that the positive wire goes to the + symbol and the negative wire to the - symbol.
This is where power will be supplied via the battery after the chip is programmed.
Step 8: Solder the Roll Switch
Cut off the excess leads from the bottom like you did with the resistors.
If for some reason you accidentally solder the tilt switch to JP2, this can be corrected later by tweaking the software.
The tilt switch has a little ball that rolls around inside and completes a connection between the two pins whenever the switch is held upright. It will be like pushing a button and connecting the two pads of JP3 whenever you turn the die over to "roll" it.
Step 9: Solder the Selection Button
If the device is going to be mounted in some sort of enclosure you probably want to use flexible braided wire. You will need to make sure you make the wire long enough to reach from wherever you are going to mount it to the circuit board.
If you are not going to mount it in anything, you probably want to use stiff solid core wire so the switch does not flop about. If this is the case, go ahead and solder the other ends of the wires to the pad labeled "J2" or "Increment."
This switch is used to tell the chip that you want to change die modes. I.e. push it once to increment from D6 (six sided die) to D8 (eight sided die) , again to move on to D10 and so on through D12, D20, D100, D2 (coin flip) and D4.
Step 10: Program the Chip
There are a number of different ways to do this, but I'm going to describe how I do it with a USBtinyISP. See my "electronic game counter/storage box" article for a few more options, the process of programing this firmware is exactly the same as in that project.
- Follow the instructions provided for setting up the AVRdude software and using the USBtinyISP.
- Plug the 6 pin cable from the USBtinyISP into the ISP header on the board.
- Get the latest version of the firmware from the google code page.
- In a dos prompt (I use cygwin instead) navigate to the directory you just created with the firmware source code.
- type "make" and watch the code compile. If AVRDude is set up correctly you should now have a file called "eDie.hex" which contains the firmware image for the chip.
- type "make burn-fuse". This will configure the chip with the right parameters to accept and run the firmware.
- type "make program". This will load the eDie.hex file onto the chip.
*I've discovered that even though it appears to work when solely powered by the programmer, without a battery the chip will occasionally be underpowered and reset itself when it tries to light up too many LEDs at a time. Like if it displays an 8. So without a battery, this device can only be a six sided die.
The firmware is a program that the chip runs automatically every time it is powered on. The program controls the displays and watches for the switch inputs. The programmer writes the firmware to the chip's non-volatile memory.
Step 11: Insert the Battery
I have no idea how long the battery will last in regular use but in sleep mode, it should last several decades.
The circuit will run from 2.7 volts to 5.5 volts. So a 3 volt battery is sufficient, while the power from the USBtinyISP is still not too much.
Step 12: Mount Device in an Enclosure (optional)
Or you can mount this device in some sort of box. I chose to combine both options by picking a translucent box, so you can see the components inside.
If you don't mind being on a secret terrorist watch list*, you can get one of these at the container store.
- Cover the spots where you will be cutting holes with masking tape.
- Place the display on the tape and trace around the edges closely with a pencil.
- Using a cutting wheel on your rotary tool, cut out the square. Make the cuts inside the square since a hole too small can be expanded, but you can't shrink one too big.
- Test the fit of the display (you can do this from the outside) and if it won't fit, use the sides of the cutting wheel to slowly expand the hole until it does.
- Use a drill to make a hole for your button. If you drill the hole with the drill set in reverse**, this will take a REALLY long time, but acrylic is soft enough that it will work anyway.
- Remove the nut from the button and work the shaft through the hole from the inside.
- Remove the masking tape and tighten the nut on the button.
- Solder the ends of the wires trailing out of the button to the "J2" or "increment" pad on the board.
- Slide the display into the square hold you made from the inside. Once you are sure everything fits you can put some glue on the board around the display to make it stick permanently. Gorilla glue is good for this as it expands to fill in the gaps left by the pins sticking up, and is non-conductive.
- Put the cap on the end and start showing it to people.
** That would be pretty dumb, but I managed to do it.
The box protects delicate components, and gives the device a flat surface to rest on.
Step 13: Use It
After a few minutes of inactivity, the die will turn itself off to save power. Push the increment button again to wake it up.
The built in dice types are:
D2 - (coin flip, show H for heads or a stretched T for tails)
D4, D6, D8, D10, D12, D20
D100 - (shows as 00 when choosing and if a 100 is rolled.)
There is nothing intrinsically special about those die types other than they are the ones I grew up with. You can add more by modifying just a couple of lines of the software.
Step 14: Schematic and Theory
Lighting the displaysThe display consists of two pairs of 8 LEDs. One LED for each of the seven segments in a digit and one for the decimal point. Each of these 16 LEDs has a separate anode (positive pin) and each digit has a single cathode (negative pin) shared by the 8 LEDs in that digit.
The micro controller doesn't have enough pins to drive every LED separately and read the buttons but because the human eye reacts much slower than the micro controller, we can take advantage of the POV (persistence of vision) effect. This means we can rapidly switch each digit on and off in turns so fast that it looks like they both are on all the time.
To do this, each segment is wired to a specific pin. i.e. Segment A for both digits is wired to pin 12, segment B for both digits is wired to pin 13, etc. To light up a particular number on one digit the pins 8 pins are set in the appropriate pattern (HIGH for on, LOW for off) and the cathode for that digit is turned LOW. This allows current to flow through all the right LEDs. At the same time, the Cathode is set HIGH for the other digit. Since LEDs are diodes, power can flow only one way and so all the segments on the other digit are off.
After a few milliseconds the display is turned back off by setting the cathode HIGH, all the segments are reset for the other digit, and that digit is turned on by changing its cathode to LOW.
This process is repeated many times every second, giving the illusion that both digits are on all the time.
Random numbersGetting a computer to reliably generate a random number is surprisingly difficult. Rather than even try, this device lets the user unknowingly pick the random number. A counter constantly adds one to it's value, hundreds of thousands of times a second. When the roll "button" is triggered the number is looked at and used to make the random number. This way, the randomness of the event is determined by when the button is triggered, at a scale way too fine for a human to control.
Power management (or, where is the off switch?)In addition to the random number counter, the device is constantly counting the time since the last time either of the two buttons were pressed. After a few minutes of inactivity, the device will put itself to sleep in an extremely low power mode. In this mode almost all activity ceases and if my calculations are right, the battery should last 30 or 40 years while asleep. Since my time machine project has not gotten very far, I have been unable to test this theory.
While in this mode, the device still is able to detect if pin 6 is shorted and is configured to wake up if this ever happens. Thus, pressing the increment button will wake the device up and it will continue on its way.
Step 15: Notes
Laser challengeAs mentioned in the introduction, I think this would look much nicer if mounted in a custom enclosure that looked like a die. With a laser cutter I would cut a nice piece of acrylic into 12 pentagons (with alternating tabs the width of the acrylic) to fit together in a dodecahedron shaped box. The cut pieces would be engraved with electronics symbols where the numbers would otherwise be, and the holes for the display and button would be perfect. This would turn it into a 12 sided die that can do the job of all the other dice, fitting since the 12 sider is otherwise neglected.
Other things I would use a laser cutter for include (but are not limited to):
- The next project I'm considering is a 7 X 32 LED scrolling sign for the back of my car. It sure would be nice to be able to cut those 224 holes for the LEDs in a perfectly uniform manner.
- Precisely cut the corners off of square things to prepare for life about a battlestar.
- Everything I previously had considered buying a cricut for, but 1000 times better.
- Boxes, boxes and more boxes.
- Make professional looking signs for every room in the house.
- Custom game pieces.
- Wooden or acrylic cosmic encounter boards and boards for other games.
- Everything else listed in my "webserver stop light" article's notes.
- Everything else listed in my "elecronic score keeper" article's notes.
- I'd make many beautiful and useful things.
- I'd make many beautiful and useless things.
Paranoia about electronics devicesBuying the small blue box I mounted this in lead me to a very surreal conversation.
I found this (and a couple of other sizes I experimented with) at a local "the container store". When I went up to pay for it, the cashier was particularly chatty, initially freindly, and (I felt) inordinately interested in what I was going to put in my containers. At first I imagined that she just liked her job, and liked to fantasize about all the fun things people people put in their containers. But after talking to me, I believe her container stuffing fantasies took a dark turn. Or perhaps she always imagines herself as a vigilant watch dog, guarding against nefarious criminal uses.
Her: Oh, those little blue boxes, I remember those. I had a lot when I was a teenager.
Me:<smiles and nods politely>
Her: Are you buying them for nostalgia? From when you were a teen? They are too small to really keep anything in them.
(I'm not really sure what the implication was here. Perhaps she used to keep drugs in hers?)
Me: No, they are for a project I'm working on.
Her: Oh, what are you going to keep in them?
Me: I'm not going to keep anything in them. I'm going to cut a hole in one and use it to mount my project.
Her: What do you mean? <looking very perplexed at that moment>
Me: I have some electronics I've made and I'm going to cut a hole in the side so you can see the display, and mount the electronics inside.
Her:<with a look and tone of horror>Do you mean.... (dramatic pause) a device???
Me: Yes. An electronic device I've made.
No longer chipper and friendly, she said nothing more to me other than to tell me the total bill. I imagine as soon as I was gone she ran off to report me for making dangerous electronics. Alas, I paid with a credit card so now my name is on some super secret terrorist watch list, for having the gall to use a small decorative box for something other than it's imagined proper use.
Over a decade in the makingI first tried to make a device like this in the late 90s. My original design was going to speak the digits with a sound recording chip I got at radio shack, and used a PIC micro controller. At that time there was (to my knowledge) no free C compiler and no free simulator for the chip. I wrote the initial code in assembly to light up some LEDs, compiled it, ran it through the dedicated programmer I bought and then stared at the chip. It did nothing. I looked at my code and found no obvious errors, but I was hardly an assembly language expert.
And then I was stuck. With no simulator or way to see what was going on in the chip, I had nowhere to go to debug it. Something was wrong with my code and the chip was a little black box I had no insight into. I never totally give up in a situation like this, but I was discouraged enough to finally put it away for a few days. And then a few more, and then a few weeks and then months. Eventually over the years I lost the PIC programmer in a move or something.
About 10 years later, I bought a mini-pov kit from adafruit and had fun supervising my son as he put it together. Later a friend asked me to help him hack it into a brain machine and I was impressed at how easy it was to replace the firmware with new software that totally changed what it did. I looked into the processor used by this device and found that micro processors had become much easier to use. This inspired me to try to make my electronic die again.
I bought a USBispTiny kit, put it together and built my first prototype on a bread board. Just like the first time, nothing happened. But now instead of being stuck, I had options. I used the free AVR studio to simulate the chip and watched exactly what my software was doing wrong. Very soon I had a working prototype and moved on to experimenting with printing my own board.
If I were doing it today, I probably wouldn't even have to bother with AVR studio, since this project could probably be designed in the arduino environment, and then ported to the ATTiny chip.
The moral of the story is that as time goes by the barrier to entry with micro controllers drops lower and lower and it gets easier to get your feet wet all the time.