Bit crushing, rate reducing, weird noises: DIY 10-bit effects/guitar pedal with an Arduino for lo-fi DSP.
Check out the demo video on Vimeo.
Step 1: Materials
Step 2: Preparing the Enclosure
I used a "fast ethernet media converter" for my enclosure. It's just a box that happens to fit the Arduino, some interface elements, and two audio jacks. It's pretty sturdy metal, which is important for a pedal. As an added bonus: it has a hinge on the back, which makes it easy to open and close.
The only modifications I had to make to this enclosure were some holes for the three pots (using a drill press) and cutting out some plastic for the USB connector.
Step 3: Connecting the Components
Once the enclosure is prepared:
Step 4: Normalize the Input and Output
This is the only real "trick" when it comes to the hardware for this system. Audio happens as an AC signal from -1 V to +1 V, but the analog inputs on the Arduino run from 0 V (Ground) to some positive voltage called the analog reference (5 V by default). You can specify this positive voltage in code or with an external reference.
Since -1 V to +1 V is a 2 V range, we'll choose something smaller than 2 V for our analog reference value. It turns out 1.1 V is specified as a built in internal reference, which works out nicely.
From here we have to normalize the -1 V to +1 V as 0 V to 1.1 V. I did this using a resistor in series followed by a voltage divider circuit. A guitar cannot directly drive this circuit, it needs a preamp (like another pedal) to drive it. I'm sure you could add a transistor or op-amp preamp to the perf board so you could plug into the pedal directly.
For the output, we're going to be using PWM. With some low level hacks in software, you can get an 8-bit PWM running at 62kHz = 16 MHz / 28
There are some other methods for audio output on the Arduino. A good overview can be found at uC hobby. I got some great results from an R2R DAC, but considering it needs around 40 resistors for 10-bit stereo output, I decided against it. Instead I went with the weighted pins technique, which is kind of like a cross between standard PWM and a resistor ladder.
Building the Circuit
I built two of each circuit on one perf board. I had a ground strip down the center that helped for arranging things as neatly as possible. The first time I built the circuit, it was too tall and didn't fit in the enclosure, so I had to build it again.
When you have capacitors in series like this, they will cut off some of your low frequencies. WIth a 2.2 uF capacitor, it's low enough so it doesn't really affect sounds in our hearing range. The larger the value, the better; but capacitors tend to get physically larger as their value increases.
Step 5: Connect Remaining Components
Once your input and output circuits are made on your perf board, place it inside and start attaching all the wires that have yet to be attached.
Step 6: Upload DSP Code
Download the code and you'll find two folders. One is the basic DSP code, "ArduinoDSP", that you can use to make your own pedal. "GlitchPedal" is the one I used for this specific setup. At some point, Vimeo removed the per-group file hosting I was using to host the code. For better reference, see this code from Tony Ivanov or follow Randy's Instructable instead.
The includes in ArduinoDSP are useful for setting the proper PWM prescaling and analog input prescaling values. They turn pins 3 and 11 into the left outputs (8 and 2 bits respectively) and 5 and 6 into the right outputs, using Fast PWM settings with no prescaling so the PWM is as fast as possible. The ADC is also set to a low prescale value, 32, and the analog reference is set to 1.1 V (the internal reference).
To modify the basic ArduinoDSP code, just insert your own code to modify the variable "input" between the line "short input = analogRead(left);" and "output(left, input);".
The code I've already written does a few things. The LEDs provide visual feedback about the knob positions and input level, and the pots control settings for the DSP happening inside the microcontroller. The first pot controls the mode, the second controls a parameter of that mode, and the third controls an effective sample rate. The modes include: