Playing a WAV file with 64 bytes of RAM

montage-final

[Jacques] thought his doorbell was too loud, so of course the first thing that came to mind was replacing the electronics and playing a WAV file of his choosing every time someone came knocking. What he ended up with is a very neat circuit: he used a six-pin microcontroller with 64 bytes of RAM to play an audio file. (French, Google translation)

The microcontroller in question is a PIC10F322. one of the tiniest PICs around with enough Flash for 512 instructions, 64 bytes of RAM, and a whole bunch of other features that shouldn’t fit into a package as small as a mote of dust. Without the space to store audio data on the microcontroller, [Jacques] turned to a 64 kilobyte I2C EEPROM. The PIC communicates with the EEPROM with just two pins, allowing it to read the audio data and spit it out again via PWM to an amplifier. The code required for this feat is only 253 instructions and uses just a few bytes of RAM; an impressive display of what a very small microcontroller can do.

Comments

  1. Bogdan says:

    The title is misleading… You need way less than 64B of RAM to make it work.
    In fact, i think it can even be reduced to 2-3B.
    Its really cool to have customizable doorbells…
    Im surprised there are no commercial products that accept an sd card with a wave file… Or are there?

    • cde says:

      For doorbells, specifically? No. Welll…. Mp3 doorbells yes, for like 40 to 50 bucks on amazon. But there are mp3 sound modules for “”arduino”” on ebay for a few bucks.

      • Matthew Rogan says:

        I had about 128 and I still used tiny little fraction of that when I got a wav from a SD going from a MSP430 project that got featured on here. I was the read from an SD cart with FAT16 one.

  2. Indeed, I think that with 2 bytes of ram you could index up to 65k samples, so at 8khz it can play audio up to 8 seconds. Maybe a couple of extra bytes to remember I2C state.

    The real hack would be to do it from an SD card with a FAT filesystem with an MCU with less than 512 bytes of ram. Probably impossible :P

  3. fartface says:

    No surprise here. Most of us that graduated past the Arduino and it’s bloated carcass have used Microchip Pics to do stuff like this.

    Honestly, want to do really cool things, study this guy’s project and stop using arduinos.

    Stop relying on everything else to do your work and write your own code instead of re-suing everyone elses libraries. You end up with the ability to do cool things with the tiny pics out there.

    • SavannahLion says:

      I do that anyways with the AVR. First thing I do is dump the damn Arduino junk and if I need a (which is rare for me so far) bootloader, I drop in the stock bootloader and go about my day.

    • John says:

      Absolutely. It’s very gratifying to do a project with the right micro instead of overkilling it with an arduino (or any of the dip avrs that the hobbyists tend to use, for that matter). I also find that there’s much more support available for the pics out there on forums and in the industry.

      • davidcdean says:

        The Arduino might be fishing with dynamite, but it does exactly what it’s supposed to do… make things that work, quickly and easily. Sometimes that gets people interested. Then maybe they work with the chips without the arduino prototyping boards, then maybe they start using them without the libraries and such, and then maybe they use more discreet components and lesser ic’s. But if all a person cares about is getting fish in the boat, there’s no harm in that.

      • SavannahLion says:

        Define, “right micro” though… I’ve got 65XX series, a few ARMs, a few AVR’s and I’m looking into grabbing a couple of 8051’s and I was just recommended by a well schooled developer to grab another similar purpose board that leverages the ARM instead. I’m also seriously considering adding a couple of CPLD/FPGA to my toolbox but the damn dev software is massive and yadda yadda yadda….. I’m not bragging about my collection though.

        Short of writing something for a well defined or predetermined platform (like an existing game console for example) I find that the core itself seems to have little bearing on the project itself. Rather I find that the chosen uC seems to be chosen either because it’s something the developer/manufacturer is immediately comfortable with or the uC is wrapped with something that supports a specific feature. And in nearly every hobbyist design choice, the former almost always supersedes the later.

        Point is at the hobby level, there is rarely a “right micro” for the job. On one project, I originally started with a ATmega32U4 but switched to the ATmega328P. I probably could have easily opted to switch to a PIC given the specifications, but I did not choose to because I already had my code (in ASM, not Crapduino) mostly fleshed out. Would I have considered a PIC or a different platform? Sure. It just ended up being with what I have on hand or thought I could easily build.

        I just find that crapping on the AVR because it’s the “wrong micro” doesn’t really make a whole lot of sense when most projects can easily be served by nearly any choice of uC.

        Now, if you just want to crap on Arduino, go ahead. I don’t particularly care for the platform myself. It serves its role, but it isn’t necessarily my “go to” of choice and I personally think it’s a bit of a disservice to the hobby industry in the long run.

        • hateyoucantrust says:

          Awesome, cool to see someone else interested in using 8051 based MCUs, don’t see them used very much. I’m a huge fan of the Silicon Labs 8051 MCUs (formerly Cygnal), they have some really nice hardware add-ons and high performance (48 MIPS, 64kB flash, 4kB RAM, integrated USB engine in some models, nice analog stuff)

    • svofski says:

      How leaving the Arduino crap behind is related to using PICs? You’re doing it wrong.

    • James says:

      “write your own code instead of re-suing everyone else’s libraries”

      You have a pretty serious case of not-invented-here syndrome, you should get that looked at.

    • wowme@wtf.com says:

      “[fartface] Stop relying on everything else to do your work and write your own code instead of re-suing everyone elses libraries.”

      YUP! I’ve always HATED reusable code, too ;P
      I love re-inventing the wheel for EVERY project.

    • Blue Footed Booby says:

      Gratifying? Absolutely. Enlightening? Most def. But if you think reinventing the wheel, axle, monobody, and duct tape for every project is ever going to achieve great things, you’re literally insane. Even geniuses benefit from standing on the shoulders of giants.

  4. R:Pi says:

    I did something like that.. but used a Raspberry Pi. $35 .. attach a usb amp and if you want an internet (so you can change the tunes from anywhere.. and vola.. It is overkill but the cost was right..

  5. Tom says:

    This is the exact reason why people are complaining when an Arduino is used for a blinking LED.

  6. jacques says:

    Personnally I have nothing agains Adruino, each one has is playground. First it is not every one who is incline to read datasheet, (I didn’t bitbang this i2c interface looking at blue sky) but personnally I prefer to read that than licence agreement. Adruino is great for thoses who don’t feel the needs to know at the very low level detail. Secondly it would have been a costly overkill to use an Arduino board for my doorbell project. But if for some project I would think it is appropriate I would’nt be ashamed to use it.

  7. Topsy says:

    I wonder how loud it is?

  8. Topsy says:

    Sorry for double post.. What about a simple audio codec to compress the data so it can be stored in flash?

  9. jpipesup says:

    I’ve been using PIC’s for a long time, and I have to say, the Arduino toolchain is so much better and cheaper than that available for the PICs. Debugging tools cost 100’s of dollars (I bought an ICD2 back in the day) compared to arduino’s breakpoints via serial port.

    The arduino toolchain is also great, PIC doesn’t have a GCC capable build that I’ve ever managed to find. If someone knows how to do it on PIC, I’d love to hear it.

Leave a Reply

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 91,915 other followers