/* Solar Bug Bot Firmware for use with ATtiny2313 Chaos Computer Congress (24C3) Mitch Altman 4-Jul-08 Distributed under Creative Commons 2.5 -- Attib & Share Alike */ /* Ladyada has a great website about the MiniPOV kit, from which this project was hacked: http://ladyada.net/make/minipov3/index.html Her website also has a user forum, where people can ask and answer questions by people building various projects, including this one: http://www.ladyada.net/forums/ (Click on the link for MiniPOV). */ #include // this contains all the IO port definitions #include // interrupt vectors and definitions #include // definitions for power-down modes /* This project has a small vibrating motor, a small speaker, two LED "eyes" and a small flexible solar panel. The Solar panel can be glued over the PCB to create a shell for the BugBot. If you attach the "eyes" at the end of pipe cleaners, and attach a pipe cleaner "tail" to the motor, and attach the PCB to the battery case, and attach 6 pipe cleaners to the battery case as "legs," then you have a cute little critter. As the motor vibrates, the BugBot moves on its flexible legs. When light hits the solar panel it changes what the BugBot does. */ /* This project provides an example of how to use the Analog Comparator and how to use interrupts on the AVR. The ATtiny2313 has two analog inputs that can be set up to compare two voltages. When the voltage on AIN0 is greater than the voltage on AIN1 the Analog Comparator Output is set (this is the ACO bit of the ACSR, the Analog Comparator Status Register). The ACO bit can then trigger a processor interrupt. For this project, the AVR normally makes the BugBot's eyes toggle in a semi-random-seeming fashion. But if light hits the solar panel, it triggers an interrupt. An interrupt is the same as a firmware function call, except the call is triggered by a hardware event (rather than by a firmware instruction). The function that is executed is the interrupt service routine for that interrupt (for this project, the interrupt service routine is one I wrote for the Analog Comparator Output). This interrupt service routine looks at the ACO bit, and if it is set (meaning that a bunch of light is hitting the solar panel), it makes the BugBot go though a song & dance routine. The song & dance continues until light stops hitting the solar panel, at which point, the eyes blink quickly, and the firmware returns to the Main function, where the eyes go into their semi-random-seeming sequence. And we're ready for the next time light hits the solar panel. */ /* Parts list for this Solar BugBot project: 1 MiniPOV kit 2 AA batteries 1 3v motor (from a junked cassette player, or Jameco #231909) 1 flexible solar panel (Jameco #227985) 1 aligator clip (for creating an off-center weight on the motor to make it vibrate when it spins) 1 100k ohm resistor (to create a voltage to compare solar panel output voltage against) 1 470k ohm resistor (to create a voltage to compare solar panel output voltage against) 1 1N4007 (to protect the semiconductors from back EMF from the motor) 1 2N3904 (to drive high current for turning the motor On and Off) 2 10 ohm resistor (current limiting for the motor, and for the speaker) 1 small speaker (Jameco #673871) 1 220uF capacitor (power supply bypass, to deal with surges of current from motor stopping and starting) 4 12" pipe cleaners (eyes, legs, tail) hot glue, or other suitable glue */ /* The hardware for this project is very simple: ATtiny2313 has 20 pins: pin 1 connects to serial port programming circuitry pin 10 ground pin 12 AIN0 -- 3v solar cell pin 13 AIN1 -- voltage divider for solar cell voltage detection (100K to ground, 470K to +3v) -- creates 0.5v at this pin pin 15 PB3 -- tiny speaker pin 16 PB4 -- transistor to drive 3v motor pin 17 connects to serial port programming circuitry pin 18 PB6 -- LED eye -- also connects to serial port programming circuitry pin 19 PB7 -- LED eye -- also connects to serial port programming circuitry pin 20 +3v All other pins are unused This firmware requires that the clock frequency of the ATtiny is the default that it is shipped with: 8.0MHz */ // This function initializes the LEDs, motor, speaker, Analog Comparator, and interrupts // (For some reason, the compiler doesn't like functions without arguments, and I'm too tired to figure out why, so I put a dummy argument in, even though Init() doesn't need an argument). void Init(int dummy) { DDRB &= ~(1<