Attiny13 green double led dice

Try making a double led dice with 14 leds driven only by 4 available pins of an Atmel Attiny13a. I did it, and it worked. See the result in this video.

Attiny13a charlieplexed double green led dice

14 leds can be driven by a technique called charlieplexing when not many microcontroller pins are available. This technique works from the fact that leds are diodes and that those diodes have a little voltage drop. In the network of leds, you can make one led turn on by applying a voltage smaller than twice the voltage drop of a led. In this way, only one led lights up. The other leds do not turn on because the voltage is not high enough.

To make all the leds light up you must cycle through all the leds very fast. Only one led can be turned on at a time. If you cycle through all leds very fast they all seem to be on at the same time to the human eye.

According to the schematic the pins PB0 to PB3 from the microcontroller are used to drive 8 leds, every 4 of those make one die (dice).

5 volt is needed to power the circuit. Any more and you will burn out the microcontroller. You can use your computers USB port to power the circuit. 3 pieces of 1,5V alkaline batteries also work. To prevent polarity reversal you can mount a reversed diode parallel to the supply voltage so that when you put the batteries in wrong you have a chance the board survives. I powered the circuit by a emergency USB phone charger, it seems to work great.

One of the four buttons in each corner on the bottom of the PCB can be used to trow the dice (inspired by Elmar on sk.net). Just press somewhere on the top of the PCB and they will signal the microcontroller on pin PB4 to start the trow.

When one of the buttons are pressed the microcontroller show random values on the leds. First at a fast pace to make throwing exciting and after a few seconds very slow ending in the value you threw, for example the value 4 and 2. The values shown are completely random, no cheating possible. This randomness is achieved by the simple fact that the moment of pressing one of the buttons (by a human) is unknown and thus random. When the buttons are not pressed the microcontroller is cycling through 1 to 36 (6×6) very fast. Pressing one of the buttons the value is frozen and that is the value you get.

You can make this double led dice yourself by programming the provides hex file in an Attiny13a microcontroller.

MB018.hex
Source code. Compile with AVR Studio 5.1.

Program the high fuse with 0xFD and the low fuse with 0x72.

You do not have to use the SMD version of the Attiny13a. A through-hole version also works. You can even use giant 10mm leds instead of tiny 0805 smd leds.

Want to try writing software yourself? Use the following tables to see how the leds are hooked up to the microcontroller:

D3A D2B
D4A D1 D4B
D2A D3B

and

D7A D6B
D8A D5 D8B
D6A D7B

D2A and D2B turn on at the same time, just as D3A and D3B, and DnA and DnB… etc.

For example, to show the value “1”, D1 must be turned on. To show the value 2, turn on D2. 3: D1 and D2. 4: D2 and D3. 5: D1, D2 and D3. 6: D2, D3 and D4.

Did you like this post? Please give it a thumbs up by sharing it on your social network. Thanks!

5 thoughts on “Attiny13 green double led dice

  1. ko4xl

    I built a very similar project before finding yours. My hardware design uses charlieplexing of the LED series pairs, much like yours. I don’t have access to PCB making supplies or SMD parts, so mine’s hand wired on perf board using all through-hole parts. On the software side, instead of an if-else chain I use tables in PROGMEM to get the DDR and PORT values for each charlieplexed pair and to get the pip pattern for each dice value. I also added a timeout feature to turn off the LEDs after 30 seconds and to put the CPU in power-down after one minute. At power-down time, the trow pin is configured for a pin-change interrupt so that the next button press will turn the CPU back on. By this method, the batteries will last almost their normal shelf life without the need for an on/off switch.

    Reply
    1. marc Post author

      Clever idea to use a lookup-table and auto-power-down. Maybe the AA batteries can be replaced with a smaller coin-cell because of the power savings.

      Reply
      1. ko4xl

        Agreed. Only had AAA holders when I built it. If I switch to coin cells it’ll fit in a thinner package like an Altoids box.

        Reply

Leave a Reply

Your email address will not be published. Required fields are marked *