• Techniques
  • implementing an xy midi controller using arduino and accelerometer
2015/02/10 01:26:38
swamptooth
for anyone that uses cakewalk synths that can use xy controllers like rapture and z3ta+ +2, or any synth via cc mapping, here's how to turn an accelerometer connected to an arduino into a midi controller.  X values are mapped to cc16 and Y values are mapped to cc17.  
 
You'll need hairless midi  http://projectgus.github.io/hairless-midiserial/
loopmidi http://www.tobias-erichsen.de/software/loopmidi.html
an arduino with an accelerometer - these may be calibrated differently, so plop your min and max ranges in the bold, italicized values. 
upload code to ardiono
run loopmidi and make a virtual midi port
run sonar 
load rapture
set its input to the loopmidi virtual port
open the xy controller pane and midi learn to your accelerometer
map the xy controls to parameters in your patch
move around the accelerometer for endless fun!
 
video here:  https://www.youtube.com/watch?v=eEnly2KNPiI&feature=youtu.be
 
Arduino code::
 
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
// set up pin numbers to use for x and y
const int x = 0;
const int y = 1;
//initialize all xy variables
//raw input variables
int xin = 0;
int yin = 0;
//filtered xy cc variables
int xcc = 1;
int ycc = 1;
//midpoints of calibrated accelerometer as initial values
int xfilt = 320;
int yfilt = 320;
//time constant for filter calculations
double ktime = .95;

void setup() {
// initialize midi communication and baud rate
MIDI.begin(MIDI_CHANNEL_OMNI);
Serial.begin(38400);
}
void loop() {


// read the analog inputs from the accelerometer
xin = analogRead(x);
yin = analogRead(y);
//apply the smoothing filters
xfilt = ktime * xfilt + (1.0 - ktime) * xin;
yfilt = ktime * yfilt + (1.0 - ktime) * yin;

//map the results to midi range 0-127
xcc = map(constrain(xfilt,287,371),287,371,0,127);
ycc = map(constrain(yfilt,287,371),287,371,0,127);

//due to a minor bug with cc sends in arduino midi library you need to send each cc twice on different channels
//x is sent on cc16 y is sent on cc17
MIDI.sendControlChange(16,xcc,1);
MIDI.sendControlChange(16,xcc,2);
MIDI.sendControlChange(17,ycc,1);
MIDI.sendControlChange(17,ycc,2);

//wait 6 milliseconds
delay(6);

}
 
2015/02/10 01:58:22
DoctorCalabria
Very cool. Now that you bring it up, I don't see why iPhone users couldn't use the MIDI output on GyroSynth to transmit the accelerometer based CC data to another device. I Haven't actually tried it but it it looks like it would be possible. I Love the current state of technology. It's a great time to be alive;) I remember building Craig's Electronic Projects for Musicians decades ago. Ahh the steam powered vocoder..
2015/02/10 02:02:10
swamptooth
Yeah, anderton is an experimental madman! Quadrafuzz is an all time fave. Seriously though why use a $500 iphone when you can build something like this for 60 bucks?
2015/02/10 02:02:57
DoctorCalabria
Because I already own one? Lol.
For that matter, Ive actually pulled my phone out of my pocket during a performance and held the speaker close to the pick up on my guitar and it came through loud and clear as I moved around to control the XYZ parameters of the GyroSynth. Pitch, amplitude and Filter cutoff. I suppose it would work with any phone that has electromagnetic transducer i.e. speaker
2015/02/10 02:03:35
swamptooth
;)
2015/02/10 02:05:41
swamptooth
I haven't figured how to get facebook control on this... Yet... Lol.
© 2025 APG vNext Commercial Version 5.1

Use My Existing Forum Account

Use My Social Media Account