d3kod’s Mechanized Android

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.

Not much space left inside...

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.

Mechanized Android - inside-out

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! ^^

Video of my Mechanized Android in action

FYI, it’s not tomorrow until you sleep.


6 responses to “d3kod’s Mechanized Android

  1. Very cool, whats D1 for? Polarity protection? Only thing I could see is it may be worth adding a pullup resistor to the switch, so when its open the pin doesn’t float. You can occasionally get false triggers otherwise..

    • About D1, I assume so… btw, is it a problem if I don’t have it? I think I forgot to put it in =/

      Yes, I suppose you are right about the pull-up… as I read a bit more into the subject, I think I made another mistake. Should the pin that connects with the switch (pin 8 in my case) be configured as input instead of output? If configured as input and the internal pull-up resistor enabled, then it will stay at logical 1 as long as I don’t short it to GND. Right now it is configured as output… not entirely sure why it works and if it is a problem 😕

  2. No, it’ll be fine as long as you don’t put the batteries in backwards :).. You’d be amazed how much current you can draw from 4 AA batteries, I did an experiment once wiring a MOSFET up backwards to see how much current it took to blow, bench supply maxed out at 3A with no magic smoke, 4 AAs instantly turned it into a firework..

    Ah yes, internal pullup will work a treat, and it needs to be configured as an input (assuming its the same as a PIC)

    • Thanks for the clarification 🙂 I have updated the post and the repository with the proper configuration for PA5. I can’t test if it works though, so if anyone encounters problems following my steps (the mute button does not work), this is a possible cause.

  3. Pingback: Robohash and website faces | Primal Pond

  4. Pingback: Happy Beltane! And a week’s worth of blogging | Primal Pond


Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s