Playing A WAV File With 64 Bytes Of RAM


[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.

37 thoughts on “Playing A WAV File With 64 Bytes Of RAM

  1. 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?

      1. 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

      1. Wow, I was so wrong. I guessed that it would be hard because the SD “sector” is 512 bytes, so you would have to parse everyting (file tables and cluster data) as soon as you get it. I suppose that it does multiple reads to the sectors, each time reading the information it needs and not storing everything else.

    1. Some (maybe all?) eeprom memories have a command that simply reads the next bytr, so you might not need to count the address. And a timer can be used to know when to stop. Of course, it’s rather limited for the door bell application…

  3. 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.

    1. 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.

    2. 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.

      1. 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.

      2. 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.

        1. 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)

    3. “[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.

    4. 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. 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. 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.

  6. 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.

    1. OMG, your info is rather outdated.
      Compilers cost zero. 16 and 32 bit PICs have GCC compiler, just download it from Microchip. Or take look at for PIC32 compiler. For 8-bits, there is relabeled free, code unlimited version of hi-tech.
      PicKit3 debuggers costs 35USD or so. It supports all 8, 16 and 32bit PIC devices. That 35USD is cost for complete semi-professional development suite.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.