USBMIDI and Xbee

18 Feb 2012

Hi, I am currently trying to get an mbed to receive a signal from an xbee, and then use the USBMIDI library to talk to the computer. do the Xbee serial and the USBMIDI serial programs conflict? I can get everything to work, except having the two combined. if USBMIDI is included in the code it no longer works

#include "mbed.h"
#include "USBMIDI.h"
//all midi code required
/*void show_message(MIDIMessage msg) {
    switch (msg.type()) {
        case MIDIMessage::NoteOnType:
            printf("NoteOn key:%d, velocity: %d, channel: %d\n", msg.key(), msg.velocity(), msg.channel());
            break;
        case MIDIMessage::NoteOffType:
            printf("NoteOff key:%d, velocity: %d, channel: %d\n", msg.key(), msg.velocity(), msg.channel());
            break;
        case MIDIMessage::ControlChangeType:
            printf("ControlChange controller: %d, data: %d\n", msg.controller(), msg.value());
            break;
        case MIDIMessage::PitchWheelType:
            printf("PitchWheel channel: %d, pitch: %d\n", msg.channel(), msg.pitch());
            break;
        default:
            printf("Another message\n");
    }
}
*/
//USBMIDI midi; //  ********HERE IS WHAT MAKES THE CODE NOT WORK

Serial taps(p9, p10);
//Serial debug(USBTX, USBRX);

int RT_Note=55;
int RH_Note=80;
int LT_Note=67;
int LH_Note=40;

DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);



/*void R_Toe() {
    midi.write(MIDIMessage::NoteOn(RT_Note,127,2));
    wait_ms(10);
}
void R_Heel() {
    midi.write(MIDIMessage::NoteOn(RH_Note,127,2));
    wait_ms(10);
}
void L_Toe() {
    midi.write(MIDIMessage::NoteOn(LT_Note,127,2));
    wait_ms(10);
}
void L_Heel() {
    midi.write(MIDIMessage::NoteOn(LH_Note,127,2));
    wait_ms(10);
}

*/
int main() {
  //  debug.baud(57600);
    taps.baud(57600);

    while (1) {
        led1=!led1;
        wait_ms(5);
        led1=!led1;
        char tap = taps.getc();
        if (tap == 'A') {
           // debug.putc(tap);

            led1 = !led1;
           // midi.write(MIDIMessage::NoteOn(RT_Note,127,2));

            wait_ms (10);

        }
        if (tap == 'B') {
           //debug.putc(tap);


            led2 = !led2;
          //  midi.write(MIDIMessage::NoteOn(LH_Note,127,2));
            wait_ms (10);
        }
        if (tap == 'C') {
           // debug.putc(tap);

            led3 = !led3;
           // midi.write(MIDIMessage::NoteOn(RH_Note,127,2));
            wait_ms (10);
        }
        if (tap == 'D') {
            //debug.putc(tap);

            led4 = !led4;
           // midi.write(MIDIMessage::NoteOn(LH_Note,127,2));

            wait_ms (10);
        }


    }

}
10 Apr 2012

Hi Jacob.

I know it's been almost two months since your question, but yesterday I did a little test program with the USBMIDI lib and I have a "similar" problem.

First of all: Have you fixed your problem yet?

If not, did you tried the program just with the default usb connector? or after you downloaded the fw to the mbed you connected it through the D+D-?? (I haven't tested your code by myself, I'm on work now).

I don't have your configuration, instead i have the MPR121 touch keypad form sparkfun (http://www.sparkfun.com/products/10250) connected to emulate a drumset for my first test. When it was connected trough the mbed usb connector the program didn't work, but when I conected it trough the D+D- it works.

The problem that I have now is that when I press one button on the keypad and generates an interrupt the program stops working at all. I think today I'm gonna have some time to test other simple interrupt to see if the usbmidi is the problem or it's between the keyboard and the chair.

Well maybe my post is not very usefull for now... I'm going to be edditting this with my future tests.

Good luck.

Rolando.

Edit 1

Well i got it working now... the problem was a "Wait(0.25);" in the isr... not sure why yet..