Introduction: Electronic Dice Using Attiny84

About: Jack passed away May 20, 2018 after a long battle with cancer. His Instructables site will be kept active and questions will be answered by our son-in-law, Terry Pilling. Most of Jack's instructables are tuto…

This project is an electronic dice using an Attiny84 chip. The Attiny84 works like an Arduino except it is a 14 pin chip and is has less memory and there is no built in programmer. I will be showing how to upload a program with an Arduino using the Arduino IDE and a USBtinyISP in later steps.

One advantage that the Attiny84 has over the Arduino is the fact that all eight pins on one pin bank (A) are available. If you want to address the pin registers directly or program in assembly language this makes it much easier. I am not using this feature in this project, but I thought I should mention it in case this is your introduction to Attiny84.

For more information on addressing the pin registers directly see this instructable:

https://www.instructables.com/id/Fast-digitalRead-d...

For more information on Atmel assembly language see this collection of instructables:

https://www.instructables.com/id/Command-Line-AVR-T...

You will need:

* This resistor kit from Sparkfun has the 470 Ohm resistors you will need for this project, and a lot more.

Step 1: Socket and Cross Wires

This is the pinout diagram for the ATtiny84 chip:

                          ATtiny84
                    VCC - 1  U  14 - Ground
                          2     13 - Arduino Digital Pin O
                          3     12 - Arduino Digital Pin 1
                          4     11 - Arduino Digital Pin 2
  Arduino Digital Pin 8 - 5     10 - Arduino Digital Pin 3
  Arduino Digital Pin 7 - 6      9 - Arduino Digital Pin 4
  Arduino Digital Pin 6 - 7      8 - Arduino Digital Pin 5

Each die is composed of seven LEDs and uses four digital pins, arranged like this:

             Green       Red
              LED        LED
             2 1 0      5 4 3
               7          6
             0 1 2      3 4 5
Mount the IC socket with the alignment notch pointing to the right.

The pink line on the IC is the alignment mark for the IC, it will go on the right when the IC is installed.

Solder the cross wires as shown.

Step 2: Center LEDs

Solder the center LEDs.

Solder the green LED, the anode (long wire) goes in F-15 and the short lead goes in E-15.

Solder the red LED, the anode (long wire) goes in F-25 and the short lead goes in E-25.

The LEDs should stand about 1/4 inch above the board.

Step 3: Resistors

The diagram show the resistors on top in the ground rail and in row I, the resistors on the bottom are in the ground rail and row C. In Fritzing the resistor mounting holes have to be .4 inches apart. Using 1/4 watt resistors it is possible to put them in mounting holes .3 inches apart. The resistors are actually soldered into rows B on the bottom and J on top.

Step 4: The Rest of the LEDs

Solder the rest of the LEDs as shown in the diagram. Keep them as straight as possible and they should stand about 1/4 inch above the board. For clarity this diagram does not show the center LEDs and the cross wires.

Step 5: The Wiring

Solder the wiring as shown in the diagram.

The red and black wires will go to the on/off switch, they should be about 6 inches long.

The yellow and black wires will go to the push button switch, they should be about six inches long.

Step 6: Drill Holes in Case

The mounting hole on the right is 2 5/16 inches from the top and 2 1/4 from the right side of the case.

Layout the holes, center punch the locations, and drill 1/16 inch pilot holes.

Be very carefull locating the holes, the web between the holes is very thin.

The holes for the LEDs are 7/32 diameter.

The holes for mounting the board are 1/8 inch diameter.

Drill a pilot and then a 1/4 hole 4 3/8 down from the top of the case, centered right to left.

Drill a pilot and then a 1/4 hole 1 1/4 inches from the left and bottom sides of the case.

You need a 1/2 inch holes for each of the two switches. The holes were drilled 1/4 inch because drilling holes this big in thin sheet metal can be difficult.

I used a 1/4 inch drill and enlarged the holes with a conical reamer like the one shown in the second picture. The conical reamer was purchased at Ace hardware.

