Update 30.04.2012 – Changed the mute/unmute pin to input and activated the pull-up resistor (because that’s the proper way to do it). Thanks frazzledbadger!
With my Mechanized Android now gone to it’s intended recipient (who’s been waiting for it for ages now, sorry for that!), here are the details of making it that may or may not help someone in my situation. For a great step-by-step explanation of the whole process follow the original guide. That’s what I did, anyway. Here I focus on the mute/unmute upgrade I made.
Firstly, a word of advice: the cables should really be as short as possible, because space in the figure is very very limited. This is one of the main problems I had on the times I failed – I had to use force to cram the electronics in the body (in a way that there is space for the head to turn), which logically resulted in broken solders and what-not else. This final time I was still tight on space, so could have done better. But it works, and I am afraid to open it up again.
The source code and the schematics can be found here. I intend to keep the repository updated, so if you find a bug please let me know 🙂
Now, the mute/unmute button. It works as follows:
- Pin 8 is set high as the Android figure is powered on.
- The chip keeps track of two global flags – S_BUTTON and S_MUTE.
- Whenever the button is pressed, Pin 8 gets shorted to GND
- A change to the voltage at Pin 8 triggers an interrupt which sets the S_BUTTON flag to 1.
- Every time the loud-noise sequence (turning the head, Morse code the eyes…) executes, the chip looks at the S_BUTTON flag. If set, it toggles the value of the S_MUTE flag (from 1 to 0 or from 0 to 1).
- The loud-noise sequence is executed muted or unmuted depending on the value of the S_MUTE flag – 1 or 0, respectively.
- The value of S_MUTE is stored in the persistent memory of the chip (EEPROM) so that it is retained on power loss.
Basically, I cheated a bit with the S_BUTTON flag to make my life easier. In reality it shows not if the button was pressed, but if the button was pressed since the last loud-noise sequence. It’s value is checked just once, at the start of the beeping period. This means that, for example, the robot will not mute immediately if you press the button while the Morse code is going. It will mute on the next loud-noise sequence, though.
As you can see, the hardware upgrade (with red) is trivial. The tactile switch simply shorts pin 8 to GND.
The biggest thing I made is the assembly source code for handling a button push. Here are the changes to the original:
- Activate interrupt on pin voltage change (in this case pin 8)
- Handle the interrupt (in the PROCESS_SWITCH label)
- Keep track of the state in one of the general registers (S_BUTTON and S_MUTE are just bits in this register)
- Write/read persistent memory (EEPROM_write and EEPROM_read, which were taken almost directly from the ATtiny44A manual)
- Bits and pieces of assembly to switch sound on/off with respect to S_MUTE.
!!! Don’t forget to set the pin which will be monitored for voltage change as input and activate the pull-up resistor on it (setting the corresponding bit to 0 in DDRA and 1 in PORTA).
I will be happy to help clarify any issues you might have, just post them below. Comments/improvements are also welcome…. I am a newbie, surely made a mistake somewhere 😉
Hope you found this useful. If you decide to give it a try, happy hacking! ^^
FYI, it’s not tomorrow until you sleep.