implementing an xy midi controller using arduino and accelerometer

Author
swamptooth
Max Output Level: -53 dBFS
  • Total Posts : 2229
  • Joined: 2012/04/16 15:44:21
  • Status: offline
2015/02/10 01:26:38 (permalink)

implementing an xy midi controller using arduino and accelerometer

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);

}
 
post edited by swamptooth - 2015/02/10 01:33:10

 
Arvid H. Peterson
Sonar X3E Prod / X2A  / X1PE | Cubase 9.5.1 | Reason 9.5 | Sibelius7 | Pure Data
Native-Instruments Komplete 10 Ultimate and a smattering of other plugins
Home-brewed VSTs 
Toshiba Satellite S855-S5378 (16GB RAM, modified with 2x 750GB HDDs, Windows 8.1 x64)  
Samson Graphite 49, M-Audio Oxygen 49, Korg nanoPAD2, Webcam motion tracking programs 
M-Audio Fast Track Ultra
Member, ASCAP   


#1

5 Replies Related Threads

    DoctorCalabria
    Max Output Level: -90 dBFS
    • Total Posts : 36
    • Joined: 2010/12/21 01:24:57
    • Status: offline
    Re: implementing an xy midi controller using arduino and accelerometer 2015/02/10 01:58:22 (permalink)
    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..

    Sonar Version:  Sonar Platinum  
    Audio Interface: RME RayDAT w/ Behringer X32 and X-ADAT interface
    Computer: i7-4790k, 32GB RAM, Windows 7 Pro x64, Samsung SSD 500G, HGST 4G x 2, QNAP NAS
    SW: iZotope Ozone 6, RX 4, NI Komplete 10 Ultimate, Plogue Bidule, Omnisphere, Trilian
    MIDI Controllers: A-Pro, NI Komplete Kontrol 61, Fatar 88, X32


    #2
    swamptooth
    Max Output Level: -53 dBFS
    • Total Posts : 2229
    • Joined: 2012/04/16 15:44:21
    • Status: offline
    Re: implementing an xy midi controller using arduino and accelerometer 2015/02/10 02:02:10 (permalink)
    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?

     
    Arvid H. Peterson
    Sonar X3E Prod / X2A  / X1PE | Cubase 9.5.1 | Reason 9.5 | Sibelius7 | Pure Data
    Native-Instruments Komplete 10 Ultimate and a smattering of other plugins
    Home-brewed VSTs 
    Toshiba Satellite S855-S5378 (16GB RAM, modified with 2x 750GB HDDs, Windows 8.1 x64)  
    Samson Graphite 49, M-Audio Oxygen 49, Korg nanoPAD2, Webcam motion tracking programs 
    M-Audio Fast Track Ultra
    Member, ASCAP   


    #3
    DoctorCalabria
    Max Output Level: -90 dBFS
    • Total Posts : 36
    • Joined: 2010/12/21 01:24:57
    • Status: offline
    Re: implementing an xy midi controller using arduino and accelerometer 2015/02/10 02:02:57 (permalink)
    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
    post edited by DoctorCalabria - 2015/02/10 02:12:06

    Sonar Version:  Sonar Platinum  
    Audio Interface: RME RayDAT w/ Behringer X32 and X-ADAT interface
    Computer: i7-4790k, 32GB RAM, Windows 7 Pro x64, Samsung SSD 500G, HGST 4G x 2, QNAP NAS
    SW: iZotope Ozone 6, RX 4, NI Komplete 10 Ultimate, Plogue Bidule, Omnisphere, Trilian
    MIDI Controllers: A-Pro, NI Komplete Kontrol 61, Fatar 88, X32


    #4
    swamptooth
    Max Output Level: -53 dBFS
    • Total Posts : 2229
    • Joined: 2012/04/16 15:44:21
    • Status: offline
    Re: implementing an xy midi controller using arduino and accelerometer 2015/02/10 02:03:35 (permalink)
    ;)

     
    Arvid H. Peterson
    Sonar X3E Prod / X2A  / X1PE | Cubase 9.5.1 | Reason 9.5 | Sibelius7 | Pure Data
    Native-Instruments Komplete 10 Ultimate and a smattering of other plugins
    Home-brewed VSTs 
    Toshiba Satellite S855-S5378 (16GB RAM, modified with 2x 750GB HDDs, Windows 8.1 x64)  
    Samson Graphite 49, M-Audio Oxygen 49, Korg nanoPAD2, Webcam motion tracking programs 
    M-Audio Fast Track Ultra
    Member, ASCAP   


    #5
    swamptooth
    Max Output Level: -53 dBFS
    • Total Posts : 2229
    • Joined: 2012/04/16 15:44:21
    • Status: offline
    Re: implementing an xy midi controller using arduino and accelerometer 2015/02/10 02:05:41 (permalink)
    I haven't figured how to get facebook control on this... Yet... Lol.

     
    Arvid H. Peterson
    Sonar X3E Prod / X2A  / X1PE | Cubase 9.5.1 | Reason 9.5 | Sibelius7 | Pure Data
    Native-Instruments Komplete 10 Ultimate and a smattering of other plugins
    Home-brewed VSTs 
    Toshiba Satellite S855-S5378 (16GB RAM, modified with 2x 750GB HDDs, Windows 8.1 x64)  
    Samson Graphite 49, M-Audio Oxygen 49, Korg nanoPAD2, Webcam motion tracking programs 
    M-Audio Fast Track Ultra
    Member, ASCAP   


    #6
    Jump to:
    © 2024 APG vNext Commercial Version 5.1