Hi,
I am trying to turn my arduino mega 2560 rev 3 into a MIDI controller. This is something I’ve done 5 times previously, the most recent time about a year ago, with not too much trouble.
But I’m doing the same steps that I’ve always done and not getting the same results. Has something changed with Arduino Megas or Arduino software?
I put my code below.
I added these lines last time I did this because it helped the code compile:
#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>
MIDI_CREATE_DEFAULT_INSTANCE();
I first uploaded the code to my arduino mega.
Then I followed the steps on this page to flash the USB port to become a midi port using Hiduino:
http://www.ladyada.net/learn/avr/avrdude.html
I am on a Mac and I used terminal to do this. According to avrdude, I did this successfully.
But when I plug my Arduino Mega into my computer via USB it is not showing up as a MIDI controller like it should. I even uploaded my arduino code again to the board to make sure it’s there.
Any suggestions? Or am I missing some new steps or code? I also downloaded the latest arduino midi library. I am using Arduino Software 1.8.5
thanks, Nick
#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>
MIDI_CREATE_DEFAULT_INSTANCE(); //nick added for compatibility with older sketch, 8/13/17
/*
March 2012
modified 8/13/17 by N.Demopoulos
*/
const int MIDIChannel = 1;
const int numAnalogIn = 13;
const int firstAnalogIn = 0; // pin number of first analog in
const int firstAnalogController = 1; // midi controller number for this analog in
int currentAnalogIndex = 0;
int analogOld[numAnalogIn];
const int numDigitalIn = 17;
const int firstDigitalIn = 22; //pin number of first digital in
const int firstDigitalController = 14; // midi controller number for first digital out
int currentDigitalIndex = 0;
int digitalOld[numDigitalIn];
void setup() {
// wire 3.3V to AREF for 3.3V reference
analogReference(EXTERNAL);
MIDI.begin(MIDIChannel);
MIDI.turnThruOff();
int i;
for (i=0;i<numAnalogIn; i++) {
analogOld[i] = -1;
}
for (i=0;i<numDigitalIn; i++) {
digitalOld[i] = -1;
// set digital pins to input with pull-up
pinMode(i+firstDigitalIn, INPUT);
digitalWrite(i+firstDigitalIn, HIGH);
}
}
void loop() {
int analog = analogRead(currentAnalogIndex + firstAnalogIn);
if (analog != analogOld[currentAnalogIndex]) {
//MIDI.sendControlChange(currentAnalogIndex+firstAnalogController, analog >> 3, 1);
analogOld[currentAnalogIndex] = analog;
sendControlChange(currentAnalogIndex+firstAnalogController, analog >> 3, MIDIChannel);
}
currentAnalogIndex++;
currentAnalogIndex %= numAnalogIn;
int digital = digitalRead(currentDigitalIndex + firstDigitalIn);
if (digital != digitalOld[currentDigitalIndex]) {
digitalOld[currentDigitalIndex] = digital;
sendControlChange(currentDigitalIndex+firstDigitalController, (digital==1 ? 0 :127), MIDIChannel);
}
currentDigitalIndex++;
currentDigitalIndex %= numDigitalIn;
}
void sendControlChange(int controllerNumber, int controllerValue, int midiChannel) {
//Serial.write(0xB0 | (midiChannel & 0x0F));
//Serial.write(controllerNumber & 0x7F);
//Serial.write(controllerValue & 0x7F);
MIDI.sendControlChange(controllerNumber, controllerValue, midiChannel);
delay(4);
}