Arduino mega MIDI controller trouble

Hi, just finished upgrading my homemade midi controller from an uno to a mega with extra pots and switches but it doesn't seem to be sending midi. I'm using the MIDI shield from the uno (this one SparkFun MIDI Shield - DEV-12898 - SparkFun Electronics) and have connected the TX0 and RX0 from the mega to the TX and RX on the MIDI shield and also the 5v and ground connections. The sketch I took from here Arcade Button MIDI Controller : 10 Steps (with Pictures) - Instructables

When using the the MIDI sheild with the Uno the little RX and TX lights lit up but with the Mega no lights at all. I've tried swapping the RX/TX connections to RX1/RX2 etc but still nothing.

Can anyone spot anything obvious that I've missed or done wrong? Any help will be greatly appreciated. Thank you :slight_smile:

It's the red wire.

Sorry couldn't resist. But seriously do you expect an answer.

How have you integrate the MIDI shield in with your Mega?

The best way it to take it a step at a time and just write some code to fire random notes out of MIDI to see if that bit works before trying to control a mess of other stuff.

Haa good one! (Actually made me laugh, i'm not being sarcastic...maybe a little :P)

Anyways, I thought as i'd built one before out of an uno using the same parts which worked very well and got used a lot, it should be easy to switch to a mega and add a few switches and pots. I wasn't suggesting you trace every wire and check it for me. I was just hoping that I'd done something obvious that someone could point out to me. I know the sketch works and I know the MIDI shield works its just the substitution of the mega (I think) :~

I know the sketch works

Well you know it works on a Uno.

the MIDI shield works

Well it worked the last time you wired it up.

With something like this you have to take it a step at a time.
If it were me I would first start with something like this:-

/* Midi note fire - Mike Cook
 * send MIDI serial data, automatically for a test
#define midiChannel (char)0

void setup() {
 //  Setup serial
   Serial.begin(31250);  // MIDI speed
 //  Serial.begin(115200);  // Hairless speed

void loop() {
  int val;
  for(int ins=0; ins<127; ins++){ // one note from all the instruments
  val = random(20,100);
    noteSend(0x90, val, 127); // note on
    noteSend(0x80, val, 127); // note off
    } // end loop function

// sends voice change message
  void voiceChange(int i){
     Serial.write(0xC0); // program change message
//  plays a MIDI note
 void noteSend(char cmd, char data1, char data2) {
  cmd = cmd | char(midiChannel);  // merge channel number

That just fires out MIDI notes. Get that going first to remove any doubt about the basic MIDI output. If that works then you know that the problem is in your code.

Well it worked the last time you wired it up.

Think this might be the problem. :blush: Loaded that sketch up like you suggested and no MIDI data reached my computer. So i plugged the shield back into the uno as it was originally and still nothing. Fried the 6N138 possibly? Or maybe I broke something trying to de-solder the MIDI connectors. Guess ill make my own MIDI shield type thing. I don't fancy messing around with surface mount stuff and don't think ill bother buying another shield.

Thank you for you help! :slight_smile:

This is where an oscilloscope will come in handy.

Well I ended up ordering some 6N138's and some sockets for them to sit in, soldered them onto the surface mount pads but that didn't fix it either. Then I realized that these chips aren't actually needed for MIDI out, they're used for incoming MIDI signals :blush: So I ended up connecting the TX, ground and 5v through a 220 ohm resistor straight to the MIDI connector. Finally got your sketch to work :slight_smile: But it didn't work with the sketch I intended to use :frowning: Ended up writing my own sketch with very limited knowledge and got the buttons to work but I'm still struggling with the control pots.

My code is pretty ridiculous, I don't understand the whole grouping thing so it's quite long compared to everyone else's I've seen. Its basically the code for one button copied 32 times. I think I prefer it this way though because I can see exactly whats going on and its easy for me to understand.

Anyone know of a really basic MIDI control sketch for one knob that I could have a look at?


Try this, it sets the volume on MIDI channel 0 controlled by a pot connected to analogue input 0.

/* Midi controller knob - Grumpy Mike
 reads a pot on analogue 0 and sends it out as a CC message on channel 0
int last_reading =0;
void setup() {
     Serial.begin(31250);       // MIDI speed

//********************* MAIN LOOP ***********************************

void loop() {
    int reading = analogRead(0); // read a pot on analog 0
    if(abs(reading - last_reading) > 7  ){ // if there has been a change
      sendCC( 7,reading >> 3); // convert to 7 bits and send to CC 7 volume
    } // end loop function

 //  send CC message
void sendCC(byte cc, byte data1) {
  Serial.write(0xB0);  // control change message

Magic!! :smiley: Got everything working now, cheers Mike!! Only problem I have now is that when I try and map the pots to a control in Ableton, Ableton sees all the pots at once. I’ve tried increasing the “7” for all of these lines; “if(abs(reading - last_reading) > 7 )” but that doesn’t fix it. Is there a was to say stop sending CC data? For example if(abs(reading - last_reading) < 7) {stop sending ( 1,reading >> 3);}

Ableton sees all the pots at once.

You need a different variable last_reading for each pot.