The commoditised PC is the most versatile tool many of us will own, and since it has been around for a very long time it is also something that can be found for free or very cheaply if the latest components aren’t a concern. It’s not without limitations though, while it’s designed for expansion it no longer has any ports that can easily be repurposed as GPIOs for reading sensors. A solution for some sensors comes courtesy of [Ruslan Nagimov], who shows us how the PC sound card can become a measurement interface.
The idea is that simple resistive or capacitive sensors can be read through their AC characteristics by sending out a sine wave on one channel of the card and reading the result on the other from a divider circuit. He goes extensively into the code, both for the resistive example and for reactive components, and we can see that it forms a handy extension to the PC capabilities.
We’re sure this technique will find applications for some readers, but it interests us for another platform. Measurement using a mobile phone’s audio jack doesn’t have an inspiring history, but perhaps this could be used as well for mobile sensors.
I know the audio from my motherboard’s build-in sound card has a lot of noise in it because it’s placed so closely to the CPU. If this is highly tolerant of noise then this might work but frankly I think this isn’t as good as just connecting an MCU with GPIOs via USB.
The measurement has to be done over multiple wave cycles anyways to get a reliable result because the recorded waveform will shift all over the place before it settles down into a steady state. After all, it’s not DC coupled.
Any time you average together many measurements, the uncorrelated noise gets diminished by a factor of sqrt(n) where n is your number of samples.
This has been used in Ham radio.
Speaking of HAM radio, SAQ Grimeton will transmit today (June 4th).
With a sound card a little interface circuit+antenna and SAQrx application for Win32
it is possible to receive it without a dedicated radio.
https://alexander.n.se/
https://sites.google.com/site/sm6lkm/saqrx/
Thanks for that! Just caught the webcast. No time to sling a wire in the air, but judging by reports it looks like I would not have received it here anyway, especially with the local QRM. Next time…
i like the idea of sending an ac signal to probe the characteristics of the attached circuit. that gets around a lot of the limitations of the sound interface, or even turns them into advantages. but i’m not sure i agree with “it no longer has any ports that can easily be repurposed as GPIOs for reading sensors”. things have changed a great deal but if you’ll pardon my nostalgia…
the old way sure was simple. i used to shove 22awg solid copper wire directly into the DB25 parallel port. i could read/write it directly from DEBUG.EXE, port 278h. truly, couldn’t be simpler. but if you wanted to do a good job, you had to come up with an actual db25 connector (which, when i was a kid, meant waiting potentially weeks to get to go to radio shack), and soldering was also a huge buzzkill for me back then. on top of that, as my projects became more sophisticated i learned that i didn’t really understand the electrical characteristics of the parallel port. i still don’t, though presumably now i could figure it out if i took a serious look at it.
the alternative on those old PCs was rs232. i did use that a lot, even had a pile of 1488s for the +/-12V signalling. not that convenient. and i’ve nothing against asynchronous serial but basically if your microcontroller didn’t have a dedicated async serial peripheral built in, it wasn’t a very friendly thing to try to figure out, compared to SPI/I2C/etc. basically impossible to decode rs232 with just a 74xx shift register. the microcontrollers available were awkward, and if you wanted reprogrammability they were expensive and rare as well. i never found rs232 easy to work with.
today, there’s nothing quite like parallel port…but instead, there’s a hundred different varieties of arduino / stm32 pill / usbpic / raspi, and you can even get cheap usb peripherals like FTDI or audio. you can’t buy any of them at radio shack but you can find just about anything online for $2-$20. gpio galore, with a variety of dedicated serial and adc/dac pins. the gpio is often limited in some way (like 3.3V vs 5V), but it is generally a simple bipolar driver that is easy to understand. a lot of them have pin headers that are easy to wirewrap or ic-clip onto, or plated through hole for easy soldering. in most ways, i find the modern situation much easier to deal with.
my biggest complaint today is that the software situation is much more complicated. there are a ton of different approaches, but i personally always wind up writing separate programs for the microcontroller and the PC side of it, treating the whole device like a dedicated i/o controller. i can usually find something easier than bitbanging usb, but handling the usb connection always requires some forethought. the strength of modern commandline tools can sometimes make it seem easy from the user perspective but there’s definitely nothing as simple as just writing to port 278h. but the flipside is, if you know how to handle all that, it is so much more powerful! an stm32 is comparable to the 286 i started with, and i can invest the whole thing on polling or delay loops and still not block my PC. and it’s definitely not any more expensive.
Can’t say I miss RS-232. Although somehow I never lacked for a DB25 connector, I definitely do not miss resoldering to swap pins 2 and 3 just about 50% of the time, no matter hard I analyzed beforehand. DTE? no, DCE, no, wait, lemme reason this through once again…
I do, it was very reliable for transceiver control. It was better than usb in that you never needed drivers, since everything was a terminal. the late terry a davis of templeos fame once planned out his ideal interface, and it was similar, with every communication being a short text string over terminal.
I do love RS-232 still. It supports connections of about 10 meters and more, you can build/use a passive switch-box with RS-232 connections, RS-232 has protective diodes built-in, so a short isn’t killing it right away, etc. By comparison, USB is just a kid’s toy. The connector itself can’t be screwed onto something, even. Heck, USB connectors don’t even have magnets or a snap mechanisms (newer SATA cables do). In fact, I still design my own stuff with RS-232 in mind first, then make it tolerant with USB-Serial converters (they use TTL or 3.3v levels). :)
pretty sure it’s only newer SATA that don’t have the clip
now someone should engineer a digital protocol that works through the sound port. AC coupled. Maybe Frequency shift key.
btdt. if you don’t mind low bandwidth, it’s laughably trivial…you can just use on/off keying (amplitude shift keying). decode is just diode -> low-pass filter -> amplifier. used a 6kHz carrier, binary amplitude modulated at about 1kbps, to control a PIC12 from an old cellphone. figuring out an RC network that lets 1kHz through but rejects (averages) 6kHz is pretty easy. a good exercise for someone first learning how to use an oscope, and how to trust the T=RC formula (like myself).
if you’re just looking for a trivial interface, that might be enough. obviously you can squeeze a bunch more out of it by being more sophisticated but if you accept that level of complication you might as well speak usb, imo.
In the 90s I built a 7-channel data acquisition device that used the sound card input as input to the computer. It used 7 voltage-frequency converter chips to impose 7 discrete subcarriers in the audio band, each frequency-modulated with the signal of interest (ECG, blood pressure, temperature, G force, and a few other telemetry channels).
The motivation was to send all those signals down a single radio channel, slip ring pair, or cassette tape. A few channels were wideband (hundreds of Hz) and a few were just a few dozen Hz.
Decoding on the PC side was with a sliding-window FFT with 7 frequency estimators, spitting out 7 channels of volts vs time. It worked splendidly.
It’s all well and good until Windows updates fries your sound card driver so that you can have no more sound cards ever again.
TLDR; Windows 10 Update = No sound card. Linux = still working
Windows update didn’t fry your card. Your card’s OEM decided that something hacked up in an afternoon by a relative’s teenager was good enough.
Oh, please! Linux has a horrible history of sound card support! OSS, ALSA, PulseAudio etc. If it works at all, it either has slight timing issues or can’t do full-duplex operation. That reminds me of SuSe 6.x with Kernel 2.1 (?) – once had that on my Pentium 75. Enabling Full-duplex support of my Sound Blaster 16 (Model CT1740) made Linux hang every time. 😰
Reminds me of installing Skywave Linux on the Lenovo X200. Didn’t bother with what I read were the possible work around(s). Figured Ubuntu and Kali were suitable for that Linux distro period.
Has anyone built a small extension card that plugs into a PC’s USB port and exposes some GPIOs?
Every Arduino(ish) board with USB will do.
You can use Firmata as a universal firmware: https://wiki.seeedstudio.com/ODYSSEY-X86J4105-Firmata/
What comes to mind are most MCU’s where you can use the Arduino IDE, unless you’re thinking something else I’m not catching.
Yes, that sounds like what I am looking for. Basically, a low-cost card with physical electrical interfaces I can program using the convenience and power of a PC host.
Disclosure: I have not played with Arduinos before.