Arduino Micro MIDI Controller; 'MIDI' was not declared in this scope error

Hello,

I just got my first arduino a couple days ago, and am very excited in trying to make my own MIDI controller. I’m using an Arduino Micro with Mac OS X and Arduino 1.8.5.

My problem is that the I am getting this error message:


Arduino: 1.8.5 (Mac OS X), Board: “Arduino/Genuino Micro”

/Users/jeff/Documents/Arduino/TestController/TestController.ino: In function ‘void buttons()’:
TestController:97: error: ‘MIDI’ was not declared in this scope
MIDI.sendNoteOn(note + i, 127, midiCh); // note, velocity, channel
^
TestController:109: error: ‘MIDI’ was not declared in this scope
MIDI.sendNoteOn(note + i, 0, midiCh); // note, velocity, channel
^
/Users/jeff/Documents/Arduino/TestController/TestController.ino: In function ‘void potentiometers()’:
TestController:154: error: ‘MIDI’ was not declared in this scope
MIDI.sendControlChange(cc + i, midiCState*, midiCh); // cc number, cc value, midi channel*

  • ^*
    /Users/jeff/Documents/Arduino/TestController/TestController.ino: In function ‘void noteOn(byte, byte, byte)’:
    /Users/jeff/Documents/Arduino/TestController/TestController.ino:175:42: warning: narrowing conversion of ‘(int)(channel | 144u)’ from ‘int’ to ‘uint8_t {aka unsigned char}’ inside { } [-Wnarrowing]
  • midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};*
  • ^*
    /Users/jeff/Documents/Arduino/TestController/TestController.ino: In function ‘void noteOff(byte, byte, byte)’:
    /Users/jeff/Documents/Arduino/TestController/TestController.ino:180:43: warning: narrowing conversion of ‘(int)(channel | 128u)’ from ‘int’ to ‘uint8_t {aka unsigned char}’ inside { } [-Wnarrowing]
  • midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};*
  • ^*
    /Users/jeff/Documents/Arduino/TestController/TestController.ino: In function ‘void controlChange(byte, byte, byte)’:
    /Users/jeff/Documents/Arduino/TestController/TestController.ino:185:41: warning: narrowing conversion of ‘(int)(channel | 176u)’ from ‘int’ to ‘uint8_t {aka unsigned char}’ inside { } [-Wnarrowing]
  • midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};*
  • ^*
    exit status 1
    ‘MIDI’ was not declared in this scope
    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File → Preferences.
    ---------
    I have already done a good amount of research/troubleshooting in trying to fix the problem “‘MIDI’ was not declared in this scope”. I’ve tried reinstalling the MIDIUSB Library through two different methods:
    1. Adding the library through the arduino program (i.e. Sketch > Include Library > Manage Libraries) and then adding the MIDIUSB Library.
    2. Adding the zip file from here: GitHub - FortySevenEffects/arduino_midi_library: MIDI for Arduino
    Additionally, I have tried editing the code a little bit since there are many slashed out lines that are relevant to the model of the arduino I am using.
    Attached is a copy of the code I am using from Nerd Musician.
    Thank you,
    Jeff
    TestController.ino (6.49 KB)

JiffiPop:

/Users/jeff/Documents/Arduino/TestController/TestController.ino: In function 'void buttons()':

TestController:97: error: 'MIDI' was not declared in this scope
          MIDI.sendNoteOn(note + i, 127, midiCh); // note, velocity, channel
          ^

From the sketch:

          // use if using with ATmega328 (uno, mega, nano...)
          //do usbMIDI.sendNoteOn if using with Teensy
          MIDI.sendNoteOn(note + i, 127, midiCh); // note, velocity, channel

          // use if using with ATmega32U4 (micro, pro micro, leonardo...)
                    noteOn(midiCh, note + i, 127);  // channel, note, velocity
                    MidiUSB.flush();

Do you see the problem? You're using the MIDIUSB library but the sketch has code for both the MIDIUSB library and the MIDI library. You need to remove all the code written for the MIDI library.

Wow, I can't believe I overlooked that! It fixed the problem, thank you very much!