Deburr the holes on the inside of the case.

Step 7: Set Up the ATtiny84 Programming Environment

You will need to have the Arduino IDE installed on a computer to program the ATtiny84 chip. Go to https://www.arduino.cc/en/Main/Software to download the Arduino IDE. There are instructions here to install it on Linux, Windows, or Mac machines. If you are using Debian or Ubuntu it is in the repositories, just open a terminal and type:

sudo apt-get install arduino

Next you need to download the chip definition files for the ATtiny chip. They are available at:

https://github.com/damellis/attiny/

You will get a zip file named attiny-master.zip, unzip it and you will have a directory named attiny-master. Inside the attiny-master directory there is a directory called attiny, this is the one you are looking for.

The Arduino software stores your programs and some other stuff in a directory called sketchbook.

Open the sketchbook directory and look for a directory called hardware. If it does not exist create it.

Copy the attiny directory into the hardware directory.

Check to make sure the Arduino IDE is finding the chip definitions by opening the Arduino IDE and clicking on Tools and then click on Board. You should see three entries to run the Attiny84 chip at 1, 8, or 20 MHz. There are also 3 entries each for the Attiny85, Attiny45, and Attiny44.

Step 8: The Program

Copy the following program into the Arduino IDE:

/*****************************************************
 * Program name: Dice.ino
 *
 * Dice Pins: Green     Red
 *            2 1 0    5 4 3
 *              7        6
 *            0 1 2    3 4 5 
 *
 * Button switch: PIn 8
 *****************************************************

/*****************************************************
 * Setup code run at startup
 *****************************************************/
void setup()
{
  randomSeed(analogRead(0));

  for(int i=0; i<8; i++) pinMode(i, OUTPUT);
  pinMode(8, INPUT_PULLUP);
}

/*****************************************************
 * Loop runs in a continuous loop when setup finishes
 *****************************************************/
void loop()
{
  int rnd;  // Holds random number
  int i, j; // Indexes for for loops

  while(digitalRead(8) == HIGH); // Wait for button press.
  while(digitalRead(8) == LOW); // Wait for button release.

  randomSeed(millis()); // Blink at randon while dice roll.
  for(i=0; i<20; i++)
  {
    for(j=0; j<8; j++)
    {
      rnd=random(1, 3);         
      if(rnd == 1) digitalWrite(j, HIGH); //Display random sequence
    }
   delay(100);
   for(j=0; j<8; j++) digitalWrite(j, LOW); //Clear random sequence
  }

  randomSeed(millis());
  rnd=random(1,7); //First Die (green)
  switch(rnd)
  {
    case 1:
      digitalWrite(7, HIGH);
      break;
    case 2:
      digitalWrite(2, HIGH);
      break;
    case 3:
      digitalWrite(0, HIGH);
      digitalWrite(7, HIGH);
      break;
    case 4:  
      digitalWrite(0, HIGH);
      digitalWrite(2, HIGH);
      break;
    case 5:  
      digitalWrite(0, HIGH);
      digitalWrite(2, HIGH);
      digitalWrite(7, HIGH);
      break;
    case 6:  
      digitalWrite(0, HIGH);
      digitalWrite(1, HIGH);
      digitalWrite(2, HIGH);
      break;
  }
  
  rnd=random(1,7); // Second Die (red)
  switch(rnd)
  {
    case 1:
      digitalWrite(6, HIGH);
      break;
    case 2:
      digitalWrite(5, HIGH);
      break;
    case 3:
      digitalWrite(3, HIGH);
      digitalWrite(6, HIGH);
      break;
    case 4:  
      digitalWrite(3, HIGH);
      digitalWrite(5, HIGH);
      break;
    case 5:  
      digitalWrite(3, HIGH);
      digitalWrite(5, HIGH);
      digitalWrite(6, HIGH);
      break;
    case 6:  
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);
      digitalWrite(5, HIGH);
      break;
  }
}

The next steps show how to upload the program to the Attin84 chip.

Follow step nine to use an Arduino as a programmer or step ten if you are using the USBtinyISP programmer.

Attachments

Step 9: Loading the Program With an Arduino

                          ATtiny84

             Five Volts - 1  U  14 - Ground
                          2     13 
                          3     12 
      Pin 10 on Arduino - 4     11 
                          5     10 
                          6      9 - Pin 13 on Arduino 
      Pin 11 on Arduino - 7      8 - Pin 12 on Arduino

Open the Arduino IDE and click on File=>Examples=>ArduinoISP.

Click on Tools=>Board and select the Arduino you are using. (In most cases, including my own, this will be Arduino Uno.

Click on Tools=>Programmer and select AVRISP mkII.

Click on the upload button. (The right arrow button second from the left.)

Place the Attiny84 on a breadboard and connect the wires as shown in the diagram.

Click on Tools=>Board and select ATtiny84 (internal 1 MHz clock).

Click on Tools=>Programmer and select Arduino as ISP.

There is no reason to run the chip at a higher clock speed, all that will do is use more electricity. If you have changed the clock speed use the Tools=>Burn Bootloader option to reset the chip to 1 MHz. The burn bootloader option does not actually burn a bootloader on the ATtiny. It just changes the internal fuses to set the clock speed and a few other settings you don't need to worry about. If you are using a new chip there is no need to burn the bootloader, the chip comes set the way you want it.

Copy/Paste the program listed in step 8 into the Arduino IDE and click on the upload button.

Step 10: Loading the Program With a USBtinyISP

This step contains the directions to upload the program in step 8 to the ATtiny84 using the USPtinyISP programmer available from Sparkfun. In the picture of the programmer there is a six pin connector in the middle that I added. The programmer comes with just the mounting holes.

Place the chip on a breadboard and make the connections shown in the diagram below:

   USBtinyISP   ATtiny84      USBtinyISP          ATtiny84<br>     1  U  8    1  U  14         Pin 1 connects to Pin 4   Reset
     2     7    2     13         Pin 4 connects to Pin 14  Ground
     3     6    3     12         Pin 5 connects to Pin 7   MOSI
     4     5    4     11         Pin 6 connects to Pin 8   MISO
                5     10         Pin 7 connects to Pin 9   SCK
                6      9         Pin 8 connects to Pin 1   VCC
                7      8 

Open the Arduino IDE, click on Tools and select Board.

Click on ATtiny84 (internal 1 MHz clock).

Click on Tools again and select Programmer. Click on USBtinyISP.

There is no reason to run the chip at a higher clock speed, all that will do is use more electricity. If you have changed the clock speed use the Tools=>Burn Bootloader option to reset the chip to 1 MHz. The burn bootloader option does not actually burn a bootloader on the ATtiny. It just changes the internal fuses to set the clock speed and a few other settings you don't need to worry about. If you are using a new chip there is no need to burn the bootloader, the chip comes set the way you want it.

Copy/Paste the program listed in step 8 into the Arduino IDE and click on the upload button.

Step 11: Final Assembly

Solder the black wire from the board and the black wire from the battery pack to the on/off switch.

Splice and tape the red wire from the board and the red wire from the battery pack together. (Or you can use a small wire nut like I did.)

Grind or sand the 1/2 inch nylon spacers down to about 7/16 long.

Mount the switch and use the two 4-40 machine screws, nylon spacers, and nylon nuts to mount the circuit board.

Mount the pushbutton switch and solder the yellow and black wires to it.

Tape the battery holder to the bottom of the case.

Assemble the case and mount the feet on the bottom using the supplied screws.

Arduino All The Things! Contest

Participated in the
Arduino All The Things! Contest

Make It Glow! Contest

Participated in the
Make It Glow! Contest

Homemade Gifts Contest 2015

Participated in the
Homemade Gifts Contest 2015