Help- using an arduino to make a midi controller

you can use an analog pin as well as a digital pin..

thanks for all the tips so far.

so this is the code I've written to date:

// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// Touch panel wiring
// Connect to Arduino these wires (used to drive power)
#define Lo 2 // LEFT to digital output 2
#define Bo 3 // BOTTOM to digital output 3
#define Ro 4 // RIGHT to digital output 4
#define To 5 // TOP to Digital output 5

// Connect to Arduino these wires (used to read the touch position)
#define Ti 3 // TOP also to analog input 3
#define Ri 4 // RIGHT also to analog input 4

#define LED 13 // LED event
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// current touched
int touchX = 0;
int touchY = 0;
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


void setup()
{
 Serial.begin(31250);//midi=31250   testing=9600 
 pinMode(LED, OUTPUT); 
}

void loop() {
       if (touched())
                   {
                                     /*Serial.print("X=");
                                     Serial.print(touchX); 
                                     Serial.print(" Y=");
                                     Serial.println(touchY); <-old code*/
                   
                  midiX = map(touchX,0,1016,0,127);  // maps the value range of the axis to midi 0->127
                midiCC(0xB0, 12, midix);  // sends midi control change for touch pad X axis
                  
                  midiy = map(touchy,0,1016,0,127);  // maps the value range of the axis to midi 0->127
                midiCC(0xB0, 13, midiy);  // sends midi control change for touch pad y axis      
              }
       while analogRead(Ti) > 0 || analogRead(Ri) > 0; //this while loop keeps the LED on whilst the touch pad is being touched
        digitalWrite(LED, HIGH);
       else
        digitalWrite(LED, LOW);
       }

// return TRUE if touched, and coords in touchX and touchY
boolean touched()
       {
       boolean touch = false;

       // Horizontal routine - set L to gnd and R to Vcc
       // set L = ground
       pinMode(Lo, OUTPUT);
       digitalWrite(Lo, LOW); 
       // set R = Vcc
       pinMode(Ro, OUTPUT);
       digitalWrite(Ro, HIGH); 
       // T e B high impedance (input mode)
       pinMode(To, INPUT);
       pinMode(Bo, INPUT);
       // wait a bit, then read from Top
       delay(10); 
       touchX = analogRead(Ti); 

       // Vertical routine - set T to gnd and B to Vcc
       // Set B = Vcc
       pinMode(Bo, OUTPUT);
       digitalWrite(Bo, LOW); 
       // set T = gnd
       pinMode(To, OUTPUT);
       digitalWrite(To, HIGH); 
       // R e L high impedance (input mode)
       pinMode(Ro, INPUT);
       pinMode(Lo, INPUT); 
       // wait a bit, then read from Right
       delay(10); 
       touchY = analogRead(Ri);
       
       

       // Only if coords are below 1000 and above 0
       if(0 < touchX < 1000 and 0 < touchY < 1000)
       touch = true;

       return touch;
 }
 

void midiCC(char command, char value1, char value2){
  Serial.print(command, BYTE);
  Serial.print(value1, BYTE);
  Serial.print(value2, BYTE);
}

I haven't tested this cus I dont yet have all the pieces.

but what It should do is:

-read the touch coordinates of the X and Y Axis
-convert them to midi signals
-transmit the midi signal
-Stop transmitting the midi signal when my finger is off the pad
-have the LED on ONLY when you are physically pressing the touch pad

I am unsure about the midi signal I am sending aswell... cus I just can't read this stupid midi table... the ones i have coded to send are a calculated guess from attempting to read the table. (here is the table by the way, it is on page 11 http://www.korg.com/uploads/Support/KP2_OM_E_633661788715550000.pdf

the last "void" command in the code is also something I am unsure about. I know its necessary...but I'm struggling to understand how it works.

thank you all so much for your help.

I haven't tested this cus I dont yet have all the pieces.

Then you shouldn't be writing a ton of code. Write code only for the hardware you have, and test each piece of hardware separately. Only when a piece works correctly independently should you move on and try to combine it with other hardware.

the last "void" command in the code is also something I am unsure about.

Learning the correct terminology will be helpful. There are functions in the code you posted, not commands. When referring to functions, the return type (void) is completely unnecessary verbiage.

cus I just can't read this stupid midi table

Well, this implies that you are trying to merge hardware you no little about, software you know even less about, with technology you don't understand. Is this a school project, by any chance?

If you focus on one aspect at a time, instead of jumping in the deep end, the whole process will be more pleasant. Get some hardware. Write some code to drive it, or be driven by it. Integrate that hardware with other hardware. Join the code to drive the new hardware with the overall application sketch. Don't move forward until you understand how the hardware and software that you have installed/written play together.

Then you shouldn't be writing a ton of code. Write code only for the hardware you have, and test each piece of hardware separately. Only when a piece works correctly independently should you move on and try to combine it with other hardware.

I see your point, but this code is mainly extracted from several links, and I know that those pieces of code work. So whilst waiting for the hardware, instead of plugging in code that I know will work, I thought I would try and create code that does the basic principle I want my code to do, But I do agree with you that trial and error is most probably the single best way of learning to do this.

Learning the correct terminology will be helpful. There are functions in the code you posted, not commands. When referring to functions, the return type (void) is completely unnecessary verbiage.

After I posted my latest post, I went and extensively researched that void function. I even asked a friend who was a programmer. the problem I have is I don't understand the purpose/format of this line : "void midiCC(char command, char value1, char value2){" as I havent assigned a "command", a "value1" or a "value2", I even used the annotation midiCC twice... problem is every single piece of functioning midi interface code I've seen has it, but no where can I find an explanation as to why.

