Pages: [1]   Go Down
Author Topic: Arduino Midi Problem  (Read 772 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi All,

I'm currently trying to setup a mini midicontroller. I've got a atmega8 in a stk500 development board with the arduino bootloader installed. I've loaded the following program via the ide :

// The switch is on Arduino pin 10:
#define switchPin 10
// Middle C (MIDI note value 60) is the lowest note we'll play:
#define middleC 60
//  Indicator LED:
#define LEDpin 13

// Variables:
char note = 0;            // The MIDI note value to be played
int AnalogValue = 0;           // value from the analog input
int lastNotePlayed = 0;   // note turned on when you press the switch
int lastSwitchState = 0;  // state of the switch during previous time through the main loop
int currentSwitchState = 0;

void setup() {
  //  set the states of the I/O pins:
  pinMode(switchPin, INPUT);
  pinMode(LEDpin, OUTPUT);
  //  Set MIDI baud rate:
  Serial.begin(31250);
  blink(3);
}

void loop() {
  //  My potentiometer gave a range from 0 to 1023:
  AnalogValue = analogRead(0);
  //  convert to a range from 0 to 127:
  note = AnalogValue/8;
  currentSwitchState = digitalRead(switchPin);
  // Check to see that the switch is pressed:
  if (currentSwitchState == 1) {
    //  check to see that the switch wasn't pressed last time
    //  through the main loop:
    if (lastSwitchState == 0) {
      // set the note value based on the analog value, plus a couple octaves:
     // note = note + 60;
      // start a note playing:
      noteOn(0x90, note, 0x40);
      // save the note we played, so we can turn it off:
      lastNotePlayed = note;
      digitalWrite(LEDpin, HIGH);
    }
  }
    else {   // if the switch is not pressed:
    //  but the switch was pressed last time through the main loop:
    if (lastSwitchState == 1) {
      //  stop the last note played:
      noteOn(0x90, lastNotePlayed, 0x00);
      digitalWrite(LEDpin, LOW);
    }
}

  //  save the state of the switch for next time
  //  through the main loop:
  lastSwitchState = currentSwitchState;
}

//  plays a MIDI note.  Doesn't check to see that
//  cmd is greater than 127, or that data values are  less than 127:
void noteOn(char cmd, char data1, char data2) {
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
  Serial.print(data2, BYTE);
}

// Blinks an LED 3 times
void blink(int howManyTimes) {
  int i;
  for (i=0; i< howManyTimes; i++) {
    digitalWrite(LEDpin, HIGH);
    delay(100);
    digitalWrite(LEDpin, LOW);
    delay(100);
  }
}


The led's goes on whenever I press the play note button. I've got it all connected to my pc using the serial port. I've tested the serial port with another program and it works fine. I installed the Roland midi/serial driver and got the settings to the correct comport.

Now what ? I've tried various programs that can see midi input such as fruity loops and even a midi monitor but I don't get anything. Any ideas on what I'm doing wrong ?

Thanks,
Tom
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Since that looks to be the standard Arduino midi code that I know works, I suspect that the problem lies with the serial to midi driver. Believe me, I've tried them all (well three or four - there may be one or two I missed) and none were what I'd call satisfactory. The big question is - are you seeing anything in the serial port monitor in the IDE? If so something's not right with the serial to midi driver - I wish I could give you some more specific but it's been a while since I've done anything midi related and from what I remember the problems I had  were just the usual frustrating driver flakiness stuff.

You could also try this: http://www.memeteam.net/2007/s2midi/ It's a converter that runs as a standard user program rather than a driver. It's seems a bit primitive but it might be useful for testing.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I checked the output in the serial port monitor and there is an output visible. So I take it the driver is not working ?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I remember having a wiring problem when trying to run midi.

In the example from http://itp.nyu.edu/physcomp/Labs/MIDIOutput, they use a female midi adaptor. I used a male midi adaptor, so all the pins were mirror images. I had to invert the 5v and the TX connections to make it work.

Also, perhaps you could use a USB interface for your midi. On mine, every time I send a valid signal, there's a led that blinks to show activity, which helps on debugging. Also, the usb port is easier to use with midi tracking programs.
Logged

Glasgow, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think your problem is in the serial speed. Although MIDI is indeed 31500, the old MIDI/serial drivers actually communicate at 38400, as the 31500 rate is not a "native" speed of the RS232 ports on PCs. Be aware that these drivers add some extra stuff into the data stream to manage MIDI ports and avoid buffer overflows due to the data rate differences - but that should only be relevant if you try to send MIDI data *to* the arduino.

Martin
Logged

Grenoble/Lyon - France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 363
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you're using the arduino as a USB midi controller, I think you should write a little sketch in processing that will pass the serial data into midi messages using the ProMidi library.
It's really simple to use.
If you're under windows, you might have to use midiYoke to have your midi messages sent from processing to your audio apps.
It worked fine for me (arduino > serial > processing > midi > midiyoke > ableton).
Logged


Pages: [1]   Go Up
Jump to: