Go Down

Topic: Problem with sending MIDI CC messages (Read 4686 times) previous topic - next topic

Nantonos

#15
Oct 23, 2012, 06:22 pm Last Edit: Oct 23, 2012, 06:26 pm by Nantonos Reason: 1
Yes, I do have te Rugged Circuits Flexible MIDI shield, although after realising that it was not (despite what the product page says) actually compatible with the Mega, I had stopped trying to use it because it would not fit my current project.

Anyway I also have a UNO so I took your code and ran it on the UNO with the RC MIDI shield. I made some changes to tid things up, corect types, what seemed to e to be better vatriable names, more comments with links. And I actually used the MIDI Library (your code includes MIDI.h but does not actually call any of the functons in the library).

I ran it, connecting MIDI Out to the MIDI In on by audio interface and then using MIDI OX to view the results. This was the code:

Code: [Select]
// Read multiple potentiometers and send the results over MIDI out.
// from
//   http://arduino.cc/forum/index.php/topic,117264.0.html
// adapted to actually use the MIDI library :)

#include <MIDI.h>
// MIDI library
//  class reference http://arduinomidilib.sourceforge.net/a00001.html
//  download http://arduinomidilib.sourceforge.net/files.html
#define COMPILE_MIDI_IN         0     // Set to 1 to use MIDI input.
#define COMPILE_MIDI_OUT        1     // Set to 1 to use MIDI output.
#define COMPILE_MIDI_THRU       0     // Set out and in to 1, and this to 1, enables MIDI passthru

// Values for Rugged Cicuits Flexible MIDI sheild
// http://ruggedcircuits.com/html/flexible_midi_shield.html
// Jumpers:
//   Rx on D0
//   Tx on D1
//   MIDI enable on D12
// MIDI enable pin, avoids conflict of Serial between USB for programming and DIN MIDI I/O
#define MIDI_ENABLE 12

// Variables:
static int input_nb = 2; // select number of desired analog inputs (max 6 for Uno)
int AnalogValue[2] = {0,0}; // raw analog readings
byte lastCValue[2] = {255,255}; // previous controller values
// select the midi Controller Number for each input (22 to 31 are free)
// for list, see
//  http://www.midi.org/techspecs/midimessages.php#3
byte midiCCselect[2] = {22,23};
byte cc; // Analog reading converted to 7 bit value
byte channel = 1; // MIDI channel number from 1 (not 0) to 16

void setup() {
 //  launch MIDI
 MIDI.begin();
 // enable MIDI
 pinMode(MIDI_ENABLE, OUTPUT);
 digitalWrite(MIDI_ENABLE, HIGH);
}

void loop() {
 for (int i =0; i < input_nb; i++) {
   //  Arduino ADC gives values in range 0 to 1023
   AnalogValue[i] = analogRead(i);
   //  convert to a control value, range from 0 to 127, for MIDI:
    cc = AnalogValue[i]/8;

   // check if control value has changed from last time
   if (cc != lastCValue[i] ) {
     //send control change on cc#i
     MIDI.sendControlChange(midiCCselect[i], cc, channel);
     // update last controller value to current one
     lastCValue[i] = cc;
   } //  end if

 }  //  end for
}


Aaaand - no output whatsoever.

To check the program flow I then made a debug version - instead of outputing MIDI it send lots of chatty debug messages to Serial. This is the code:

Code: [Select]
// Read multiple potentiometers and send the results over MIDI out.
// from
//   http://arduino.cc/forum/index.php/topic,117264.0.html
// adapted to actually use the MIDI library :)

#include <MIDI.h>
// MIDI library
//  class reference http://arduinomidilib.sourceforge.net/a00001.html
//  download http://arduinomidilib.sourceforge.net/files.html
#define COMPILE_MIDI_IN         0     // Set to 1 to use MIDI input.
#define COMPILE_MIDI_OUT        1     // Set to 1 to use MIDI output.
#define COMPILE_MIDI_THRU       0     // Set out and in to 1, and this to 1, enables MIDI passthru