Well, this implies that you are trying to merge hardware you no little about, software you know even less about, with technology you don't understand. Is this a school project, by any chance?

If you focus on one aspect at a time, instead of jumping in the deep end, the whole process will be more pleasant. Get some hardware. Write some code to drive it, or be driven by it. Integrate that hardware with other hardware. Join the code to drive the new hardware with the overall application sketch. Don't move forward until you understand how the hardware and software that you have installed/written play together.

Your pretty much spot on with my knowledge. But no I'm not at school, I'm actually at university and this is not a project for my degree, This is a personal challenge/hobby I've set myself, as I've wanted to do this since I was about 15, but I only recently found out the proper way to do it. I've just finished my first year of studying mechanical engineering, sadly the only thing that my degree has as a transferable skill is basic programming (I have had to write code in MATLAB). But I've always been fascinated by electronics and I recently found that an arduino bridges that gap between hardware and software. Essentially I'm just looking to broaden my knowledge with this and electronics as I find them very intriguing.

Now when it comes to midi... IT IS HORRIFIC TO FIND A GOOD SOURCE OF KNOWLEDGE FOR IT... I have read through countless hours of junk about midi, starting from the very basics and going to the very complex, on other pieces of guitar equipment I have, I have found exactly the midi information I need. but simply this kaoss pad I feel has a very badly explained table.

personally I think midi is a terrible technology and they shouldn't have done it so early. cus now were stuck with it.

But if someone could help me understand how that table works, or even how that void function works. I would greatly appreciate it.

thanks to all.

Can't help you with the midi table, as you know more about midi than I (care to).

The midiCC function, though, takes 3 arguments. The first is reference, in the function, using the name command. The second is referenced using the name value1. The third is referenced using the name value2.

You call the function this way:
midiCC(0xB0, 12, midix); // sends midi control change for touch pad X axis
midiCC(0xB0, 13, midiy); // sends midi control change for touch pad y axis
So, the function will write the 3 values (0xB0, 12, and midix or 0xB0, 13, and midiy) to the serial port, where the midi-controller is presumably listening.

Well I think that makes sense, Yeah thanks for the help. :slight_smile:

Hey Chris,
I'm new the forum and arduino as well, but I've been trying to accomplish the same thing. What I do know is Gareth's Hold Switch bypasses the "pad off" command sent.

Hope this helps!

Phi

don't listen to mowcius its a resistive touch screen with 4 wires and it uses 4 analog inputs with resistors to ground

don't listen to mowcius its a resistive touch screen with 4 wires and it uses 4 analog inputs with resistors to ground

Umm, you must be new here.

That's not how things work around this forum. If you can provide some tried and tested code to show some method with only 4 analog inputs (and some pull down resistors) working then I will happily accept your statement.

Please don't say things like 'don't listen to'. It's not really in the spirit of this forum. I might just go and say something like, "don't listen to bassman76jazz, he's a noob with 1 post and doesn't know anything about what he's talking about" but under normal circumstances I would not ever say something like that.

Basically, please provide some more details on this method and try to be a bit more constructive on the forum in future.

Mowcius

Im new here but have come accross this site that details how to use a four wire resistive touchscreen with an arduino and 10k ohm resistors to earth. I have not tested the code yet however.

I cant post the site up though as its my first post..

http://kalshagar.wikispaces.com/Arduino+and+a+Nintendo+DS+touch+screen

I see what they did, seems like a nice way to do it. Well thank you for providing a link.

Mowcius

Which one would you recommend I use? I does one have a clear advantage to the other?

Which one would you recommend I use? I does one have a clear advantage to the other?

Well one uses 4 pins and one 6. I would not have thought it mattered. As long as they tell you the position, they presumably do what you want them to do.

Mowcius

ahh this is killing me!

so I decide to do the 6 wire method as I was already half way through doing it anyway, the computer reads the touch pad no problem.

the Kaoss pad however -.-"

it just wont...

If I change the midi signal to

midiCC(0xC0,0,touchX);

I can control the setting the touch pad is on (the command Im hoping to use for the encoder.)

but when I put it back to midiCC(0xB0,12,touchX);

its just wont bloody work! i have literally tried everything...im just completely out of ideas as to why its not working... Every single midi site ive gone to has basically told me that the command is correct.

pheh....a little help anyone?

xD

so I just wrote and used a program that went through every single midi signal in the CC list... none of them triggered the touch pad, im really confused now...

midiCC(0-255,0-16,fixed constant)

thats the combination i went through.

I know you're probably super frustrated, but just some troubleshooting:

Did you put the KP2 into MIDI control mode?

Gareth said something about mapping out the midiCC to a certain coordinate on the X-Y touch screen, although it seems that the program you made showed that it isn't the pad's fault.

I'm out of ideas for the moment. I'm rooting for you! Because I'd like to make one myself :slight_smile:

Maybe try it with a DigiTech Whammy as well?

How's the LED control and the Hold switch going?

i havent tested it on the whammy, but im assuming it will work, i may do that now and post the results.

the back light LED is actually alright to work with, the hold button im not sure about either.

the only midi message the kaoss pad has received so far is the effects change...and thats the easiest one to send as its only like 1 value.

argh i wish i knew what i was doing wrong.

anyway im gonna go try the digitech whammy.

Was the KP2 in MIDI receiving mode?

Also, I think the Whammy is mapped differently, which is why Gareth's kit involves pressing the encoder to switch control between a Kaoss and a Whammy. One channel won't control the device it's not intended to.

But getting it with the whammy will be progress!

yeah um...it works lol... its just the kaoss pad that is a maHUSIVE beatch