Miffy surprise

From Electriki
Jump to navigationJump to search


Fig.1: real bunnies. Once upon a time (in a galaxy far, far away), Miffy emerged as the next evolutionary step out of these proto-rabbits.
Fig.2: Miffy.
Fig.3: "what is playing now" bush, front. While Miffy performs on stage, the viewers would surely like some indication of which song is currently playing. Hence, this bush; LEDs indicate 1 out of 3 'main' tunes, or an 'intermission'-tune.
Fig.4: "what is playing now" bush, back. Wiring is modest; 4 wires for 4 LEDs, with common kathode.
Fig.5: Coke. When time is a factor and sleep a luxury, Coke is vital.
Fig.6: lightshow-bush, front. Nice LED 'walklight' (what's this called in English?) is displayed here with a few different modes.
Fig.7: lightshow-bush, back. Wiring is slightly less boring, with 4 series-chains of 4 LEDs each.
Fig.8: the board. Not extremely interesting, is it: a relay, an MCU, a transistors for each of the 4 'walklight'-channels, a zener, and a few resistors.
Fig.9: a snug fit. Everything is designed genau wie die Profis as they say in France, to fold together into a box-shape. Electronics is hidden under the 'floor' on which Miffy stands.
Fig.10: action! So ok, victim opens/unfolds the box, presses button, and is amazed. Mission accomplished. Congratulations.

So... WTF?!

As a surprise-gift for some combined events (among which, a birthday), I thought it was fun to make something that involved electronics at least to a minimal extent. It was not until later that I found out that such a thing is called a music-box and is available in the stores - but ok, this would be a customised music-box.

Of course, why prepare while you still have lots of time, if you could wait until deadlines become a factor, and stress yourself? This was no exception; 16 hours to go until I physically had to leave the house and catch bus/train/plane to deliver the result (whatever it would be), so let's go.

Disclaimer

Basically, I don't have time nor mood to answer/respond_to time-wasting /useless comments. E.g...

  • code is not perfect, ...
  • note-frequencies are not perfect, ...
  • my cardboard-skills suck a bit, and...
  • yes, the used tints of spraypaint are way off from what was intended, ...
  • it still smells of spraypaint even now, and of course...
  • electronics are crude, and may hurt the delicate designer's feelings.

So there. Really, I'm a nice guy, but really, get off my back. But constructive comments are of course always welcome! :-)

Oh, and CBA to make a schematics. It's so very simple - all relevant things are explained in normal English below, anyway.

Hard-/software

Faithful workhorse is Atmel ATtiny2313 (2kb flash, 128 bytes RAM) with internal 8 MHz RC-oscillator. Its main task is to play some tunes in a row when a button is pressed, while performing a simple lightshow. The code is available too.

Sound

For sound I used literally what was closest at hand, namely a speaker from a PC within 50cm reach. I think it's connected to a digital out of the MCU, with a 220 ohm (or something) resistor in series. Even googled a bit as to make it nicer a bit, then decided to CBA and leave it at this.

Notes are played by using a timer (I think 8-bit) which toggles the corresponding output pin 'from hardware' (so, no ISR) on counter overflow or reaching TOP (I forgot which - who cares).

After (stupidly) 'trying' to come up with some nice note-frequencies, finally got smart and used an existing note-frequency table. Choose nice timer-prescaler, divide, #define, and sito presto, we are able to play notes. For 'silence' I used the highest frequency possible iirc, so this 'silence' might in fact not be silent for dogs :-)

Then, made some C-functions to do stuff I often needed in tunes, e.g. play 3/4 of a 'tune tick' (god I am so music-unclued, my dad would be ashamed if he read this...), and then 1/4 silence. For more clue, see the source - I tried to find a nice balance between RAM- and flash-use, wallclock-time until I had to sod off, and remaining mental capacity. (In fact I made some basic music-playing stuff earlier already, but some shaving was required to make it all fit after adding the light-thingies - see below).

While the actual notes were generated by hardware (toggle speaker-pin on timer overflow), the actual changing of tones/volume by setting timer-registers was done from the main loop in the code.

You can listen to the tunes (MP3), and see if you can recognise...

  • the Dutch Miffy-tune
  • 'happy birthday'
  • the Pac-Man tune
  • 'gelukkige verjaardag' ('happy birthday', Dutch version)
  • some Johnny Cash song I CBA too look up the title for

Light

What's a good show without some light-effects? Nothing, that's what. There would be 2 light-thingies (although I considered adding a lot of 'always-on' LEDs to make it less gloomy, but no time for that anymore):

I won't even discuss the song-indicator because it's trivial.

The 'walking light' (jeez what's this called in English?) thing was nicely done using 'coroutines', or rather, a bastardisation thereof. Very nice for state-machines, which it was, running from a 10 Hz clock interrupt. I think each 'channel-chain' consisted of 4 LEDs - 1 of each colour - and a 100 ohm resistor in series, turning them on/off using a BC547.

Power supply and control(s)

All is fed using a 9V 'block' battery. I didn't want it to consume any power while 'off', and yet not have a physical 'on/off'-switch but instead a pushbutton; therefore, after trying and failing to get no power consumption using a transistor plus time being a factor, I used a 5V-relay.

Pushing the button would cause the relay to close, thereby feeding the MCU, which would itself assert a pin to activate the relay itself, thereby keeping itself happy. After playing all tunes, the pin goes low, the relay opens, and the show ends. How very simple.

Cardboard-ware

So ok, that's for the playskool-electronics. Now for the cutting/glueing/cursing bit: making a cardboard frame to hold everything, making nice decorations, cutting it into a nice shape, and making it fold together nicely to be carried sensibly. Oh, and spraypainting (as always).

Fold-together box

After searching for a reasonable box that wouldn't require too much mods, and giving up, I took a big box and cut my own DIY-box parts out of it.

The idea was to fit everything into a 15x15x15 cm cube, where, when unfolded/opened, the underside and backside would stay put, the left-, right- and front-side would fold down, revealing lots of glued-on goodies that were on the inside of the box until then.

The backside was meant to be some very basic forest-scenery with Miffy itself, the song-indicator bush, and the lightshow-/congratulations-bush. Reality was slightly different, since the (green) spraypaint was really glossy and much darker than intended. Oh well.

Used a liberal amount of Pritt (or the El-Cheapo version thereof), a set of color-pencils I got earlier, and knife/scissors. Really not that interesting to go into more detail I think; look at the pretty pictures.

The bottom 2cm of the box were another box, that opened towards the underside, and to be used by the developer only, to put in the electronic innards. Used a plastic bag as 'padding material' to prevent stuff from moving around during transport.

I haven't used Pritt (nor El-Cheapo version thereof) since primary school or something. I remember one kid actually eating Pritt (and surviving - I think he's still alive, in fact).

Other stuff

Ah well, apart from the actual box, there are decoration-bushes, a 'Miffy-holder' to keep the poor rabbit in place, holes for the wires to/from the indicator-/lightshow-bushes, and holes for the speaker (it was really silent without those - not weird, considering there was a good 1.5 cm of cardboard between speaker and ear, at first. Pritt is nice. :-)

Painting, drilling, sandpapering etc

Unfortunately there was no sandpapering nor drilling - sorry, pit. If I had to do it over again, I wouldn't use spraypaint; spraypainting cardboard is like spraypainting a sponge. Perhaps some roller + thicker paint would have been much nicer. And so on, and so forth.

Why is spraypaint so expensive btw?

Conclusion

Ok, worked for about 16h straight, then it was 'presentable' (let's call it 'finished') Wrapped the thing in wrapping-paper, made a lid with 'lift cover' to make it auto-unfold upon opening, and done. Gift was very well received, so there :-)


Have fun -- Michai