October 12, 2024, 09:10:23 AM

Shield-MIDI on UNO R3

Started by deseipel, January 13, 2013, 10:10:00 PM

Previous topic - Next topic

deseipel

Hi, I posted this in the duinoxxx forum, but maybe it applies here. 

I have an UNO r3 with the Olimex Shield-MIDI.  And for the life of me, I can't get it to do anything.  I connect a midi instrument to it and the leds don't even light up.  I've verified (I think) that its getting power (5v). 

its a bit of a challenge since the uno only has 1 serial connection.  I have to remove the shield every time I upload new code.  Also, I've tried using softserial but I believe it wont work since to monitor this, the usb cable would have to be connected? 

I'm trying to simply send program changes upon the reception of a specific note value.

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX


#include <MIDI.h>
// set NRPN to set volume to zero for part xyz
// read existing program/patch number ???
// send stop control

void HandleNoteOn (byte channel, byte note, byte velocity){
  int program =0;  //program or patch always begins at 0

    //if note1 or note2 is sent, send program change control to go up or down
  if (note == 0x15){   //need to get the actual note number that I'll assign
    MIDI.sendProgramChange((program++),10);
  }
  if (note == 0x16){  //need to get the actual note number that I'll assign
    MIDI.sendProgramChange((program--),10);
  }
}
//if note3 is sent, send nrpn to set volume to zero  (not implemented yet)


void setup() {
  // set the data rate for the SoftwareSerial port
  mySerial.begin(38400);
  mySerial.println("MIDI Setup");


  int program =0;  //program or patch hardcoded to begin at zero
  MIDI.begin(MIDI_CHANNEL_OMNI);  //listen to all channels
  MIDI.setHandleNoteOn(HandleNoteOn);
  MIDI.sendProgramChange((program),10);   //channel is hard coded to 10 for now
}

void loop () {

  MIDI.read();
  if (mySerial.available())
    mySerial.write(MIDI.read());

}







deseipel

update:  I located the RXD_E jumper and figured out that I can simply remove it to upload to the UNO.  Also, I can turn on the green and red LEDs, but thats about it. 

I'm using midiox to try to send midi data to the shield and I'm getting nothing returned, LEDs won't light.





#include <MIDI.h>
// set NRPN to set volume to zero for part xyz
// read existing program/patch number ???
// send stop control

int ledPinRed = 06;                 // LED connected to digital pin 6
int ledPinGrn = 07;                 // LED connected to digital pin 7

void HandleNoteOn (byte channel, byte note, byte velocity){
  //int program =0;  //program or patch always begins at 0

    //if note1 or note2 is sent, send program change control to go up or down
  //if (note == 60){   //need to get the actual note number that I'll assign
   // MIDI.sendProgramChange(1,10);
      digitalWrite(ledPinGrn, HIGH);   // sets the LED on
  delay(1000);      // waits for a second;
      digitalWrite(ledPinGrn, LOW);   //set the LED off
  //}
  //if (note == 62){  //need to get the actual note number that I'll assign
   // MIDI.sendProgramChange(2,10);
   //   digitalWrite(ledPinRed, HIGH);   // sets the LED on
  //delay(1000);                  // waits for a second;
    //  digitalWrite(ledPinRed, LOW);  //set the LED off
//  }
}
//if note3 is sent, send nrpn to set volume to zero


void setup() {
pinMode(ledPinRed, OUTPUT);      // sets the digital pin as output
pinMode(ledPinGrn, OUTPUT);      // sets the digital pin as output
   
  //int program =0;  //program or patch hardcoded to begin at zero
  MIDI.begin(MIDI_CHANNEL_OMNI);
  MIDI.setHandleNoteOn(HandleNoteOn);
//  MIDI.sendProgramChange((program),10);   //channel is hard coded to 10 for now
}

void loop () {

  MIDI.read(); //is there incoming MIDI?
 
  // LED Tests
  //digitalWrite(ledPinGrn, HIGH);   // sets the LED on
  //delay(1000);                  // waits for a second
  //digitalWrite(ledPinGrn, LOW);    // sets the LED off
  //delay(1000);                  // waits for a second



}





deseipel

Anyone out there?  This still doesn't work and I'm about ready to return it.

MIDI OUT & THRU has 5v on pins 4,5.   

LubOlimex

Hey desipel,

Try this code:



// defines for MIDI Shield components only
#define KNOB1  0
#define KNOB2  1

#define BUTTON1  2
#define BUTTON2  3
#define BUTTON3  4

#define STAT1  7
#define STAT2  6

#define OFF 1
#define ON 2
#define WAIT 3

byte incomingByte;
byte note;
byte velocity;
int pot;

byte byte1;
byte byte2;
byte byte3;

int action=2; //1 =note off ; 2=note on ; 3= wait



void setup() {

  pinMode(STAT1,OUTPUT);   
  pinMode(STAT2,OUTPUT);

  pinMode(BUTTON1,INPUT);
  pinMode(BUTTON2,INPUT);
  pinMode(BUTTON3,INPUT);

  digitalWrite(BUTTON1,HIGH);
  digitalWrite(BUTTON2,HIGH);
  digitalWrite(BUTTON3,HIGH);

  for(int i = 0;i < 10;i++) // flash MIDI Sheild LED's on startup
  {
    digitalWrite(STAT1,HIGH); 
    digitalWrite(STAT2,LOW);
    delay(30);
    digitalWrite(STAT1,LOW); 
    digitalWrite(STAT2,HIGH);
    delay(30);
  }
  digitalWrite(STAT1,HIGH);   
  digitalWrite(STAT2,HIGH);

  //start serial with midi baudrate 31250
  Serial.begin(31250);     
}

void loop () {

  //*************** MIDI OUT ***************//

  pot = analogRead(0);
  note = pot/8;  // convert value to value 0-127
  if(button(BUTTON1) || button(BUTTON2) || button(BUTTON3))
  { 
    Midi_Send(0x90,note,0x45);
    while(button(BUTTON1) || button(BUTTON2) || button(BUTTON3));
  }

  //*************** MIDI LOOPBACK ******************//
  if(Serial.available() > 0)
  {
    byte1 = Serial.read();
    byte2 = Serial.read();
    byte3 = Serial.read();

    Midi_Send(byte1, byte2, byte3);
  }

  //*************** MIDI IN ***************//
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();

    // wait for as status-byte, channel 1, note on or off
    if (incomingByte== 144) // Note on
    {
      action = OFF;
    }
    else if (incomingByte== 128) // Note off
    {
      action = ON;
    }
    else if (note==0 && action != WAIT) // note on, wait for note value
    {
      note=incomingByte;
    }
    else if (note!=0 && action != WAIT)  // velocity
    {
      velocity=incomingByte;
      if(action == ON){
        Midi_Send(0x90,note,velocity);
      }
      if(action == OFF){
        Midi_Send(0x80,note,velocity);
      }
      note=0;
      velocity=0;
      action=WAIT;
    }
    else{
    }
  }

}

void Midi_Send(byte cmd, byte data1, byte data2) {
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
  Serial.print(data2, BYTE);
}

void blink(){
  digitalWrite(STAT1, HIGH);
  delay(100);
  digitalWrite(STAT1, LOW);
  delay(100);
}

char button(char button_num)
{
  return (!(digitalRead(button_num)));


Best regards,
Lub/OLIMEX
Technical support and documentation manager at Olimex

deseipel

This code is for a shield that has buttons and knobs.  The Olimex shield doesn't have either.  However, I've tried this code (and countless others) and I have yet to receive any data from the board in MIDIOX (connected via MIDI/USB cable.  Was this board tested on an actual midi device?  It could be the MIDI/USB cable I'm using.  BUT that cable (and software) works with other MIDI devices.  BUT perhaps the way that commercial midi devices send data differs from the way that your shield (ontop of the Arduino UNO sketch) sends MIDI data?  I don't know.  I guess I'm curious if this shield was tested with an actual midi device? 

deseipel

so,  did you guys get this working? 

lordkex

It does not work for me either. The issue is rather weird. When I power up the board from outside and measure the RX pin, I can see the incoming MIDI. I am using a Nucleo board and my UART example also work there when I short TX and RX.
But as soon as I connect the shield with the Nucleo, the RX goes silent.

LubOlimex

What is this nucleo board exactly? Did you try to play with the RXD_E jumper state?
Technical support and documentation manager at Olimex