Sound Card Microcontroller/PC Communication

The usual way send data from a microcontroller is either over RS-232 with MAX232 serial ICs, crystals, and a relatively ancient computer, or by bit-banging the USB protocol and worrying about driver issues. Not content with these solutions, [Scott] came up with sound card μC/PC communication that doesn’t require any extra components.

[Scott] bought a cheap USB sound card dongle on eBay (although a built-in sound card will do) and wired up the tip and ring of the plug to the microcontroller. The data is sent from the microcontroller a lot like Morse code – a short gap between pulses is a zero, a long gap is a one. This is parsed by a Python script using PyAudio. Synchronization, timing, and calibration is automatic because of a 10-bit ‘packet header’ explained in this video.

After he had a really great way of sending data from a microcontroller to a PC, [Scott] asked himself if it would be possible to have bidirectional communication. Using the same sound card setup, he managed to get bidirectional communication off an ATtiny44a. You can see his demo video of this here.

The cleverness of hack is overwhelming, and we’re kind of amazed that this technique isn’t in the standard repertoire of solder monkeys. After looking at this, we’re tempted to throw out the half-dozen USB/RS-232 adapters we have lying around. They never worked anyway. Check out [Scott]’s highly informative video of his build below.


40 thoughts on “Sound Card Microcontroller/PC Communication

  1. i figured the usual way these days was for your arduino to send it’s data back over the ftdi usb link?

    more seriously, you could probably crack open one of your cheap usb/rs-232 adapters, strip out the level converter they attached to an ftdi chip and then just have an ftdi cable.

  2. You should be able to combine this USB audio hack with the transistor and crystal hack, plus a simple receiver circuit to create a two way data over FM radio link.

  3. Why hack the sound card? Why not just use a cable with the proper plug on the end. Any old pair of headphones will do.

    It seems like in his effort to replace serial with something simpler, he’s come up with something much more complex. The only advantage is price.

  4. im a geologist. I do not understand the usefulness of this hack. You people need to understand that in life sometimes time is better wasted on other things, like geologists understand well. get a life. get a real useful hack. peace and long live the earth and mother nature.

    – heady brosevelt

  5. If you were to solder the connections behind the input/output capacitors, you’d be able to get proper DC-coupled digital signals in and out of the USB sound card.

    The capacitors are quite easy to identify.

  6. I bet for the other side, it involves a rectifier, a capacitor, and either a linux audio device for proper control, or prerecorded sounds which will be turned into much lower frequencies by the rectifier and capacitor….. just a guess

  7. Price was a criteria he mentioned several times. probably important for a future doctor that may be some time from their first good payday. No doubt at at 6x the cost of this solution the sparkfun product would have been rejected as well. In that amateur radio operators have been using computer sound cards as 1200 baud RF modems for years, this should be plenty fast enough. When you are the only one quite a bit of data can be passed at 1200 over the course of a day. Yea a patch cord would be my first choice, but if the best your junk box has to offer is bell wire..

  8. @jay – I’ve opened-up some of those rubber-coated USB/serial adapters. The chips are HIN211EIA (level converter) and PL-2303 (USB/serial controller). Purchasing each is a little pricey, but doable – if my microcontroller had rs232 capability!

    @nate & @phil – Yeah a simple headphone cable could interface a PC sound card, but I figured if I wire something wrong I’d rather blow up a $1 sound card than my motherboard’s integrated sound controller!

    @james – thanks for sharing! That’s news to me. It looks a little complicated in the link, and wow that’s $$$ for what it is, but still cool.

    @mike – The capacitors are only used for the output, a SMT series capacitor is used for the input. Although I’ve tried this, I don’t feel right requiring newbies to de-solder SMT components, but you’re certainly thinking in the right direction. Tight control over voltage allows a whole new level of control and speed to the data transfer process!

    @Miroslav – This transfers a few hundred bytes in the blink of an eye. Anything faster would obviously warrant USB or something fancier. This is intended for small chunks of data. I wonder though, would sampling right and left channels at 192,000 Hz with 256 levels of amplitude (8-bit) resolution allow for 98.3 million bits of data to be transferred per second?

  9. I just wish there was a company that made a TTL -> USB serial chip in one package, instead of TTL -> MAX232 -> FTDI. That would be much simpler, 1 chip, no level conversion, etc…

    Perhaps this chip already exists, if so, please enlighten!

  10. hahaha. now *this* is cool.

    Someone hacking together a flash drive inside a tape for your PC which in combination with any old cheap tape recorder emulates a Commodore 16/Speccy tape drive in 3..2..1… Pwned.
    I love the sound of tapes spinning in the morning… :) :) Anyone for a nostalgia trip?

    Actually I looked into using my Creative Zen for ambulatory multichannel EEG monitoring via LM567 based sound input as it has dual mic inputs.
    Sadly it is no more, it is demised. I gave it away to a friend “just to see if he could fix it” but methinks it is a brick as the FW recovery fails and it won’t even charge any more :-(

    Cheap Bluetooth headsets also work well. I actually got as far as getting a reliable on/off switch via LM567 detected tone before finding that it was prone to RF interference.

  11. I watched the video with curiosity for why he used an external USB sound card and soldered the uC to the connectors directly instead of soldering a standard jack to the uC cables and used the integrated sound card. It would be transferable to any sound device.
    I’ve previously used a similar hack to talk with an N900. It uses the 4-conductor jack variant as both stereo output and mono input are in the same connector. Additionally, a specific resistance needs to be used on the mic conductor before the N900 detects the inserted “headphones” as a microphone equipped set.

  12. PIC18F13K50 is about one dollar with full speed USB2.0

    I don’t like when hi say “…but I’m just a dentist” while trying to teach others.

    Also, MAX232N is about 30 to 50 cents, not 5 dollars he say!

  13. @Scott: I was wrong/unclear. At 44 kHz sampling rate you could maybe transfer up to 44 kiloBytesPerSecond. If you can force your card to sample 192 000 times per second, and each sample is 1 byte, you may be able to reach about 192 kiloBytesPerSecond.
    All in all a useful hack that could work with broad range of computer architectures.

  14. Doesn’t seem all that useful. If you really need serial and you don’t have a uart, bit-bang serial in software is *not* that hard. I did it as an after-thought when using an attiny24 in a project and it only took a couple of hours to figure out. Even better, you can steal my code from for free!

    Level shifting isn’t the big problem he says it is. You only need a level shifter when talking to a PC, and even then you only need one level shifter per RS-232 port and computer you own. Buying a level shifter for every project is the wrong way to go. I have only one FT-232RL breakout for all of my projects. The level shifter is part of the PC – not the project. Even so, there are some alternatives out there that are much cheaper than the FT-223RL, especially if you aren’t in need of USB.

  15. Do you guys have a technical editor or anything?

    >>The usual way send data from
    >>a microcontroller is either over RS-232
    >>with MAX232 serial ICs

    Is it? really? What about i2c, can, spi etc?


    Since when did a max232 or any of its clones need a crystal?

    >>bit-banging the USB protocol

    Why do you need to do that? USB to UART chips exist and are cheap… you can get the CP21xx chips on a board ready to go for a few dollars. Probably cheaper than the USB sound card he used..

    While this is neat and cool .. the copy hackaday comes up with to make out that things like this are somehow useful or a must have for “our” projects are bizarre to say the least.

  16. Soooo this “new” thing goes back 30 years in time. Great! He should set up a BBS now. (I wonder how many people know what a BBS is these days…)
    If you still mess with the drivers, at least mess with the drivers from a usb->serial adaptor instead of the drivers from a usb sound card. Then you’ll have a more normal protocol that doesn’t need any software to be written.

  17. @signal7 – What alternatives are cheaper than the FT-223RL? Alternatives are exactly what I’m seeking!

    @cantido – It was implied I was referring to “from a microcontroller to a computer”. Also, clock rate is critical to error rate when using a level converter to connect a MCU to a PC via serial port. I’ll look into CP21xx! Is it DIP and bread-boardable? USB sound card is $1.30 shipped.

    @Isotope – lol, I can’t justify buying a $17.95 cable (plus shipping?) to send a few numbers from a $1 microchip to my computer.

    @defyboy – that’s a cool product! Is it supported for Linux and windows XP, Vista, and 7? Oops, the page says “Drivers don’t seem to work on Windows 7”

    @filisoft – next cutting-edge step will be to design an “audio modem” to allow data to be communicated over a phone line to bring back the dialup BBS

  18. @Scott

    >>“from a microcontroller to a computer”.

    The common way of doing that is a UART.. thats what its made for.

    >Also, clock rate is critical to error rate

    But your clock is close enough to time pulses coming out your USB sound card?

    >>when using a level converter to connect
    >>a MCU to a PC via serial port.

    Level converter doesnt make a difference. Baud rate does.. if your clock is pretty far off or unstable use a low baud rate so that it doesnt matter. Again.. your clock is good enough to time pulses, so my guess is its good enough to run a UART at 9600 baud.

    >I’ll look into CP21xx! Is it DIP
    >and bread boardable?

    Yes, its a 5 or 6 pin male header… as a bonus the pins are 5v tolerant so one board can be used with both 3.3v and 5v systems. Even if the USB->UART bridge is $4 .. how much time have you wasted coming up with this? less than $4 worth of time?

  19. BTW, this chip uses the CMedia CM108/119 chip made for VoIP telephones and stuff. It technically has I2C as well as 8 GPIO pins. You could probably just write a drive in libusb to make use of it.

  20. @jj: Thanks for the tip! I think I looked at that chip before when looking at options for micro controller pc communication w/o serial ports, but didn’t like the packaging (I prefer breadboardability, though I suppose I could bend the pins and dead-bug it). Not terribly cheap either, especially if you want/need the breakout board from SparkFun.

  21. I don’t get the article. Why do they claim that (their) USB/RS232 adapter don’t work? Did they bought shitty quality? I mean hardware hackers use these adapters (either sold as this or modified mobile phone data cables) all the times and they usually don’t have problems. Are idiots at work here?

  22. @hans – “Are idiots at work here?” Quite possible! While I agree “they usually don’t have problems”, the small lot of USB serial adapter dongles I purchased are quite a problem. They’re some no-brand Chinese things not supported on Linux or Windows 7 (my fault for buying them), and I was too discouraged to go back online and pay (and wait) for a replacement. Again, I just wanted a few numbers from my microchip to my PC, and this zero-component solution was a pretty solid way to make that happen with the parts I had on hand.

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.