Pages: [1]   Go Down
Author Topic: Arduino Micro and MIDI Library  (Read 1079 times)
0 Members and 1 Guest are viewing this topic.
Stockholm
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I recently bought a Arduino Micro board. I intent to use it for a midi footcontroller project. I tried a few basic sketches and the confirmed the board functions OK.

I want to use Franky's MIDI library for this project. The midi over serial is also an other option. Anyways, I tried a few basic codes for sending the midi message, but non of them working. Do I need to modify the code especially for arduino MICRO? All documentation on arduino Micro is based on Leonardo board, and it seems like some parts are out of date or doesnot really apply to MICRO board. I would really appreciate any help on this.

Midi out; pin3 goes to arduino ground, pin4 goes to 5v with a 220ohm resistor, pin5 goes to arduino TX with a 220ohm resistor.

Button is connected to arduino digital 2.

I tested the following codes but

The first code I tried:
Code:
#include <MIDI.h>

// set pin numbers:
const int ledPin =  13;      // the number of the LED pin

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);     
  MIDI.begin(); 
}

void loop(){

    MIDI.sendNoteOn(42,127,1);
    delay(1000);  
    MIDI.sendNoteOff(42,0,1);
    delay(1000);
    MIDI.sendNoteOn(25,127,1);
    delay(1000);  
    MIDI.sendNoteOff(25,0,1);
    delay(1000);
  }
This code is constantly sending note on/off messages but midi in monitor displays nothing.

The second code is to send to note when a button is pressed. The led flashes when is pressed.
Code:
#include <MIDI.h>

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);     
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  MIDI.begin(1); 
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) { 
    digitalWrite(ledPin,HIGH);
    MIDI.sendNoteOn(42,127,1);  // Send a Note (pitch 42, velo 127 on channel 1)
    delay(1000);         // Wait for a second
    MIDI.sendNoteOff(42,0,1);   // Stop the note
    digitalWrite(ledPin,LOW);
  }
}
Button is working and the led is flashing when it is pressed. But again no signal in midi monitor.

The final code I tried is just using serial.write and doesnt include the midi library. This also didnt work. Again No midi signals
Code:
const int button1 = 2;     // the number of the pushbutton pin

int buttonState = 0;       

void setup() {
  pinMode(button1, INPUT);     
  Serial.begin(31250);
}

void loop(){
  buttonState = digitalRead(button1);
  if (buttonState == HIGH) {
    noteOn(0x90, 0x1E, 0x45);
    delay(100);
  }
}


void noteOn(int cmd, int pitch, int velocity) {
  Serial.write(cmd);
  Serial.write(pitch);
  Serial.write(velocity);
}

I checked my midi cable and it is working perfectly. MIDI in port at my soundcard also functions OK with other devices. So all external factors are isolated.

Thanks in advance...
Logged

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

I'm having a similar issue with my UNO.   trying to send MIDI data and I get nothing.  wish I could help.  I'm using the Roland UM1 MIDI/USB cable and MIDIOX, very simple MIDI commands yeild nothing.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I know this post is old, but I was having the same issue and I would have loved to see a solution posted here, since this is the first result I found googling this problem.
Here´s what happens, if you are using Arduino Micro or Leonardo and you want to use the TX pin for a DIN connector, you need to refer to Serial1 instead of Serial.
Here´s how:
Code:
void setup()
{
  Serial1.begin(31250);
}
void loop()
{
//write whatever code you want [...]
    //note ON
    Serial1.write(144); //noteOn channel 1
    Serial1.write(42);  //pitch
    Serial1.write(127); //velocity
    //note OFF
    Serial1.write(144);
    Serial1.write(42);
    Serial1.write(0);
}

Cheers!
Logged

Stockholm
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you. I have completely forgot about this topic.

I have edited the midi.h file in ordet to use the midi library with midi din connected to TX pin on Arduino Micro or Leonardo.

To do that:
1 - Open; MIDI.h with a text editor
2 - Find line; #define USE_SERIAL_PORT   Serial
3 - Replace; Serial with Serial1
4 - Save&Close file

Logged

Pages: [1]   Go Up
Jump to: