Running 3-wire fans on 4-wire PWM

New motherboards have 4-pin fan connectors that accept a 3-wire or 4-wire plug. The fourth wire is for speed control, a nice feature if you’re trying to quiet things down. But what to do when you can’t find any 4-wire heatsink/fans to fit your CPU?

My computer uses a pair of Dynatron A86G 2U server heatsinks with 50mm fans. These do an excellent job of keeping the CPUs cool, but are extremely loud at normal temperatures, and of course the fans are 3-wire types. It turns out, most 2 and 3 wire fans can be speed controlled by applying PWM to the power supply. The disadvantage is that the tachometer signal’s accuracy can be degraded by this approach.

I built a small adapter to try this out. It uses a couple of transistors to switch the power based on the motherboard’s output. These are needed to keep from damaging the motherboard as its the maximum voltage it can switch is around 3 volts. In this circuit it will never see more than about 1.4V.

A schematic of a PWM level shifting circuit

When the PWM signal is pulled to ground by the motherboard, the transistors are driven into cutoff, momentarily interrupting power to the fan. This reduces its speed, but may also interrupt the tachometer signal, resulting in errors in the measured speed. However, a stalled fan (0 RPM) is still correctly detected.

SSH smartcard authentication

A few months ago I picked up a GnuPG smartcard (available from Kernel Concepts) with the intention of using it for SSH authentication. Today I finally got around to making it work! Here’s how I did it on my Debian laptop.

First, install a few packages: sudo apt-get install pcscd gnupg-agent scdaemon. Run gpg --card-status to make sure it sees your card. gpg --card-edit will drop you into a shell where the card can be initialized. Type admin at the prompt to enter administrative mode, then generate to generate some RSA keys. It’s recommended to back up the private key to an encrypted file in case the card is ever lost or destroyed. Once that’s done, use the passwd command to change the card’s default PINs.

Now a couple configuration files need to be edited. Edit ~/gnupg/gpg.conf and uncomment the use-agent line. Add a line enable-ssh-support to ~/gnupg/gpg-agent.conf (create this file if it isn’t already there). Restart your X session, then run ssh-add -L. If all the magic is working properly, the card’s SSH key should be printed in your terminal.

Paste this key into the authorized_keys file everywhere you want to log in, just like any other SSH public key. Now, the first time you make a SSH connection after plugging in the card, you’ll be asked for the card PIN; additional connections Just Work(tm).

On Copyright

There’s been a lot of talk about copyright lately. For whatever small amount it was worth, I joined the SOPA blackout and wrote to my senators and representative, although given today’s events I’m not sure any of this was very convincing. I want to know when copyright became a trump card that allowed the copyright industries to interfere with anything and everything. Patrick Leahy claims that losses due to piracy are close to $250 billion. This is nearly 1/40 of household income in the United States, and roughly 14 times Microsoft’s 2010 profit. Since these numbers do not stand up to even the most cursory fact checking, they should not be used to justify Draconian enforcement measures.

Anyone who provides web hosting, file uploading, or even e-mail service is providing a tool for moving data, and the percentage of users who use the service in an unlawful way cannot be reduced to zero. Ever. This is simple probability. This should be considered no differently than any other tool. If a bill were to be introduced to Congress tomorrow suggesting that manufacturers of vehicles should be shut down and have their assets seized because some tiny number of motorists use their cars to rob banks, it’d be laughed out of committee. If by some miracle it didn’t, we’d all have to start riding horses, or bicycles. All that would be gained would be a pervasive odor of horse dung. By the same analogy, if hammer manufacturers were to be shut down on account of hammers being used in vandalism, I suppose we’d all be pounding nails with our foreheads. At least in that case, the brain damage might make us too stupid to care.

Putting aside the SOPA/PIPA/seizure debacle for a moment, the term of copyright needs to be revisited. The “creative” industries have no reason to be creative when copyright lasts as long as it does today. After all, where’s the incentive to try out a new concept when you can just rehash the same old ideas over and over again? Because old works effectively never enter the public domain, entertainment firms don’t have to compete with their own past. Therefore, we get lots of variations on successful themes, and little that’s truly original.

Everyone seems to have forgotten that copyright is a bargain we make. As a society, we choose to respect copyrights (and patents) as an incentive for people not to keep things to themselves forever. Without them, the incentive for creativity and invention would be diminished. However, the copyright holders currently aren’t holding up their end of the bargain, and the prevalence of copyright infringement can be seen as an indication that people don’t think they’re getting their fair shake anymore. Think about this: in what other industry can you do all the hard work once, then continue to turn a profit off it for a hundred years or more?

