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.

Comments

  1. jay says:

    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. adam outler says:

    Very cleaver!

  3. Satiagraha says:

    @Adam Outler

    You think so? Why don’t you axe him a question?

  4. Max says:

    That was very interesting, thanks for sharing.

  5. Sprite_tm says:

    @Satiagraha: I like the cut of your jib!

  6. Nate says:

    Rather than take this apart and solder it, I would use a cheap jack so that it can be plugged into any sound card.

  7. rusty says:

    wanna get in on this duel!

  8. Daniel Matthews says:

    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.

  9. James says:

    This is far far from new, even sparkfun makes a board to help matters along:

    http://www.sparkfun.com/products/10331

  10. Phil says:

    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.

  11. lou eney says:

    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

  12. Mike says:

    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.

  13. adam outler says:

    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

  14. Miroslav says:

    Might be useful for specific application. Only problem is max. speed is limited to about 20 kbps (44 kHz sound card sampling rate). Overall a good idea.

  15. D_ says:

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

  16. Scott says:

    @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?

  17. Kevin says:

    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!

  18. password says:

    a simple pabx circuit come to mind

  19. password says:

    this would also be quite usefull if you connect th uC to a mp3 player that has a mic input, to store be able to store more data

  20. mr foo says:

    “Press play on tape”

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

  22. Max says:

    Now the really clever way to do this would be to use a cmedia cm108 based dongle (some others too), it has extra gpios on it which could be used to bit bang a serial interface. Plus you can still use the the rest of the sound dongle at the same time :)

    http://mgrela.rootnode.net/yaesu-usb-rif/

    (not my site)
    -Max

  23. Lupu says:

    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.

  24. jj says:

    @Kevin
    Check the FTDI datasheets again.

    http://www.ftdichip.com/Support/Documents/DataSheets/ICs/DS_FT232R.pdf

    “Integrated level converter on UART and CBUS for interfacing to between +1.8V and +5V logic. True 5V/3.3V/2.8V/1.8V CMOS drive output and TTL input.”

  25. Bojan says:

    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!

  26. svofski says:

    Finally we can ditch this digital serial crap and load firmware like our grandparents did.

  27. Miroslav says:

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

  28. signal7 says:

    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 http://www.aperature.org 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.

  29. cantido says:

    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?

    >>crystals,

    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.

  30. Isotope says:

    http://www.sparkfun.com/products/9717

    they also have a 5v version. Doesn’t get any simpler than this.

  31. defyboy says:
  32. filisoft says:

    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.

  33. Scott says:

    @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

  34. cantido says:

    @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?

  35. signal7 says:

    @scott:

    Note that I said, “if you don’t need usb”. Bearing that in mind:

    http://www.sparkfun.com/products/8780

    SFE charges a lot for this circuit (for what it is). You could buy the components from digikey and prototype it yourself for even less.

  36. AnonymousCoward says:

    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.

  37. Kevin says:

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

  38. hans says:

    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?

  39. Scott says:

    @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

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 96,434 other followers