# Introduction

I had this nice step motor lying around and searched for a funny way to use it. Then I came across the idea of using a stepper as rotary encoder, a nice idea explained in detail on several sites:

Since I wanted to make this experiment as simple as possible, I thought about using my soundcard as input device. I came up with this really simple circuit:

In short, it just limits the voltage to the soundcard to about +-0.7 Volts. The resistor values shouldn't be critical.

Some pics of the pretty crappy mc-guyverish construction as well as screenshots of the waveforms while turning the knob:

One of the soundfiles I recorded to study the signal: stepper.wav

# The algorithm used to analyze the audio data

This algorithm is implemented in the example python application, see below.

It basically goes like this:

• for both channels, differentiate the input (calculate difference between actual and last sampled value)
• if differentiated value goes above (below) a certain threshold, set (clear) a bit for each channel representing the actual binary state
• feed these two bits (one for each channel) into a fsm. The dse-faq (german) explains the fsm I used.

# A practical application

Now that the basic idea was working, I needed a practical application to use it.

I was a long time fan and listener of websdr. In short, it's a web controllable shortwave receiver (open to anyone, without registration etc.) A real physical tuning knob would be nice, so I started thinking.. The challenge was to remote control a web application without being able to change something on the server side. So I stumbled upon Greasmonkey This Firefox extension allows you to manipulate and access the html/javascript of specific sites. I wrote a Greasemonkey script which periodically fires up a http request to localhost and calls the websdr's javascript function to set the frequency with the passed value. On localhost, the server part of my software (written in python) calculates the actual increments from the soundcard's input and returns them to the Greasemonkey script with a simple build-in web server.

### See a short video of the remote controlled websdr:

If you want to try this out, read below..

## Control websdr with a real knob

### You need:

• a stepper motor connect to the line of your soundcard with above circuit
• the server part of the software: websdr.py
• Python, numpy, PyAudio to run it
• Firefox with the latest Greasmonkey-Extension installed
• My greasemonkey script installed in Firefox (just click this link in Firefox)

### Setup:

• connect circuit to the line input of your soundcard
• set line input to the default input in your mixer application
• adjust the record volume just below peaking while turning the dial
• run the server side script: python websdr.py (-h gives more options)
• point Firefox to websdr
• ???
• PROFIT!!!111

### NOTES:

known bugs: The Greasemonkey script _should_ add a custom menu to Firefox (allows setting of the host/port where the server part runs), but it doesn't..

UPDATE: With Greasemonkey 0.8.20091209.4 on Firefox 3.6 (Ubuntu 9.10) the menu DOES appear, it seems that MY Greasemonkey setup was broken. (Thanks for the feedback, David!)

This software is far from being perfect, any fixes/additions are welcome.