I create copyrighted software, circuit board layouts, photographs, whatever. Some of that is my livelihood, some of it just for fun. But in any case, in twenty years or so that stuff won’t even be worth paying me for. If I haven’t moved on to something better by then I’m doing it wrong. I respect the work of the truly creative (who end up signing away their copyrights to someone else), but Hollywood fat cats who want mailbox money for the rest of their lives should get their grubby fingers off our Internet, which sooner or later will cut them out of the picture.

P.S. I don’t pirate, and neither should you.

CC430 breakout board design available

I’ve finished laying out a tiny breakout board for Texas Instruments’ CC430F513x line of wireless microcontrollers. This board, about 1.5 square inches in size, can be populated with the following items:

  • QFN48 footprint for CC430F5133/F5135/F5137 microcontroller
  • 18-pin header for power input and fully-remappable I/O ports 1 and 2
  • Integrated 433MHz balun
  • SMA antenna connector
  • 26MHz crystal for radio
  • 32kHz crystal for use with CC430′s onboard timers
  • RGB LED connected to port 3 pins
  • 2-wire JTAG / bootloader / serial connection header (5 pins)
  • Reset button

That is to say, everything one would need to get a CC430 wireless application up and running. In the coming weeks I’m going to try to get a couple of these up and running and compile an accurate bill of materials; meanwhile, the untested design is freely available and editable using gEDA‘s gschem and PCB. If anyone’s interested in getting in on the pilot production run, feel free to leave a comment…

Adventures in network audio streaming

Wireless routers are wonderful devices. For under $50, you get an embedded Linux system with at least a network port (or five), and maybe one or two serial ports. Lately, more and more routers have also included USB ports, which opens up a whole range of possibilities, like cheap IP cameras (but that’s for another day) or NAS devices.

Today’s story starts a month or so ago, when my mom was blaring iTunes across the house, from her computer speakers, so she could hear her music in the kitchen. The radios in the two adjacent rooms worked well enough, but I hadn’t thought to put in audio tie lines to computer locations when I pulled CAT 5. Whoops. I decided that fixing this would make a good Christmas gift.

Previously, I had installed an Asus WL-520gU wireless router (with the aforementioned USB port) in the basement under the living room, where one radio was installed. Years ago, we’d run a tie line to the bigger stereo across the house so the radio could play back CD music. (Apparently, CD players were expensive back then.)  This tie line happened to run right by the router’s location, so I could avoid pulling new cable through the walls.

I picked up a Turtle Beach Audio Advantage Micro 2 USB adapter for a modest sum from Newegg, and compiled OpenWRT trunk for the router, making sure to include inetd, alsa-utils, and the relevant kernel modules. I’d like to say that this went without a hitch; while most problems were easy to solve, things didn’t go 100% smoothly. First, the aplay program wouldn’t run because the build system didn’t recognize that it depended on librt being installed. The router also got very angry at OpenWRT’s default choice of microcode for the wireless adapter. This was easy enough to fix once I knew what the problem was, but the only symptom was mysterious crashes whenever WiFi was turned on. (Reading all the way to the end of the OpenWRT wiki page the first time around might have saved me the headache…) Considering that OpenWRT got me from zero to a mostly-working, custom-built flash image in about half an hour, these complaints seem minor.

On the Mac side of things, I knew that Soundflower would allow looping the audio from iTunes back to another process where it could be recorded; from there, getting it to the router was straightforward.

On the router, I created an inetd.conf like this, and a corresponding /etc/services entry, to take in raw 44.1kHz PCM data on TCP port 12347:

audio-stream    stream    tcp    nowait    root    /usr/bin/aplay    aplay -D front:CARD=Device,DEV=0 -r 44100 -c 2 -f s16_le

On the Mac, I used MacPorts to install esound, then did:

esd &
esdrec | nc 12347

from a terminal window. Route sound output to Soundflower instead of the onboard speaker, fire up iTunes and away I go? Not so fast, my left channel has nothing on it! Fired up alsamixer on the router and everything looked fine, so I plugged the USB dongle into my laptop. Same problem there, but it went away after I bumped the levels up and down a bit in alsamixer and added that “-D xxx” switch to aplay. Not sure why this was a problem but at least the fix was easy. Wrap up the shell commands in something easily clickable, and it’s good to go, networked iTunes streaming without having to buy an AirPort Express (or make it play nice with the existing network…)