Arduino Forum

Using Arduino => Audio => Topic started by: boguz on Mar 24, 2012, 08:10 am

Title: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Mar 24, 2012, 08:10 am
Soooo, i am now trying to build a little MIDI "Xilophone".

I followed this schematics:
(http://img9.imageshack.us/img9/6067/skeml.jpg)
(found here: http://www.jdeboi.com/portfolio/electronics.html (http://www.jdeboi.com/portfolio/electronics.html))

i have now finished all the connections and they seem to be working.
When i press any of the piezo disks i get a little flash on the TX light on my Arduino UNO board. (this means it is transmitting, or??!?)
When i open the Serial Monitor i get this:
(http://img33.imageshack.us/img33/6411/sermono.jpg)
Is this how it is supposed to look like?

My next step was to try to convert the serial data into MIDI.
I am on a Mac, so i have created a new "IAC Device".
Then I used the serial to MIDI converter from SpikenzieLabs and used this new IAC Device.
i have tried several different configurations, different port ins, different port outs, baud rates,...
(http://img560.imageshack.us/img560/7329/s2mv.jpg)

As you can see there on the image, i also get there the green light in the RX (receiving?).
But i do NOT get it in the TX...

When i now try to connect it to Ableton (making a Manual Mapping) i cannot get it to work.
I have turned on the IAC Device on the Preferences and sometimes i even get a "Midi in light" blink (very rarelly), but when i try to map it it doesn't really work!

Does someone have an idea of what i'm doing wrong?

Thanks
=)
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Mar 24, 2012, 06:17 pm
The baud rate must be the same on the arduino and what the Mac is expecting.
It is unlikely you will see anything useful in the serial monitor. Google for a MIDI monitor.
This will show you if something is arriving in the Mac.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Mar 24, 2012, 08:56 pm
thanks, that was a good idea. i did't know such a program existed.
i tried Snoize and i got NO signal of MIDI!!  =(

What could the problem be?
How can i know the baud rate that the mac is waiting?
At this point i have:   Serial.begin(57600);

This is how the whole code looks like:

Code: [Select]
//Jenna deBoisblanc, 2011
//
//Code adapted from:
//Mark Demers' code, Copywrite 2009 (http://spikenzielabs.com/SpikenzieLabs/DrumKitKit.html)
//Georg Mill's YAAMIDrum (www.georgmill.de/)
//Arduino on the 4051 (http://www.arduino.cc/playground/Learning/4051)


unsigned char PadNote[8] = {60,62,64,65,67,69,71,72};
unsigned char status;
int PadCutOff[8] = {80,110,110,110,80,110,110,110};
int MaxPlayTime[8] = {90,90,90,90,90,90,90,90};
#define midichannel 0;
boolean activePad[8] = {0,0,0,0,0,0,0,0};                   // Array of flags of pad currently playing
int PinPlayTime[8] = {0,0,0,0,0,0,0,0};                     // Counter since pad started to play
boolean VelocityFlag = false;

int analogPin = A0;   
int hitavg = 0;
int pad = 0;

byte byte1;
byte byte2;
byte byte3;

int r0 = 0;      //value of select pin at the 4051 (s0)
int r1 = 0;      //value of select pin at the 4051 (s1)
int r2 = 0;      //value of select pin at the 4051 (s2)
int count = 0;   //which y pin we are selecting

int multiplex1[8];
int multiplex2[8];
int multiplex3[8];

//*******************************************************************************************************************
// Setup   
//*******************************************************************************************************************

void setup()
{
  pinMode(2, OUTPUT);    // s0
  pinMode(3, OUTPUT);    // s1
  pinMode(4, OUTPUT);    // s2
  Serial.begin(57600);     
}

//*******************************************************************************************************************
// Main Program   
//*******************************************************************************************************************

void loop (){
  midiLoopback();
  readSensors(0);
  //readSensors(1);
  //readSensors(2);
  checkSensors(0);
  //checkSensors(1);
  //checkSensors(2);

}

void readSensors (int analogPin) {

  for (count=0; count<=7; count++) {

    // select the bit
    r2 = bitRead(count,0);    // use this with arduino 0013 (and newer versions)   
    r1 = bitRead(count,1);    // use this with arduino 0013 (and newer versions)   
    r0 = bitRead(count,2);    // use this with arduino 0013 (and newer versions)   
 
    //r0 = count & 0x01;      // old version of setting the bits
    //r1 = (count>>1) & 0x01;      // old version of setting the bits
    //r2 = (count>>2) & 0x01;

    digitalWrite(2, r0);
    digitalWrite(3, r1);
    digitalWrite(4, r2);
 
 
      //Read and store the input value at a location in the array
      //if(analogPin==0){
     
     multiplex1[count] = analogRead(analogPin);
    //Serial.print(count);
     //Serial.print(" ");
     //Serial.println(multiplex1[count]);
      // }
      //else if(analogPin==1){
      //  multiplex2[count] = analogRead(analogPin);
      //
      //else if(analogPin==2){
      //  multiplex3[count] = analogRead(analogPin);
      // }
      }
}




void checkSensors(int analogPin){

  for(int pin=0; pin <=7; pin++){
 
    if(analogPin==0){
      hitavg = multiplex1[pin];
      pad=pin;
    }
    else if(analogPin==1){
      hitavg = multiplex2[pin];
      pad=pin+8;
    }
    else if(analogPin==2){
      hitavg = multiplex3[pin];
      pad=pin+16;
    }

    if((hitavg > PadCutOff[pin])){
      if((activePad[pad] == false)){
     
        if(VelocityFlag == true){
          hitavg = (hitavg / 8) -1;
        }
        else{
          hitavg = 127;
        }
   
        MIDI_TX(144,PadNote[pad],hitavg);
        PinPlayTime[pad] = 0;
        activePad[pad] = true;
      }
     
       else {
         PinPlayTime[pad] = PinPlayTime[pad] + 1;
      }
    }
 
    else if((activePad[pad] == true)) //the pad is active, but it is not greater than cutoff
    {
      PinPlayTime[pad] = PinPlayTime[pad] + 1;
   
      if(PinPlayTime[pad] > MaxPlayTime[pad])
      {
        activePad[pad] = false;
        MIDI_TX(128,PadNote[pad],127);
      }
    }
  }
}

void midiLoopback(){
  if(Serial.available() > 0){
      byte1 = Serial.read();
      byte2 = Serial.read();
      byte3 = Serial.read();
   
      MIDI_TX(byte1, byte2, byte3);
    }
  }

//*******************************************************************************************************************
// Transmit MIDI Message   
//*******************************************************************************************************************
void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY)
{
  status = MESSAGE + midichannel;
  Serial.print(status);
  Serial.print(PITCH);
  Serial.print(VELOCITY);
}   


Thank you
=)
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Mar 24, 2012, 09:00 pm
As you have :-
Serial.begin(57600) ;
Then you need to set the Serial <> Midi baud rate to the same value, that is 57600.
Only then will you be able to see anything in the MIDI monitor. 
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Mar 25, 2012, 09:30 am
hey, thanks, that was good advice.

i have now done some experimenting with the baud rates.
First i have left it at 57600 and tried the Serial2Midi also at the same rate. It doesn't work! I get only the red light flashing.
Then i tried several other combinations, and noticed that when i set the baud rate in the Converter a little bit lower then in the Arduino (like for example Arduino: 57600, Converter: 38400), then i get green lights blinking.

So i opened the MIDI Monitor and was, at first, happy. Now i can, at least, get some kind of readings there.
The problem is that the readings are erratic, so not so useful as MIDI!

When baud rates are the same, the MIDI Monitor doesn't read anything at all.
When baud rate are slightly different (like in the example above) then the MIDI Monitor reads a lot.

Here is an example (Arduino's baud rate was at 57600):
(http://img638.imageshack.us/img638/2122/midiserial.jpg)
All those readings on the MIDI Monitor (on the left) are from only ONE piezo disk touch.
Sometimes i get more, sometimes i get less...

If i open the serial monitor from the Arduino software and set it to the right rate (57600), then i get for one touch:
1446412712864127

Any ideas???



= = = = = = = =
Another thing...

When i read down the code, i notice that there are lots of place using the //
Like here:
(http://img837.imageshack.us/img837/4570/code1a.jpg)

or here:
(http://img845.imageshack.us/img845/6351/code2f.jpg)

Is this supposed to be like that or i'm i actually supposed to change parts of the code according to my "setup" of the piezo disks?


Well, once again, thank you for your help!
=)
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Mar 25, 2012, 10:22 am
Quote
When baud rates are the same, the MIDI Monitor doesn't read anything at all.
When baud rate are slightly different (like in the example above) then the MIDI Monitor reads a lot.

The baud rate has to be exactly the same on both devices. Try making it 9600 on both the arduino and the serial to MIDI software. What sort of arduino do you have?
If they are not the same you get rubbish.

Your value of 1446412712864127 is correct this is the message
144 - note on channel 1
64 - the MIDI value of the note
127 - the velocity of the note on event, a bit like the volume
128 - note off on channel 1
64 - the MIDI value of the note
127 - the after touch of the note off event

The code is fine for the setup you have, you can add another two multiplexed inputs by uncommeting those lines.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Mar 25, 2012, 01:00 pm
My board is an Arduino Uno that i got about two weeks ago.

I just tried to set both baud rates at the same, but then i get red lights on the Serial to MIDI converter and i get no signal at all in the MIDI Monitor.
(on the serial monitor in the Arduino software i get the same values as before)

I tried 9600, 57600 and 115200 (always the same on both the arduino and the software), but got always the same result!
=/
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Mar 25, 2012, 01:26 pm
How are you changing the speed on the arduino.
You must change the Serial.begin(9600)
And upload the sketch again.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Mar 25, 2012, 02:09 pm
Yes, that is how i am changing it. i Open the sketch in the Arduino software, I change the Serial.begin that is in the void setup and then i upload it.

I also noticed i get a red light on the RX and NO light at all in the TX of the Serial to MIDI converter.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Mar 25, 2012, 02:16 pm
OK how are you running the serial <> MIDI app.
Try running it direct from processing, you have to down load the library it is asking for before it will run, but the .pde processing source code is in the download package.
I couldn't get the serial <> MIDI app running directly on my Mac but it works through processing.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Mar 25, 2012, 03:39 pm
Sorry, but i have no idea of what it means to run it from processing.   =/
I have been running it just by double clicking it.
but yes, with it there is a folder with a "Serial_MIDI_Converter_V2C.pde" and "Serial_MIDI_Converter_V2C.java" files.
i have opened the .pde file in Arduino's software, but then what should i do with it?
Should i upload it to the arduino?

If i open it in Arduino's software and then open the serial monitor from there i get:
1446912712869127 (which i assume are also the same midi values as before...)

i am feeling soooooooo lost with this!!
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Mar 25, 2012, 04:53 pm
Quote
If i open it in Arduino's software and then open the serial monitor from there i get:
1446912712869127 (which i assume are also the same midi values as before...)

Yes this is the same as before and shows your arduino and sensors are working correctly. What is not working is the bit that converts this serial data into MIDI. The arduino's serial monitor must be closed when you attempt to use serial <> MIDI.

Processing is a language, a bit like the aruino but it runs on your computer.
Down load it from here:-
http://processing.org/ (http://processing.org/)
And install it ( it is just clicking )

Then down load the "themidibus" library from:-
http://smallbutdigital.com/themidibus.php (http://smallbutdigital.com/themidibus.php)
Unzip it and put it in the libraries folder which is inside the Processing folder that the Processing language created when you installed it.

Then go into the Processing folder and create a folder called Serial_MIDI_Converter_V2C, and put that source file Serial_MIDI_Converter_V2C.pde inside it.

Then run the Processing application and use the menu File -> Sketchbook -> Serial_MIDI_Converter_V2C to load it in. Run it from the arrow in the top corner.
Choose Bus 1.
If you choose Java Sound Synthesizer, when offered, then you should be able to hear your taps on your sensors.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Mar 25, 2012, 06:16 pm
Aaaaaaahhhhh, i can feel that we are getting close!!!

I have installed the Processing software (which, by the way, seems like a nice software to explore...) and also instaled the midibus library.
i opened the "Serial_MIDI_Converter_V2C" pde file in Processing but then got an error message when i tried to run it.

it sais:
The function returnList() does not exist.

and it highlights this line of the code:
Quote
String midiport[][] = myBus.returnList();


Any ideas on what is wring with this line?
Thanks
=)
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Mar 25, 2012, 06:23 pm
Odd I searched all that code and there is no mention of returnList(),
can you copy ALL the error message and paste it in the reply.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Mar 25, 2012, 06:31 pm
Have you got the same source as me, that line you changed by editing doesn't exist either.
It might be worth downloading this code again.
I downloaded it this morning, unfortunately it is too long to post.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Mar 25, 2012, 10:25 pm
Yes, you were right, i add the "old" version SMv2c. Now i have downloaded the SMv2d and i can run it on Processing.

But still when i set baud rates the same i get red light in the converter (running from Programing) and no signal at all in the Midi Monitor.
Like this:
(http://img816.imageshack.us/img816/4136/progserial.jpg)

=/
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Mar 25, 2012, 10:30 pm
Do you get any sound from tapping the sensors generated in processing?
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Mar 25, 2012, 10:32 pm
no, i get no sound...
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Mar 26, 2012, 07:37 am
This morning i was reading the code from the Converter (which i am opening in Processing) and i noticed that it sais that having mmj installed makes some kind of bug.

I went to uninstall it, restarted the computer, opened again Processing...

...and got still the same result!

When baud rates are at the same speed i get only red light and no signal in Midi Monitor!
:/
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Mar 26, 2012, 11:25 am
OK, try this. Can you replace the Extensions folder with this one attached and see if it makes any difference.
It is to be found at:-
Macontosh HD -> Library -> Java

What version of the OS are you on?
It might be worth searching for people who have had trouble with Serial <> MIDI with your version.

If this doesn't work then we might have to explore going directly into Ableton. I don't have it but I could download the trial version and see what can be done directly.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Mar 26, 2012, 12:58 pm
i have osx 10.6.8

i have replaced the extension folder and it still doesn't work, but i got an error message from Processing:

Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
RXTX Warning:  Removing stale lock file. /var/lock/LK.008.011.010

Bah...   =/   

If i would add a MIDI out port to the setup, would it mean i had to change all the code?


= = = = = = = =

Let me see if i am doing things right.

I plug the Arduino via USB.
Open Arduino software and upload the sketch.
"play" a couple of piezos to confirm i get the TX light in arduino board.
Open Processing and the SMv2d sketch.
Run the sketch.

?
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Mar 26, 2012, 01:31 pm
Quote
i have osx 10.6.8

Me too.

Quote
I plug the Arduino via USB.
Open Arduino software and upload the sketch.
"play" a couple of piezos to confirm i get the TX light in arduino board.
Open Processing and the SMv2d sketch.
Run the sketch.

Sounds OK as well, as long as the arduino serial monitor window is not open.

When I run processing I just get:-
Quote


Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7


That error message :-
RXTX Warning:  Removing stale lock file. /var/lock/LK.008.011.010
might mean you have to find that file and then delete it. Then restart processing, worth a try.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Mar 27, 2012, 02:28 pm
i can't find that file. Not even the folder...
=/
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: dxw00d on Mar 27, 2012, 03:06 pm
Code: [Select]
RXTX Warning:  Removing stale lock file. /var/lock/LK.008.011.010

Is just a warning. It's telling you that it removed the stale file, that's why you can't find it.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Mar 27, 2012, 04:45 pm
I couldn't run the stand alone application on my machine until is set it to run in 32 bit mode.
Click on the Serial_MIDI_Converter_V2D icon. Then select information from the finder and click the open in 32 bit mode in the window.
Now it opens fine. It might be worth trying this and see if it improves things. You could also try running Processing in the 32 bit mode as well.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Mar 28, 2012, 06:45 am
The message
Quote
RXTX Warning:  Removing stale lock file. /var/lock/LK.008.011.010

come when i chose the "Midi Out Port".

Then when i press any of the piezodisks the only thing i get is the Serial RX Light blinking RED!!

I now tried running the both the stand alone application and Processing in 32-bit mode. Everything goes exactly the same.

If the lights blink red, it means that at least some kind of information is getting to Processing (?). Is it possible to see WHAT is getting there?

= = =

I am getting king of crazy (sad, frustrated, desperate,..., curious,...) , so i am tried something that maybe is also not so smart...
should the Arduino code run on Processing also?

I copied it into Processing and i got an error saying :
Quote

unexpected token: unsigned

processing.app.SketchException: unexpected token: unsigned
   at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:326)
   at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:197)
   at processing.mode.java.JavaBuild.build(JavaBuild.java:156)
   at processing.mode.java.JavaBuild.build(JavaBuild.java:135)
   at processing.mode.java.JavaMode.handleRun(JavaMode.java:176)
   at processing.mode.java.JavaEditor$20.run(JavaEditor.java:481)
   at java.lang.Thread.run(Thread.java:680)


the error was refering to this line of the code:
Quote
unsigned char PadNote[8] = {60,62,64,65,67,69,71,72};


well, maybe that is supposed to happen...
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Mar 28, 2012, 09:44 am
Quote
I am getting king of crazy (sad, frustrated, desperate,..., curious,...)

Yes it is understandable. I don't think there is a sympathy smilie.

Quote
should the Arduino code run on Processing also?

No, while the syntax is similar it is the language C in the Arduino and Java in Processing, so it will not work.

Quote
Is it possible to see WHAT is getting there?

You can add print statements to processing to look at any variables while it is running. That could give you an insight into what is happening.
I was asking a friend about this yesterday and he said he had trouble with this program at first and it was down to the way the MIDI configured using the Audio MIDI setup application. The website for the serial <> MIDI converter had a guide to setting this up have you gone through this?
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Mar 28, 2012, 12:38 pm
Yes, when installed the Serial <> MIDI i have followed the instruction in their website on how to set things up.

i will try to get some kind of Serial Port Monitor and see if i can get some info there also...
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Mar 28, 2012, 12:55 pm
i have just tried a Serial Monitor (Serial Tools) and i got the same. i got green light blinking and the same value as before with the "Midi information".
I guess this means the serial information is arriving ok?

= = = = =

When i got to the Audio MIDI Setup -> Preferences and then choose Information, i get this:
(http://img9.imageshack.us/img9/895/infoke.jpg)

Can it be that i am missing something i should have? Can i have something outdated?
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Mar 28, 2012, 02:45 pm
It looks the same as mine, attached.

I think we need to find out where it is going wrong.
Can you run up a sketch that talks from the arduino into processing.
Just something on the arduino that prints a string every second, and the processing prints out what it receives.
That would check the serial path into processing.
There is a sketch in Examples -> Library -> Serial -> Simple read.
After the :-
Code: [Select]
val = myPort.read();
put a
Code: [Select]
println(val);
You should then be printing the ASCII value of the bytes you receive from the arduino.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: dxw00d on Mar 28, 2012, 03:25 pm
FWIW, I can't get it to work either. I've done a number of Arduino to Processing serial things successfully. I have Lion - 10.7.3.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Mar 28, 2012, 06:11 pm
Just to make sure we are on the same page.
This is the arduino sketch I have been using to test the MIDI input. It just generates random chimes. Run it on the arduino and see if the Serial <> MIDI make sense of it:-
If you choose the Java Synth option you should here the chimes.

Code: [Select]


/* Midi note fire - Mike Cook March 2012
*
* -----------------
* send MIDI serial data, automatically for a test
*
###############################################################################################

HARDWARE NOTE:
The MIDI Socket is connected to arduino TX through a PNP transistor to invert the MIDI signal.
A common anode RGB LED is pulled down through pins 9, 10, 11

################################################################################################
*/
#define MIDI_TEST   // un comment for a test to format the data for the serial monitor

#define midiChannel (byte)0
void setup() {
//  Setup serial
   Serial.begin(9600);    // Serial speed
   programChange(0xc0, 14);  // Change MIDI voice

}

//********************* MAIN LOOP ***********************************

void loop() {
  int val;
  val = random(20,100);
    noteSend(0x90, val, 127);
    delay(200);
    noteSend(0x80, val, 127);
   delay(800);
    } // end loop function
   
//********************* Functions ***********************************


//  plays a MIDI note
void noteSend(char cmd, char data1, char data2) {
  cmd = cmd | char(midiChannel);  // merge channel number
  Serial.write(cmd);
  Serial.write(data1);
  Serial.write(data2);
}
//  change the voice
void programChange(char cmd, char data1) {
  cmd = cmd | char(midiChannel);  // merge channel number
  Serial.write(cmd);
  Serial.write(data1);
}

//  change the bank
void bankChange(char cmd, char data1) {
  Serial.write(0xB0 | char(midiChannel));  // control change
  Serial.write(cmd);
  Serial.write(data1);
}
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Mar 28, 2012, 06:21 pm
OK I think I have cracked it.
You need to change the MIDI_TX() function in your code to this:-

Code: [Select]

void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY)
{
  status = MESSAGE + midichannel;
  Serial.write(status);
  Serial.write(PITCH);
  Serial.write(VELOCITY);


Then make sure the baud rate is set the same between MIDI and Arduino.

Sorry for taking so long and not having spotted this before.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: dxw00d on Mar 28, 2012, 06:23 pm
Mike, your test code worked ok for me.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: dxw00d on Mar 28, 2012, 06:32 pm
It seems to be working fine for me now. I might have had the Midi setup wrong. I can pass midi into Live now.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Mar 28, 2012, 09:46 pm
oh nooooooooooooo, i can't believe it!!!   It is actually WORKING!!!   :D

There are two piezos not working and one that plays two notes at the same time. But i'll take a look at this tomorrow when there is more light and i have some more energy (probably i have some connections in the breadboard that opened from all the moving around)!

THANK YOU SOOOO MUCH!   I think this has been a great step towards making this project come true!
=)

Stay tuned for the next chapter...
;)
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Mar 31, 2012, 07:42 am
I took a close look and, indeed, some of the piezo wires were a bit loose from all the moving around. I fixed that and now they all play a different not and i run the Serial <> Converter through Processing.

When i now open the MIDI Monitor i get this kind of result:
Quote
*** ZERO ***   From Xilof OUT   Note On   1   D3   127
*** ZERO ***   From Xilof OUT   Note Off   1   D3   127
*** ZERO ***   From Xilof OUT   Note On   1   F3   127
*** ZERO ***   From Xilof OUT   Note Off   1   F3   127
*** ZERO ***   From Xilof OUT   Note On   1   A3   127
*** ZERO ***   From Xilof OUT   Note Off   1   A3   127

(from pressing 3 piezos in sequence)

So, is it now ok to assume the "assembly" and Midi Conversion parts are working fine?

= = = = = = = = = =

So, my next step would involve two things: add some LEDs and add some controls.

LEDs
I would like to add an LED to each piezo, that would light up when we play and then would slowly fade out (maybe 1 second)
What would be the easiest way to achieve this?

Controls
I would like to add 4 buttons (MIDI, that i could then assign for things like Play, Stop, trigger some event, change sound,...)
and add also 4 knobs (that could be assigned for things like volume, modulation, tempo,...)
Would this be easily done by just enabling one other multiplexer from the code?

Any thoughts about this two things?
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Mar 31, 2012, 01:04 pm
Any extras you add are going to increase the latency because the code has to look at them as well. Anyway you can pile on the extras until it gets too much.

With the LEDs the simplest from a programming point of view is to add a shift register:-
http://www.elcojacobs.com/shiftpwm/ (http://www.elcojacobs.com/shiftpwm/)

Quote
add also 4 knobs

Yes adding an extra multiplexer will do this.

Quote
to add 4 buttons

You should have some spare pins left on the arduino.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Mar 31, 2012, 03:03 pm
Quote
You should have some spare pins left on the arduino.

So i can just add normal buttons to a digital pin? This shouldn't then be a problem, at the moment i am using only 3 of the digital pins.

Quote
With the LEDs the simplest from a programming point of view is to add a shift register:-

for the LEDs, i have a couple of 74HC595N. I saw http://arduino.cc/en/Tutorial/ShiftOut (http://arduino.cc/en/Tutorial/ShiftOut) that we can use it to plug several LEDs. But i would have really NO IDEA on how to right a code reading which piezo was played and telling which LED should light up!

Well, i think i will start with the buttons. Maybe that is something accessible for my level.
Anyway, i don't have anymore multiplexers, so i need to wait until tuesday when i'm going to town to buy one more.

Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Mar 31, 2012, 04:17 pm
Quote
So i can just add normal buttons to a digital pin?

Yes, you can even use an analogue pin and treat it as a digital one if you want.

Quote
I saw http://arduino.cc/en/Tutorial/ShiftOut that we can use it to plug several LEDs.

Two things, that schematic has an error, there should be no capacitor on the latch pin. Second that software will not give you the fading you want. Use the code in the link for that.
Just do a few examples, given in the link, and you will get the hang of how to control the shift registers.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Apr 01, 2012, 11:43 am
So, today i am trying to make the 4 buttons work...
i have things setup in the breadboard and i have the buttons connected to Arduino like this:
Button 1 ---> Pin 8
Button 2 ---> Pin 9
Button 3 ---> Pin 10
Button 4 ---> Pin 11

Now, being that i have no experience writting code, i got a bit stuck with it.
I looked around internet, in arduino forum's and i actually think i got at least something i can work on...
right now the code i wrote (JUST for the buttons) is like this:

Quote
//trying to make 4 buttons work

// == = = = = = = = = = = = = = = = = = = =

//BUTTON 1
int button1Pin = 8;       //Button input pin
int button1Val = 0;       //Variable for reading the button status
int button1State = 0;     //Variable to hold the button's current state
int bounce1Check = 0;     //Variable for debouncing

//BUTTON 2
int button2Pin = 9;
int button2Val = 0;
int button2State = 0;
int bounce2Check = 0;

//BUTTON 3
int button3Pin = 10;
int button3Val = 0;
int button3State = 0;
int bounce3Check = 0;

//BUTTON 4
int button4Pin = 11;
int button4Val = 0;
int button4State = 0;
int bounce4Check = 0;

void setup() {
  pinMode(button1Pin, INPUT);   //Pin 8 as Button 1 Input
  pinMode(button2Pin, INPUT);   //Pin 9 as Button 2 Input
  pinMode(button3Pin, INPUT);   //Pin 10 as Button 3 Input
  pinMode(button4Pin, INPUT);   //Pin 11 as Button 4 Input
  Serial.begin(57600);               //Baud rate of 57600
}

void loop()
{
  // Momentary buttons
 
  //BUTTON 1
  button1Val = digitalRead(button1Pin);                     //Read input value from button1 (pin8)
  delay(10);                                                          //Delay of 10ms
  bouce1Check = digitalRead(button1Pin);                 //Checking value from button1 (for debouncing)
  if(button1Val == bounce1Check){
    if (button1Val == HIGH && button1State == 1) {
      MIDI_TX(0x90, 1, 127);
      button1State = 0;
    }
    if(button1Val == LOW && button1State == 0) {
      MIDI_TX(0x90, 1, 0);
      button1State = 1;
    }
   
  //BUTTON 2
  //BUTTON 3
  //BUTTON 4
 
  }


This would, of course, be incorporated with the rest of the code (that i posted already earlier in this thread).
I was adapting it from some one else's code and they have used their code to connect ONE button via MIDI, but i want to connect FOUR and use SERIAL. (right?)

In the code i have written only the void loop for the Button 1, but i would then copy it and adapt for the rest of the buttons.

i am really unsure about the "MIDI_TX(0x90, 1, ...)" lines...

I would like that the buttons are assignable to some midi event in the software (ableton, or Logic,...) like Play, Effect On, trigger sample,...

Would something like this work?

Thanks!
=)

Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Apr 01, 2012, 12:00 pm
How are the buttons wired exactly? Do you have an external pull up resistor?
The best way is to wire the button between the pin and ground and enable the internal pull up resistor.
Then you will read a LOW when it is pushed and a HIGH when it is not.

The code looks OK at first glance all be it a bit turgid. I would not bother about debounce at this stage as you will probably not need it in the end.

Quote
i am really unsure about the "MIDI_TX(0x90, 1, ...)" lines...

Here you put the MIDI message you want to send. 0x90 is note on for channel 1, you are best using something useful here like a CC message. Look up what bytes constitute one of these.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Apr 01, 2012, 01:36 pm
i had the buttons plugged like this in the button tutorial here in the arduino.cc forums.
I looked now what the internal pullup resistors are and indeed it seems a better solution.

So would it be right to connect the like:

pin1 ---> pin 8 in Arduino
pin2 ---> ground

and use a code like this?

Quote
int button1Pin = 8;

//BUTTON 1 (Connected to pin 8 )
void setup() {
  pinMode(8, INPUT);      //Input pin for Button 1 in Breadboard
  digitalWrite(8, HIGH);  // Activates internal resistor in Pin 8
}

void loop() {

  if(digitalRead(8 ) = LOW){
  MIDI_TX  // HOW CAN I NOW SEND CC MESSAGE?
  }
}


i also read that the MIDI has 4 defined Controller Numbers defined as "General Purpose Buttons".
They are the controllers 80, 81, 82 and 83.
How could i use them?
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Apr 01, 2012, 06:56 pm
Quote
So would it be right to connect the like:

Yes that and the code is fine.

Quote
Control Change.
1011nnnn    
0ccccccc
0vvvvvvv    

This message is sent when a controller value changes. Controllers include devices such as pedals and levers. Controller numbers 120-127 are reserved as "Channel Mode Messages" (below). (ccccccc) is the controller number (0-119). (vvvvvvv) is the controller value (0-127).


So to send a controller change on channel 1 to controller 80 (decimal?) with a value of on:-
MIDI_TX(0xb0, 80, 127);
and for off:-
MIDI_TX(0xb0, 80, 0);


Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Apr 06, 2012, 11:42 am
So, today i had some time off so i came back to the Xilophone project.

i am now working on having the buttons working.
The idea is to have 4 button assignable to any button,sample,..., in the music software, like for instance play, rec, trigger a sample, start an FX, mute, solo...

i have the button plugged to the arduino in pins 8,9,10, and 11 and i am using the internal pull up resistors.
this is the code i am using is this:
Quote
int button1Pin = 8;
int button2Pin = 9;
int button3Pin = 10;
int button4Pin = 11;

void setup() {
  pinMode(8, INPUT);      //Input pin for Button 1 in Breadboard
  digitalWrite(8, HIGH);  // Activates internal resistor in Pin 8
  pinMode(9, INPUT);      //Input pin for Button 2 in Breadboard
  digitalWrite(9, HIGH);  // Activates internal resistor in Pin 8
  pinMode(10, INPUT);      //Input pin for Button 3 in Breadboard
  digitalWrite(10, HIGH);  // Activates internal resistor in Pin 10
  pinMode(11, INPUT);      //Input pin for Button 4 in Breadboard
  digitalWrite(11, HIGH);  // Activates internal resistor in Pin 10
}

void loop() {
// BUTTON 1 (Connected to pin 8, CC channel 80)
  if(digitalRead(8) = LOW){
    MIDI_TX(0xB0, 80, 127);
  }
 
// BUTTON 2 (Connected to pin 9, CC channel 81)
  if(digitalRead(9) = LOW){
    MIDI_TX(0xB0, 81, 127);
  }
 
// BUTTON 3 (Connected to pin 10, CC channel 82)
  if(digitalRead(10) = LOW){
    MIDI_TX(0xB0, 82, 127);
  }

// BUTTON 4 (Connected to pin 11, CC channel 83)
   if(digitalRead(11) = LOW){
    MIDI_TX(0xB0, 82, 127);
  }
}


and the MIDI_TX that i am using for the whole code is:
Quote
void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY)
{
  status = MESSAGE + midichannel;
  Serial.write(status);
  Serial.write(PITCH);
  Serial.write(VELOCITY);
}


Today i plugged everything in.
The piezo disks are working fine!  =)
The buttons are working but there is one problem. Each time i press a button it send a message CONTINUOUSLY without stopping.
How could i change it so it will send a message when i push it down, and then wait and send again another message ONLY when i press the button again?

I have tried a couple of times to write something using a "buttonState" var, but i didn't manage to make it work.
Any ideas or pointers in the right direction?

Thanks
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Apr 06, 2012, 02:04 pm
Quote
Each time i press a button it send a message CONTINUOUSLY without stopping.

Yes that is what your code has been written to do.
By the way can you post code using the # icon not the quote one next to it. It will stop smillies appearing in your code.

What you have to do is to remember the state of your button push just before you exit the loop() function, in a variable, call it something like lastState. Then only send your MIDI when current state is LOW and the lastState was HIGH.
Do your digital reads into a variable rather than directly in the if statement, then this is easy.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Apr 06, 2012, 06:08 pm
ai, ai, ai...

i think i understand the idea...   but i can't really make it work!!!
i was trying it with the LED from pin13 in the arduino with just one button from pin8.

in the end i came to a code that seems to work but i am worried on how it would work with more buttons.
Please let me know what you think about this:
Code: [Select]
int lastState = HIGH;

void setup() {
  pinMode(13, OUTPUT);   
  pinMode(8, INPUT);     
  digitalWrite(8, HIGH); 
}

void loop() {
  bool buttonState = digitalRead(8);
  if (buttonState == LOW && buttonState != lastState) {
    digitalWrite(13, buttonState);
    delay(1000);
    lastState = LOW;
  }
  else {
    digitalWrite(13, buttonState);
    lastState = HIGH;
  }
}


where there is now the digitalWrite on pin 13 and the delay, i would then replace it with the MIDI_TX (    MIDI_TX(0xB0, 80, 127);   )   that i am using with the rest of the code.

Would this be an effective way to do it?
When i change for the MIDI messages what should i have inside the else? Just "lastState = HIGH;"?

Thank you
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Apr 06, 2012, 06:29 pm
Quote
i have inside the else?

nothing.

Quote
bool lastState = HIGH, currentState;

void setup() {
  pinMode(13, OUTPUT);   
  pinMode(8, INPUT);     
  digitalWrite(8, HIGH); 
}

void loop() {
   currentState = digitalRead(8);
  if (currentState == LOW && currentState != lastState) {
    // do your MIDI stuff here
  }
lastState = currentState;
}

You need currentState and lastState variables for each button you want to monitor.

If you want to be grown up then make these into an array:-
http://www.thebox.myzen.co.uk/Tutorial/Arrays.html (http://www.thebox.myzen.co.uk/Tutorial/Arrays.html)
but if it is too much then just repeat that code.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Apr 07, 2012, 08:25 am
Quote
http://www.thebox.myzen.co.uk/Tutorial/Arrays.html

hey, that was cool reading!!! Of course understanding 100% what it means will take long time, but still i found it really interesting. THANKS!
(and, by the way, when i was looking at the other things there in the website, i found your Hexome. WOW!!! Amazing! i loved it!!! Congratulation)...

Well, after reading your article on arrays, i decided to give it a go.
i tried a couple of times, but in the end when i press the "Verify" button i always get some errors that i cannot fix.
Here is what i have at the moment:
Code: [Select]
bool lastState = HIGH, currentState;

void setup() {
  int buttonPins[4] = { 8, 9, 10, 11 };
  for (int i=0; i<4; i++) pinMode(buttonPins[i], INPUT);
  for (int i=0; i<4; i++) digitalWrite(buttonPins[i], HIGH);
 
}

void loop() {
  for (button=0; button<4; button++) {
    currentState[button] = digitalRead(buttonPins[button]);
  if(currentState[button] == LOW && currentState(button) != lastState(button)) {
    //STILL MISSES MY MIDI_TX HERE
  }
  lastState[button] = currentState[button];
  }
}


and i get the errors
Code: [Select]

sketch_apr07a.cpp: In function 'void loop()':
sketch_apr07a:12: error: invalid types 'bool[int]' for array subscript
sketch_apr07a:12: error: 'buttonPins' was not declared in this scope
sketch_apr07a:13: error: invalid types 'bool[int]' for array subscript
sketch_apr07a:13: error: 'currentState' cannot be used as a function
sketch_apr07a:13: error: 'lastState' cannot be used as a function
sketch_apr07a:16: error: invalid types 'bool[int]' for array subscript
sketch_apr07a:16: error: invalid types 'bool[int]' for array subscript


Well, if i am kind of close maybe i can still try to fix it, if not maybe i need to stay simple (at least for this project) and just repeat the code for the four button.

What do you think?
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Apr 07, 2012, 10:27 am
You have to declare the arrays outside of any function if you want to use them in more than one function. The one declared in setup() will not be valid in loop()
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Apr 07, 2012, 11:43 am
ahhhhhhhhhhhhh, i feel that i am almost there, but i can't understand what is wrong!!!

Code: [Select]
bool lastState = HIGH, currentState;
int buttonPins[4] = { 8, 9, 10, 11 };

void setup() {
  for (int i=0; i<4; i++) {
    pinMode(buttonPins[i], INPUT);
    digitalWrite(buttonPins[i], HIGH);
  }
  Serial.begin(9600);
}

void loop() {
  for (int button=0; button<4; button++) {
    currentState = digitalRead(buttonPins[button]);
    if (currentState != lastState) {
      if (currentState == LOW) {
        //REMEMBER TO CHANGE SERIAL WITH MIDI_TX!!!!!!!!!!
        Serial.println (button);
       }
       lastState = currentState;
     }
   }
}


When i press the buttons i get on the serial monitor "0, 1, 2 and 3", but i get A LOT OF THEM!!!
as long as i am pressing the button there are ALWAYS numbers being printed!

with this code, when i press a button shouldn't the "lastState" be set to "LOW"?
Wouldn't that mean that the next time, if my button is still down, the currentState would be equal to the lastState, and so do nothing...?
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Apr 07, 2012, 09:29 pm
You only have one last state variable and you are over writing it every times round the for loop.
Make the last state and current state variables arrays and access then with the index of the for loop.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Apr 08, 2012, 07:53 am
Yesterday when i read you message
Quote
Make the last state and current state variables arrays and access then with the index of the for loop.

i didn't understand what it meant.
Well, to be honest, i am not sure i already do!!! But, anyway, today when i woke up i had an idea of what it could mean.
So i changed the code like this:
Code: [Select]
bool currentState [4] = { HIGH, HIGH, HIGH, HIGH };
bool lastState [4] = { HIGH, HIGH, HIGH, HIGH };
int buttonPins[4] = { 8, 9, 10, 11 };

void setup() {
  for (int i=0; i<4; i++) {
    pinMode(buttonPins[i], INPUT);
    digitalWrite(buttonPins[i], HIGH);
  }
  Serial.begin(9600);
}

void loop() {
  for (int button=0; button<4; button++) {
    currentState[button] = digitalRead(buttonPins[button]);
      if (currentState[button] != lastState[button]) {
        if (currentState[button] == LOW) {
        //REMEMBER TO CHANGE SERIAL WITH MIDI_TX!!!!!!!!!!
        Serial.println (button);
      }
    }
    lastState[button] = currentState[button];
  }
}


It seems to work ok, but sometimes i still get 2 or 3 values for just 1 button push!
Is there still something missing from the code?
Should there be some kind of debouncing?

When i try to fit this code to the full Xylophone code i get the error:
Quote
Xilophone_with_Buttons.cpp: In function 'void setup()':
Xilophone_with_Buttons:57: error: a function-definition is not allowed here before '{' token
Xilophone_with_Buttons:186: error: expected `}' at end of input

I looked for { } missing somewhere but i can't find any. If it works when it is on it's own sketch, why doesn't it work when i copy and past it into to Xylophone sketch?

i can't find any duplicates, i have put each part of the code to it's right place, but still i get the same error...


HAPPY EASTER!!!  =)
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Apr 08, 2012, 10:16 am
It dosn't work because you are not doing it right.
The error message tells you where the compiler gets mixed up.
It sounds like the compiler thinks you are trying to define a function in the wrong place.
The number 57 is the line number where it got confused, the error is likely to be a line or two before this.
The line numberyou are at is shown in the bottom left corner of the window with your code in.
Tip - if you click so your cursor is just to one side of a { or a ( then the matching one will be highlited. Use this to work out where you are going wrong.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Apr 08, 2012, 01:17 pm
ai, ai, ai...  maybe i have been eating to much chocolate eggs!!! There was, of course, a missing { quite in the beginning.  :smiley-eek:

I found it and then everything worked fine.
i change a couple of lines so the signal from the buttons comes from the MIDI_TX, so now it looks like this:
Code: [Select]
void buttons() {
    for (int button=0; button<4; button++) {
    currentState[button] = digitalRead(buttonPins[button]);
      if (currentState[button] != lastState[button]) {
        if (currentState[button] == LOW) {
          MIDI_TX(0xB0, 80+button, 127);
        }
      }
      lastState[button] = currentState[button];
    }
  }


It seams to be working ok. When i check from the MIDI Monitor (running the serial <> midi converter also) i get this:
Code: [Select]
*** ZERO *** From Xilof OUT Control 1 General Purpose 5 127
*** ZERO *** From Xilof OUT Control 1 General Purpose 6 127
*** ZERO *** From Xilof OUT Control 1 General Purpose 7 127
*** ZERO *** From Xilof OUT Control 1 General Purpose 8 127

one General Purpose button for each of my 4 buttons.

I think it is time to go on to the next stage: adding the 4 potentiometers!
=)
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Apr 08, 2012, 09:38 pm
Have you thought that while those buttons set the CC to 127 what resets this value?
Think about how you want to operate your buttons and what you want them to do.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Apr 09, 2012, 08:18 pm
i had thought that the buttons would be assignable to commands inside Ableton, like for instance Play, Stop or trigger a sample.
In this case the buttons would work fine because one button would be Play and another Stop.
But now that i think of it, if i wanted to assign it for instance to effect On/Off now that wouldn't work.
Hmmm...

i saw that there is a library that allows us to use clicks, double clicks, triple,...
Any experience with it? Do you think i would be able to use to send for instance 127 on a click and 0 on a double click?


Well, today i was trying to get the 4 pots to work. I tries to follow the advices you gave for the last few pieces of code.
I made them into array and i created a "if (potOutput[potnumber] != potLastOutput[potnumber])".
And i was then quite happy when it actually worked!!!  =)
But there is one problem...
i am mapping the 0-1023 from the pot to 0-127 of MIDI. I think sometimes the pot gets "stuck" in a place where the conversion "jumps" between two values. So in the MIDI monitor it happens (not so often) then i turn the knob and even after i stop turning it the value for that pot are changing.
I don't think this would be a big problem, but still, if there is a way to fix it it would be nicer to have things clean.
Do you think making some kind of average would fix it?

This is the code i have now...
Code: [Select]
for (int potnumber=0; potnumber<4; potnumber++) {
  potVal[potnumber] = analogRead(potPins[potnumber]);
  potOutput[potnumber] = map(potVal[potnumber], 0, 1023, 0, 127);
  if (potOutput[potnumber] != potLastOutput[potnumber]) {
    MIDI_TX(0xB0, 7+potnumber, potOutput[potnumber]);
    potLastOutput[potnumber] = potOutput[potnumber];
  }
}
}
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Apr 09, 2012, 09:01 pm
Quote
In this case the buttons would work fine because one button would be Play and another Stop.

Are you sure?
Push play - it starts push stop - now play and stop are both on, how do you play again?
Sure it depends on how you system responds to it but is sounds to me like it will be on all the time.

Quote
And i was then quite happy when it actually worked

Well done.  :)

Quote
sometimes the pot gets "stuck" in a place where the conversion "jumps" between two values

Yes this is what happens with any A/D converter, it is called dithering and happens due to the natural noise in a system.
I think the best way round it is to test for any change on the raw value you read. But not only that only when a change is greater than say 4. To do this you would use a test like this:-
Code: [Select]
if(abs(oldValue - newVlaue) > 4) .....
In other words you subtract the two and remove any negative sign by using the abs() function, abs stands for absolute value.
Of course you would do it with arrays if you are doing four in one loop.
Only then map the newValue to the MIDI range and send it.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Apr 09, 2012, 10:45 pm
i was looking at the library ClickButton.
Maybe this would be a nice solution and with 4 buttons i could actually control thing better that with just one simple click per button.
i have never used a library before, but i think thing didn't go so bad.

i wrote something like this...
Quote
#include "ClickButton.h"

int buttonPin1=8;
int ledPin=13;

ClickButton button1(buttonPin1, LOW, CLICK_PULLUP);
int lastClickCode1=0;

void setup() {
  pinMode(buttonPin1, INPUT);
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  button1.Update();
  if(button1.click == CLICK_SINGLECLICKED && button1.click != lastClickCode1){
    Serial.println("1");}

  else if(button1.click == CLICK_SINGLEHOLD && button1.click != lastClickCode1){
   Serial.println("2");}
lastClickCode1 = button1.click;
}


Nothing too complicated. for each button two options: simple click or click+hold.
simple click i could then assign to cc and 127 and click+hold to 0.  Like this i could have On AND Off in just one button.

The problem is that when i try to get it done for the four buttons with arrays i get all mixed up!!!!  Maybe i eat too much easter chocolate eggs!!! :smiley-roll:
It starts already in the beginning with "ClickButton button1(buttonPin1, LOW, CLICK_PULLUP);"...


ai, ai, ai...
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Apr 09, 2012, 10:54 pm
Quote
i was looking at the library ClickButton.

The problem with using libraries like this for simple functions is that you are not in control of what is happening and when it doesn't do what you want you are stuck.
What is wrong with sending the 127 value when you press the button and 0 when you release it?
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Apr 10, 2012, 12:29 pm
well, i think you are right. Maybe it is smarter to have a way to send also value 0.
I played around with the ClickButton library and manage to make to buttons work so that 1 click sends 127 and Click+Hold sends value 0.
i didn't manage to make it into an array yet, but i'll still give it another go.
putting the "ClickButton button1(buttonPin1, LOW, CLICK_PULLUP);" from the beginning into the arrays is confusing me, but there is no hurry, the "firmware" can always be updated when i know enough coding to do it!   ;)

So, let me recall what is working so far:
the 8 piezos,
the 4 assignable buttons (with click and click+hold),
the 4 potenciometers;

But now i have one other question for a 5th button.
There is a defined array of notes for the piezos
Quote
unsigned char PadMajor[8] = {60,62,64,65,67,69,71,72};


what i would like to do, would be to have 3 Scales (or modes) that i can chose with a button.
To have a major scale, a minor scale, and maybe a Pentatonic Scale or a Prhygian Mode.
It would start with Scale1 (major). Each button click would make it to the next scale. Each button Hold would change it into the previous scale.

Finding the midi note numbers is no problem. (maybe not so easy to decide which mode i want to have!!!   8)  )

i imagine it could work like this:
i make a new button than can control a "mode" variable.
when mode is equal to 1 the scale to be played is PadMajor. mode 2 = PadMinor and mode 3 = PadPentatonic.

But now imagining it and doing it are very different things...
Is an array "loopable"?
Let's say
for (int mode=0; mode<3; mode++)   -  when mode is equal to 3 if i would use something like "mode++) would it go back to 1 or would it continue to 4?

How can i connect two separate parts of the code, the one with the button defining the "mode" with the one that is telling which notes to play?

Ahhhh...    :~   i think i am at a stage now where i can understand some of the concepts involved with programing, but i cannot use them yet. i can understand for instance that with variables we can connect things, but then when i try to use them everything get's mixed up along the way...
well, i guess i cannot ask to learn it all in two weeks! With time i'll get there.
Until then, i am lucky to have this form to push me in the right directions!  Thanks!
=)

Let's get this last button working...  then it's time to start building everything!  =)
And PLAY!!!  =)
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Apr 10, 2012, 06:40 pm
Quote
would it go back to 1 or would it continue to 4?

It would be 4.

Quote
Is an array "loopable"?

No idea what you mean. I like to think of an array as being a variable with a name that is a variable. That is it allows the same code to operate on different variables.

Getting to know what you want to do is half the battle. You have done very well so far, you should be very pleased with yourself. There is always more to learn, that's the fun.  :)
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Apr 10, 2012, 08:26 pm
by "loopable" i meant if if will continue to four or if after the last value in the array it will "loop" back to the first. So if we add always (++) it would "loop" through the values inside the array.
But i made a couple of experiments and it seems it's not like that.

Well, anyway, i have good news!!!
I think now EVERYTHING is working!  8)

Surely it is not the most elegant nor the most genial code, but hey, it is getting the job done!
This will be the V1.0 of (maybe) several to come...   ;)

Now the piezos are working, the buttons and the pots also and the button is also enabling us to choose from Ionian (major), Aeolian (minor) and Major Pentatonic Modes.

Now it is time to try to plug it to some music software and get some sound from it!!!
Also time to start thinking about building a nice "real music instrument" (maybe out of wood).


== = = = == === ==== == = = =
i have still one more question that just came to my mind.
i thought a couple of times that it could be useful to have a little led somewhere blinking whenever there is some "communication", like the TX led in the Arduino Board.
How could i do this?
I noticed that there is a pin in the board (digital pin 1) where it also reads TX. Could i use it?


Thank you!
=)
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Apr 10, 2012, 08:49 pm
Quote
a pin in the board (digital pin 1) where it also reads TX. Could i use it?

Yes you could but as it has to drive the USB to serial converter chip then don't load it too much. An LED with a 1K would be best.

Quote
So if we add always (++) it would "loop" through the values inside the array.

Still not sure but:-
Code: [Select]

index = 0;
while(conditionIsTrue){
array[index++] = // something
if(index > indexLimit) index = 0;
// do something else
}

Would work. The index++ is called post incrementing, that is the operation is performed and then the value index is incremented. The inverse is pre indexing
Code: [Select]
array[++index] = // something
Here the value index is incremented before doing the operation with array.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Apr 15, 2012, 04:29 pm
hmmm, i have been looking on information on how to make the "external TX indicator" work (i mean, an LED that blink as the onboard TX LED), but i don't seem to find it...

When i connect an LED with a 1k resistor to the pin1 on the Arduino, the LED is ALWAYS on (but not the onboard TX one). i didn't even add it to the sketch, i just connected it and it came on.

Any ideas where i can find information on how to do this?

= = = = = =

Another question...

Every time i have built something with the Arduino i have used breadboards.
Now that the MIDI Xylophone is getting ready i start to think on the "building it" side of things to make a more defenitive version that i can actually play, take with me to rehearsals,....
The design, what wood to use and what kind of "enclosure" i want to make, ...
But then it came to my mind: do i need to solder things to the ARDUINO?
If i am using some kind of protoboard where i solder/connect all the components in the project, how do i then connect them to the Arduino's pins?
Should i use the same kind of jumper wires that plug in the pins and then solder the other end to the protoboard?

Thank you
=)
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Apr 15, 2012, 10:43 pm
Quote
When i connect an LED with a 1k resistor to the pin1 on the Arduino, the LED is ALWAYS on

Yes it will be. That is because the normal state of the logic line on a serial port is a logic one. Therefore you will see the LED lit. If you want it the other way round then you must connect the LED and resistor between +5V and the pin1. In that way you sink the current ( as opposed to sourcing it ) and when something is transmitted the LED is lit up. As you had it the LED is turned off when something is sent and it is hard to see any change in a lit LED going briefly off, where it is easy to see an unlit LED going briefly on.

Quote
But then it came to my mind: do i need to solder things to the ARDUINO?

Yes, or at least solder things to pin headers that you plug into the arduino.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Apr 28, 2012, 04:14 pm
So i have been waiting (IMPATIENTLY) for some parts to arrive in the post...

Meanwhile, and because this project keeps popping in my head, i decided to try to draw a schematic of the whole thing. (Who knows, maybe one day someone wants to build something like it...).

I had already fritzing, so i gave it a go making a Breadboard representation of what i have.
I came to this:

(http://img69.imageshack.us/img69/9126/xylophonebbsmall.jpg)

But then i decided to try to make areal schematic!!!
Ai, ai, ai...
I think i cannot even READ a schematic properly, much less draw one...
Anyway, i thought this would be a good way to learn a couple more things. I looked around the net and it seemed that Eagle was a choice many people make so, i decide to try it out (it helped that they have a freeware version!).
But, of course, soon in the process the problems/doubts started.

At the moment i have this:
(http://img40.imageshack.us/img40/4647/poposchem.jpg)
Would this be the right way to draw the schematic for the diode/res/piezo part?
(i made only two, so then i don't need to delete them all again and remake them the right way...  ;)  )

Do you know any "exercises" site to learn how to read/draw schematics?


= = =
I have now wired the TX LED as you suggested (to +5v instead of ground) and it is working fine. Thanks!!!

=)
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: Grumpy_Mike on Apr 28, 2012, 04:34 pm
There is no right way of drawing a schematic but there are a number of conventions that make reading one easier.
Ground at the bottom, positave at the top, signal flow from left to right.
Drawn with the minimum number of crossing wires. Eagle makes this hard because of the fixed pin distribution of a chip's outline. Better packages allow you to change where abouts each pin appeares on a package.

On your example it is hard to see that the 1M is across the sensor and ground, and the diode looks the wrong way round.
Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on May 18, 2012, 09:18 am
So, it is now almost 2 months since i started this project but i am now happy to tell you that it's completed!
Yesterday i had some time and i finished it, tried it, and enjoyed a nice project done!   =)

I have to thank you all for the help you gave me. In many of the steps of this project i felt quiet lost, but there was here always some one ready to point me in the right direction.
THANKS!!!  :)

Here are some pictures of the final thing.
I call it PöPö (MIDI Xylophone)
(http://img10.imageshack.us/img10/3528/popoxyl.jpg)

There are, surely, many things that could be improved. The code could be much tidier and elegant (but i still need to learn a lot before i can do it), some practical things could be improved (i would now maybe put 8 buttons and 8 pots, i would like to make the piezos more sensitive,...), it would be cool to have a small LCD showing in which mode/scale we are playing (now there is just a LED showing mode 1, 2 or 3), and, many more...
But this is Version 1.0, maybe more to come one day...

I will now try to make a PDF with the "instructions" on how to build it, schematic, code,...  Who knows, maybe one day someone else will be interested in making he's own...
;)

Title: Re: MIDI Xilophone (over serial) to Ableton
Post by: boguz on Feb 15, 2013, 05:50 pm
I have made a little website talking about this project.
It was just for me to try a couple of webdesign ideas i had, but still, now i kind of like it, do i decided to put it online.

You can check it out here: http://popo.webatu.com

There you can see some photos, read about the main characteristics of the Xylophone, and see how to make your own (there is list of materials, schematics, code and explanation,...)

Hope you enjoy it.

And, once again, thank you for all the help you guys gave me with this project!
=)