An idea that came up during the 31C3. The guys from VisualPhi had some motion sensors lying around and wanted to use them to control their VJ-software. That’s why I built them a Motion-Sensor-to-MIDI-Converter.

As usual it all starts on a breadboard. Most of the times I draw the schematics parallel to building the circuit on a breadboard. Guess that’s the usual way.

The circuit itself is rather unspectacular. 8 inputs are polled from a 74HC165. Then there’s a little bit of logic implemented within an Arduino and then there’s 16 LEDs, a rotary encoder and MIDI out.

This project is the first one to benefit from my new 3D Printer. Due to the fact that I don’t have a dedicated toolshed anymore it’s kind of impossible to reliably manufacture the case anymore. Seems as if I don’t need one from now on.

I really think the fixation of the rotary encoder is one of the smartest pieces ever done by mankind. Ever =)

The LEDs are driven via Charlieplexing. It’s rather easy to implement but you really need to concentrate while soldering. By the way: If everything else fails I guess I’ll become a Soldering-Artist one day.

The function of the device is easy to explain. Every input is triggered when the state of a connected switch changes. This is indicated by the red LED below the channel. The green LEDs indicate the channel that’s influenced by the rotary enoder: The encoder gives the possibility to set the time that has to pass from the moment the input is triggered until it can be retriggered again. Something like a ‘Retrigger Threshold’. The value can be set to values between 0 and ~2 seconds. When the lower / upper limit of the value is reached the green LED flashes. Pressing the rotary encoder (it has a built-in switch) switches to the next input.

Or: Creating an audio-signal with an Arduino, feeding it into a mixing desk, altering the frequencies via the mixer’s eq and analyzing the processed audio with another Arduino which then turns it into a MIDI-signal. Yes, that is Digital-to-Analog-to-Digital-to-Analog-to-Digital-conversion. Phew!

Here’s a picture of the setup:

On the left side there is a circuit consisting of an Arduino and an Attiny85. The Arduino creates a low-frequency ( ‘bass’ ) sine-shaped tone which perfectly sits in the frequency range of the mixer’s bass-EQ. I did some testing here to find the perfect frequency. Testing means: Using Ableton Live to create a white noise, feed this into the mixer, feed the mixer’s output back into Ableton and use the Spectrum-tool to see which frequency gets most influenced by the bass-EQ (C2, that is).

Creating a somewhat true sine needs some effort since the Arduino’s analog outputs only do PWM which isn’t very useful when talking about low-frequency audio signals. PWM basically creates a square-wave signal with a certain pulse-pause relation. While this might be okay for dimming an LED, this becomes quite unusable when dealing with audio because you can simply hear that it’s no sine – the lower the frequency the more the signal turns into some sort of ‘click’-noise. No wonder, the bass-EQ doesn’t influence this to any convience.

That’s why I used this solution to make the Arduino spit out something that’s a little more sinewave-like. I ommitted the circuit as you may see on the picture below. I didn’t have the necessary parts lying around and it worked nevertheless.

The Attiny85 is used to create the second tone. It’s a simple PWM signal at 480 Hz. This time the PWM-nature of the signal can be used for our benefits: A square-wave signal has a recognizable amount of harmonics. You don’t hear one but (at least) two tones. Perfect for us because the mixer I used perfectly influences (well … “perfectly” ) the signals with its mid- and hi-EQs.

The code for the Attiny85 looks like this:

void setup(){
pinMode(3, OUTPUT);
}

void loop(){
buzz(3,480,100);
}

void buzz(int targetPin, long frequency, long length) {
long delayValue = 1000000/frequency/2; // calculate the delay value between transitions
long numCycles = frequency * length/ 1000; // calculate the number of cycles for proper timing
for (long i=0; i < numCycles; i++){ // for the calculated length of time…
digitalWrite(targetPin,HIGH); // write the buzzer pin high to push out the diaphram
delayMicroseconds(delayValue); // wait for the calculated delay value
digitalWrite(targetPin,LOW); // write the buzzer pin low to pull back the diaphram
delayMicroseconds(delayValue); // wait again or the calculated delay value
}
}

the two microcontroller’s output signals are fed into a 7408 (Quad AND) and then sent out into the analog world by a circuit I found over at the MunichMakerLab. This is my first audio-circuit with an Arduino. it’s probably spine-crawling for those who do this on a more professional base but I was getting the best results with this circuit.

[Edit] As someone pointed out in the comments section for this post on Hackaday this might read like I didn’t know at all what I am doing here or that it’s all just a big coincidence. This is not correct. The AND gate protects the audio sources from interfering with each other for a certain amount. I tested that, it simply sounds cleaner. At least I had a certain intention when I added the gates to the circuit (…not that I completely remember….). Looking at the circuit I am still wandering about _why_ but that’s one of the things that I file as ‘Audio things’ for now. [/Edit]

The signal is fed into the mixer and from the mixer sent to another Arduino which does the processing. the circuit looks like this:

To be honest: I cannot really remember where I got this circuit from. Somehow all the solutions I found while trying to find the circuit again look a little different. Again this might be spine.crawling for some of you but… it’s a fun project and it works. The code for the realtime audio-analysis is based on the FHT library by openmusiclabs and expands an example I found over at dontquityourdayjob.

/**********************************************************************************
Loop – includes initialization function and the full loop
**********************************************************************************/
const int NUMREADINGS=10;
int readings[NUMREADINGS]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
int average = 0;

The whole mechanism is not THAT precise but it gets the job done and it’s a fun thing to watch. The bass-frequency has to be smoothed-out quite a bit in order to make it all work. After spending a little more than a day with this some might ask “what for?”. I tell you what for: for the sake of finally doing it. I had this idea for over a year now and it was well worth trying.

The system is quite slow in its reaction (mainly caused by the necessary smoothing) and results are still a bit unpredictable but turning an audio-mixer into a midi-controller just by using hardware of ~10€ ain’t too bad, isn’t it?

There are numerous hacks out in the wild adding some weird functionality to it. For quite some time I wanted to something similar. This is the documentation of how to make the Easy-Button a MIDI-USB device based on Atmega328 (Arduino).

Many hacks have in common that they are either relatively expensive (like…involving something with a dedicated teensy device) or rather ugly (due to holes just being sawed into the Easy Button’s case).

My first goal was to build a device that automatically identifies itself as an HID-compliant USB-MIDI device and gives simple MIDI functionality by using an Atmega328 and V-USB. In order to achieve a correct enumeration and to get a useful starting point I used the demo-versionof USBLyzer to get the necessary data from my KORG nanoKey and altered them in various places (Vendor ID etc..). (You will remember this one later.)

When the button is pressed a ‘MIDI Note ON’ signal is sent. Upon release it sends a ‘Note OFF’ message.

The second goal was to give it a clean overall look.

Let’s see…

This is the Staples Easy Button with the cap and the clicker already being removed (which makes it just a pretty unidentifiable bunch of electronics and some plastic)

we don’t need the speaker so it will be gone soon….

The black line shows how deep the cap goes when it’s pressed.

This is the spot where the USB connector will be placed

I might not be the best craftsman around (already mentioned that once before) but after some filing this one looks pretty decent:

The plastic on the inside has to be cut as well

This DOES look quite well

Now I need to add the circuit board. Due to the speaker being thrown out there is lots of space for that now.

The circuit is basically a 1:1 copy of the V-USB keyboard example. The Button is connected with data pin 6 of the Atmega. It involves some creative soldering of the diodes because I didn’t care too much about the circuit’s layout before I started soldering.

Everything’s coming to an end soon

It seems impossible for my camera to do any decent shots that contain the color red.
Anyway, you might get an idea of how the circuit fits into the structure.

Some detail of how the actual button-mechanism is connected to the Atmega (the blue wires, you guessed it)

To make future additions a little easier I added an ICSP connector which fits nicely into what has formerly been the battery case

Finally… in all its glory.

I had this in the back of my mind for ~2.5 years now. Shortly before starting with this built I started wandering whether this might make sense or be worth the money or time invested or…..

F*CK IT. Never let doubts get in the way of your creativity. If this wouldn’t make sense than I probably wouldn’t have built it. Word! =)

The whole Arduino project (I did that arduino IDE 1.0.3) can be downloaded here. Unzip and copy the folder ‘Nanokey’ to the libraries-folder of your arduino IDE. Feel free to contact me if anything is left unclear.