Midi Controller for Line 6 m5 with Arduino Due

Hi guys, this is my first post in the arduino forums so I hope I make myself clear, i'll get to the point.

So I'm building a midi controller for my guitar effects processor Line 6 m5, it does have MIDI in and out ports. The problem I'm having is that my code doesn't seem to do anything on the processor.

I started with some complex code with many buttons and stuff but eventually tried with simplier code just for the sake of debuging.

I've tried sending the MIDI messages manually and using the MIDI library but none of them worked. Here is the code I'm working with right now:

The one without the MIDI library...

void setup() {
  Serial.begin(31250);
}

void loop() {
 
    noteOn(0xC1,0x00);
    delay(1000);
    noteOn(0xC1,0x02);   
    delay(1000);
}

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

And the one with it:

#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>

MIDI_CREATE_DEFAULT_INSTANCE();
void setup() {
  // put your setup code here, to run once:
MIDI.begin(1);
}

void loop() {
  MIDI.sendProgramChange(0x04,1);
  delay(2000);
  MIDI.sendProgramChange(0x05,1);  // put your main code here, to run repeatedly:
}

I've tried different things like using Serial1, Serial2 and Serial3 but didn't work.
The wiring is ok, I wired the circuit just like this example:
http://arduino.cc/en/pmwiki.php?n=Tutorial/Midi
(And also swapped midi pins 4 and 5 to see if that was the error but still nothing).

I'm also attaching the only info about the midi functions my guitar effects processor has in the manual

Any help would be greatly appreciated. Thanks guys!.

midi line 6 m5.PNG

A couple of things

  1. The Due is runs on 3.3V not 5V, and I don't know if the serial lines are buffered back up to even 5V. I'm not sure what voltages Midi uses.

Are you using some sort of Midi shield ?

  1. This code is problematic
void loop() {
  MIDI.sendProgramChange(0x04,1);
  delay(2000);
  MIDI.sendProgramChange(0x05,1);  // put your main code here, to run repeatedly:
}

Put another delay in

e.g.

void loop() {
  MIDI.sendProgramChange(0x04,1);
  delay(2000);
  MIDI.sendProgramChange(0x05,1);  // put your main code here, to run repeatedly:
delay(2000);
}

Edit.

Just looked at the Due schematic and the Serial lines are not buffered, so probably are not high enough voltage
You will need to use a buffer IC (sorry can't remember the part number, I'm sure someone else will respond with it) ;0)

I notice that you are sending the messages on MIDI Channel 2, are you sure that is correct?
in hardware terms MIDI channels run from 0 to 15 but musicians call this 1 to 16, therefore to send something out on MIDI channel 1 your software in the arduino must use channel 0, but your effects peddle must be set to channel 1.

Also as mentioned the Due will probably not be able to supply enough current to drive the MIDI interface anyway and you could end up damaging the Due.

Thank you very much for your fast replies.

I tried changing channels in the line 6 processor but it didn't work (even tried in omni mode). Also changed the delays in the code after I posted (that's why the code without the midi library has 2 delays) but as you may guess, that was not the problem.

So, what about the buffer?, I'm planning that the MIDI controller to be only MIDI out, so I wouldn't need to receive MIDI data. I suppose there shouldn't be a problem If I try to pass the signal through a buffer to make sure that the processor receives the signal correctly right?. In that case, could something like the 74HC126D buffer be helpful?.

I was thinking about buying one of those or in the worst case scenario buy another arduino maybe something like a nano just for testing this or a Mega because I would like to have more than one serial port, because my actual goal is to make the arduino control 2 processors (2 independent MIDI outs).

The thing is... it would be perfect to make this project work with the Due because one of the main reasons I started this was because I already had an arduino.

Thanks again for your help!

If you need to level shift the 3.3V outputs to 5V you could use the techniques described here

The Arduino Leonardo and Pro Micro both have a hardware serial port that you can use (Serial1) because the internal serial to the PC is handled directly inside the microcontroller IC as the IC use don those boards has a built in USB connection, which leaves the normal serial lines free for other uses.

I've bought several Pro Micro's from eBay sellers for around $10.
But I also have a Mega2560 etc

Was there a specific reason you are using the Due, it seems overly powerful for simple midi processing.

BTW. I have a Due on order but it seems to have been lost in the post ;-(

you could use the techniques described here

Errr, I don't like that.

I tested the first code without the library on a Due and it works fine.
I was concerned that the Due could not handle that odd baud rate but it is fine. Attached is an image of the output, I actually shortened the first delay to get both messages on the same screen, but as you can see the data is transmitted perfectly.

Therefore it is your MIDI interface that is wrong. Note you can use one of the other three serial outputs on the Due as well.

Again, thank you very much to both of you.

@Grumpy_Mike: The problem I think I might have is on the receiver device (the line 6 m5 effects processor), my MIDI interface is nothing more than the 3 cables described in the diagram in the first post connecting the arduino to the MIDI socket in which the midi cable is connected (then it goes straight to the m5).

Maybe I should check again for a faulty cable, because I know the MIDI cable works (tested it with other devices without a problem), that would leave the MIDI socket and the cables i'm using to connect the circuit. I also tried the other serial pins but didn't work. The other thing that I think it could be causing the problem, is that the processor needs to receive something else and not just the Program Change MIDI message (note that in the line 6 m5 manual says "Preset Change" but I took for granted that it meant Program Change, could this be a problem too?).

Anyway, thanks again!, I'll come back here when I try all those things or learn something new about the processor.

my MIDI interface is nothing more than the 3 cables described in the diagram in the first post connecting the arduino to the MIDI socket in which the midi cable is connected (then it goes straight to the m5).

Yes but the point of that interface is that it will only work with a 5V signal, this is a Due and so you do not have a 5V signal. So you have to make it into one before that interface will work.

related question: I have a Due in which I'm trying to send/receive MIDI using a Rugged Circuits MIDI shield

The MIDI data comes from an SD card on the Adafruit 1.8" TFT LCD. Does that shield deal with the voltage issue?

update: I see that it has a 74HC125D on the output

just to update, I was able to play some notes with a Due + the rugged Circuits MIDI shield (converted to 3.3v), using this simple code:

void setup() {
  //  Set MIDI baud rate:
  Serial.begin(31250);
  
    pinMode(A5, OUTPUT);      // sets the digital pin as output, D19 on Rugged circuits MIDI shield = A5 on Mega/Due.
  digitalWrite(A5, HIGH);
}

void loop() {
  // play notes from F#-0 (0x1E) to F#-5 (0x5A):
  for (int note = 0x1E; note < 0x5A; note ++) {
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, note, 0x45);
    delay(100);
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    noteOn(0x90, note, 0x00);   
    delay(100);
  }
}

//  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(int cmd, int pitch, int velocity) {
  Serial.write(cmd);
  Serial.write(pitch);
  Serial.write(velocity);
}

HI .
I made muy own DIY switch for line6m5 and it is great :slight_smile:

Visit my YT chanel and get the code :wink: