Arduino ATtiny workshop

Project: Programmable Arduino Sound Device

Schematic:

Kit:

  • 1 Attiny85 or ATtiny45
  • 1 Speaker
  • 1 Battery holder
  • 1 3V Lithium coin cell battery
  • 1 Photoresistor
  • 1 22 K Ohm Resistor (red-red-orange) to go with photoresistor

Consumables:

wood, nails, wire, solder, etc.

Tools

hammer, wire cutters, wire strippers, needle nose pliers, soldering iron, etc.

Instructions for Builders:

Construction steps (pictures to follow):

  1. Solder a red and a black wire to the battery holder. Make sure the red wire is attached to the terminal marked +

  2. Insert a pair of nails for the battery holder
  3. Attach battery holder to first pair of nails. Make sure the red wire is on top.

  4. Solder a red and a black wire to ATtiny. Make sure the red wire is attached to the pin (pin 8) opposite the dot (pin 1)


  5. Insert a new nail for the black wire of the ATtiny
  6. Attach the red wire of the ATtiny to same nail as the red wire of the battery holder. Attach the black wire of the ATtiny to the new black nail.
  7. Solder a blue and black wire to the loudspeaker. It doesn’t matter which is which.
  8. Attach the blue wire of the loudspeaker to pin 3 of the ATtiny, and attach the black wire to the same nail as the black wire from the ATtiny
  9. Insert two nails for the photoresistor
  10. Connect the photoresistor to the two new nails. The photoresistor is non-polarized, meaning it does not matter which way it is connected.
  11. Insert a new nail for the fixed resistor below the photoresistor
  12. Attach the fixed resistor between the photoresistor and the new nail
  13. Solder a blue wire between pin 2 of the ATtiny and the nail between the fixed resistor and the photoresistor

  14. Connect the two upper nails with a red wire
  15. Connect the three bottom nails with a black wire
  16. Solder all connections to the nails
  17. Insert battery. Make sure the side marked “+” faces up
  18. If you have a pre-programmed ATtiny, proceed to step 19. If you have an unprogrammed ATtiny, follow the instructions (that I haven’t written yet) to program your ATtiny. You can also deduce these instructions from the links below. You will need something to use as a programmer, such as an Arduino, and a way to connect 4 wires to the ATtiny, such as tiny alligator clips or microhooks.
  19. Cover up the photoresistor with your hand and see if the sound changes

Instructions for Assistants:

Prepararations:
Preparation I: Installing ATtiny45 / ATtiny85 support in Arduino

  1. Download: attiny45_85.zip
  2. Locate your Arduino sketchbook folder (you can find its location in the preferences dialog in the Arduino software)
  3. Create a new sub-folder called “hardware” in the sketchbook folder.
  4. Copy the attiny45_85 folder from the attiny45_85.zip to the hardware folder.
  5. Restart the Arduino development environment.

Preparation II: Set up your Arduino as an ISP

  1. Download ArduinoISP revision 04 and unzip in the examples directory (E.G., arduino-0023/examples on Linux)
  2. Program Arduino with ArduinoISP

To Program ATtiny:

  1. REMOVE THE BATTERY FIRST!!
  2. Connect wires:
  3. ATtiny Pin 1 to Arduino Pin 10
  4. ATtiny Pin 5 to Arduino Pin 11
  5. ATtiny Pin 6 to Arduino Pin 12
  6. ATtiny Pin 7 to Arduino Pin 13
  7. ATtiny Pin 4 to Arduino Gnd
  8. ATtiny Pin 8 to Arduino VCC
  9. Select “ATtiny45 (w/ Arduino as ISP)” or “ATtiny85 (w/ Arduino as ISP)” from the Tools > Board menu
  10. Upload the sketch.
  11. You’ll probably get the following message, but don’t worry, the upload should have worked anyway:

avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85

avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85

References:

http://hlt.media.mit.edu/?p=1229

http://toasterbotics.blogspot.com/2011/08/programming-attiny85-arduino-style.html

http://jarv.org/2011/11/custom-musical-greeting-card-for-less-than-5/

http://hackaday.com/tag/attiny85/

Arduino Program (sketch)

// For the ATtiny workshop
//
// A3 is the light sensor
//
// PB4 is the speaker

// For a 20 MHz ATtiny85, delayMicroseconds can be between about 4000 (low frequency) and 1 (high frequency)
void setup()
{
  pinMode(PB4, OUTPUT);
} 

// Simple tone
void loop()
{
  while(1)
  {
    digitalWrite(PB4, HIGH);
    delayMicroseconds(50);
    digitalWrite(PB4, LOW);
    delayMicroseconds(50);
  }
}

void setup()
{
  // PB3 and PB4 are unused during programming
  pinMode(PB4, OUTPUT);
} 

// Raygun - like sounds 
const int scale[]={3200, 1600, 800, 400, 200, 100, 50};

void loop()
{
  for( int i = 0; i < 7; i++)
  {   
    digitalWrite(PB4, HIGH);
    delayMicroseconds(scale[i]);
    digitalWrite(PB4, LOW);
    delayMicroseconds(scale[i]);
  }
}

void setup()
{
  pinMode(PB4, OUTPUT);
} 

// Theremin
void loop()
{
  digitalWrite(PB4, HIGH);
  delayMicroseconds(analogRead(3)/10);
  digitalWrite(PB4, LOW);
  delayMicroseconds(analogRead(3)/10);
}

Acknowledgements

Thanks to the authors of the pages listed in the references above

Thanks to my nephew Adam for helping me develop this project!

One Response to “Arduino ATtiny workshop”

  1. nanoBorg88 Says:

    I like the traditional breadboard you used. A few questions however, you have three sketches written there, can you use them at the same time, as it is there? or would you need to choose one to upload? If it doesn’t use it, does the ATtiny mind the extra code being there?
    If anything I guess you do have some free pins so can have a push button to cycle through them.

Leave a comment