// Values for Rugged Cicuits Flexible MIDI sheild
// http://ruggedcircuits.com/html/flexible_midi_shield.html
// Jumpers:
//   Rx on D0
//   Tx on D1
//   MIDI enable on D12
// MIDI enable pin, avoids conflict of Serial between USB for programming and DIN MIDI I/O
#define MIDI_ENABLE 12

// Variables:
static int input_nb = 2; // select number of desired analog inputs (max 6 for Uno)
int AnalogValue[2] = {0,0}; // raw analog readings
byte lastCValue[2] = {255,255}; // previous controller values
// select the midi Controller Number for each input (22 to 31 are free)
// for list, see
//  http://www.midi.org/techspecs/midimessages.php#3
byte midiCCselect[2] = {22,23};
byte cc; // Analog reading converted to 7 bit value
byte channel = 1; // MIDI channel number from 1 (not 0) to 16

void setup() {
 //  launch MIDI
 //MIDI.begin();
 Serial.begin(57600);
 // enable MIDI
 //pinMode(MIDI_ENABLE, OUTPUT);
 //digitalWrite(MIDI_ENABLE, HIGH);
}

void loop() {
 for (int i =0; i < input_nb; i++) {
   //  Arduino ADC gives values in range 0 to 1023
   AnalogValue[i] = analogRead(i);
   Serial.print("AnalogValue[");
   Serial.print(i, DEC);
   Serial.print("] = ");
   Serial.println(AnalogValue[i]);
   
   //  convert to a control value, range from 0 to 127, for MIDI:
    cc = AnalogValue[i]/8;
   Serial.print("cc = ");
   Serial.println(cc, HEX);

   // check if control value has changed from last time
   if (cc != lastCValue[i] ) {
     //send control change on cc#i
     Serial.println("Changed ===============================");
     //MIDI.sendControlChange(midiCCselect[i], cc, channel);
     // update last controller value to current one
     lastCValue[i] = cc;
   } //  end if

 }  //  end for
 delay(2000);
}


Result - exactly as expected. Code is fine, its just that no MIDI is being sent.

Coincidentally, today my Teensy 3.0 (ARM-based Arduino-compatible) and Teensy 2.0 (AVR-based Arduino compatible) arrived in the post. These have the handy property that as well as using the USB to upload programs, you cn also set it to be a USB keyboard, or a USB mouse, or a generic USB HID device ... or USB MIDI. So I ran the same code on Teensy 2.0, set up as USB MIDI. Here is the code:

Code: [Select]
// Read multiple potentiometers and send the results over MIDI out.
// from
//   http://arduino.cc/forum/index.php/topic,117264.0.html
// adapted to run on Teensy with usbMIDI feature
// http://www.pjrc.com/teensy/td_midi.html


// Variables:
static int input_nb = 2; // select number of desired analog inputs (max 6 for Uno)
int AnalogValue[2] = {0,0}; // raw analog readings
byte lastCValue[2] = {255,255}; // previous controller values
// select the midi Controller Number for each input (22 to 31 are free)
// for list, see
//  http://www.midi.org/techspecs/midimessages.php#3
byte midiCCselect[2] = {22,23};
byte cc; // Analog reading converted to 7 bit value
byte channel = 1; // MIDI channel number from 1 (not 0) to 16

void setup() {
 //  launch MIDI by selecting USB MIDI in the Arduino IDE with Teensyduino installed
 // http://www.pjrc.com/teensy/teensyduino.html
}

void loop() {
 for (int i =0; i < input_nb; i++) {
   //  Arduino ADC gives values in range 0 to 1023
   AnalogValue[i] = analogRead(i);
   //  convert to a control value, range from 0 to 127, for MIDI:
    cc = AnalogValue[i]/8;

   // check if control value has changed from last time
   if (cc != lastCValue[i] ) {
     //send control change on cc#i
     usbMIDI.sendControlChange(midiCCselect[i], cc, channel);
     // update last controller value to current one
     lastCValue[i] = cc;
   } //  end if

 }  //  end for
}



Result - MIDI output to MIDI OX displayed as expected.

I was running the Teensy on a breadboard, maybe that is a bit noisy, because I saw some +- 1 variability in the 7 bit data (so, lots of MIDI messages with very similar values) while on Arduino I was getting genuine 10-bit data with +-1 or maybe 2 variability (so, no actual change when reduced down to 7-bit valuses for MIDI).

But apart from that, the Teensy 2.0 used as USB MIDI just worked as expected, while I couldn't get the RC MIDI sheild using DIN MIDI to either input or output correctly to MIDI OX. Since USB MIDI is faster than the DIN version, as well, this seems like a win all round and I plan to use the Teensy 2.0 in my controller project and consign the Rugged Circuits MIDI shield to the parts bin.

I did not observe the variability that you mentioned. No erratic values at all.

I wonder if you have the pots connected to ground correctly or if you are using them in a very elecvtrically noisy environment?

#16
Oct 24, 2012, 03:03 pm Last Edit: Oct 25, 2012, 02:16 am by HANKENSTIEN Reason: 1
man I just wrote this big reply , and I accidentally hit the back button on my mouse, and lost it all.
I did get the code i posted on here last to work, I found out after buying some new pots for a different project, that all the pots i bought were garbage!, they seem to be pretty smooth with an ohm meter, but? while hooking those up, i had 5 ports working fine with various pot sizes, from 1k up to 20k and even a slider that I don't remember what the resistance value was, I had a button but it appears that it was an always on, so didn't work correctly. so I believe it was the pots, and that also answers the question of does it matter what size pot to use basically no but dont just buy the 10 for a dollar ones!
I believe one reason why the code that works for me doesn't work for you, and the code you give me doesn't work for me, maybe because your using hardware, and im using software (abelton), that's just a guess, but the code does work for me now that i have different pots, but  if i can use your code, and it will still work, then i know its ready for further projects, im waiting on a new patch cable, so i can hook it to my keyboard as we speak.
What was the reason it did not work with the mega? was it because of the location of the midi (din) plugs, or was it another issue?
Im also curious as what to do now that ive used up my six analog inputs, I want to add a few buttons and if possible maybe even more pots? what sort of code is needed to add them on digital pins can I just ad more inputs, at the top of my code and add more CC #'s and use the non-PWM pins, or would I need more code as well?
I am sorry to ask so many questions, but i know that this will help many others as well, because I tried to contact the manufacturers with my code, and they would not even give me a single pointer about any of it they said sorry we do not give code support, yet they don't have much for instructions other than only one jumper in each row, and two sample sketches, witch, are not very helpful.
If you search Google for the rugged circuits flexible midi shield you get their store, these postings, and a you tube video of a guy showing of the rotator, witch he made very nice, but it is just to show his finished piece no code, no explanations etc. so basically their is no support although I did ask we shall see if anything comes of it.
so I do not even know what is specifically required in the code, and I haven even started on the midi in witch would not be part of this project anyway, so Again I thank you for your help.
I have seen the new "arm-duinos" some are even dual core etc, wow the power differences.... plus the built in capabilities, im still learning the basics b4 I jump to those, plus don't have the cash.
One last thing, before you toss your shield in the parts bin, do you have any sketches or code, you'd be willing to share, whether it be 1 or 100 I have a server and a site rduino.com , we can figure out details of how to transfer if ur willing to share, but I figure its worth an ask, before they end up deleted. even if I am the only one who owns this shield it would still be helpful to me and id make them available to all if you so wish.
Anyway thank you again for your time, It is very much appreciated, and even though I believe I have my issue figured out, I am going to study / try your code, as ideally i would like to have a hardware and software suitable code. Plus I hope to learn, thats what its all about :)
Thanks again For your time and effort
HANKENSTIEN
P.S. I gave ya some karma point not sure what you can do with them but, Again thanks

Go Up