'MIDI' was not declared in this scope

Hi, guys...first time with Arduino here.

I'm trying to make a USB MIDI Host and I'm following a detailed tutorial but I'm facing an unexpected issue. When I upload the sketch to the board the process stops with the error message "'MIDI' was not declared in this scope"

This is the error message copied from clipboard:

Arduino: 1.8.5 (Windows 7), Board: "Arduino/Genuino Uno"

C:\Program Files\Arduino\libraries\USBH_MIDI-IOP_ArduinoMIDI\examples\bidrectional_converter\bidrectional_converter.ino: In function 'void setup()':

bidrectional_converter:52: error: 'MIDI' was not declared in this scope

MIDI.begin(MIDI_CHANNEL_OMNI);

^

C:\Program Files\Arduino\libraries\USBH_MIDI-IOP_ArduinoMIDI\examples\bidrectional_converter\bidrectional_converter.ino: In function 'void loop()':

bidrectional_converter:74: error: 'MIDI' was not declared in this scope

if (MIDI.read()) {

^

C:\Program Files\Arduino\libraries\USBH_MIDI-IOP_ArduinoMIDI\examples\bidrectional_converter\bidrectional_converter.ino: In function 'void MIDI_poll()':

bidrectional_converter:34: error: 'MIDI_DEFAULT_SERIAL_PORT' was not declared in this scope

define _MIDI_SERIAL_PORT MIDI_DEFAULT_SERIAL_PORT

^

C:\Program Files\Arduino\libraries\USBH_MIDI-IOP_ArduinoMIDI\examples\bidrectional_converter\bidrectional_converter.ino:98:7: note: in expansion of macro '_MIDI_SERIAL_PORT'

_MIDI_SERIAL_PORT.write(outBuf, size);

^

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've read about a line to add: MIDI_CREATE_DEFAULT_INSTANCE(); but I dont know where to insert it in the sketch.

BTW this is the tutorial I'm following: http://cyfrowogitarowo.pl/wp-content/uploads/2014/04/MIDI-USB-HOST-DIY-tutorial.pdf

THANKS IN ADVANCE!

You need to correct the code you didn't post.

HTH

You got something wrong in your code. You didn't post the code. So nobody can really tell you what you messed up.

I find it mind boggling how many times we have to tell people this. I'm starting to think common sense might actually be a super power these days.

Sorry, I’ve just copied the error message.

Here is the code:
/*



  • This program is free software; you can redistribute it and/or modify
  • it under the terms of the GNU General Public License as published by
  • the Free Software Foundation; either version 2 of the License, or
  • (at your option) any later version.
  • This program is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • GNU General Public License for more details.
  • You should have received a copy of the GNU General Public License
  • along with this program. If not, see http://www.gnu.org/licenses/

*/

#include <MIDI.h>
#include <Usb.h>
#include <usbh_midi.h>

//Workaround for Arduino MIDI library v4.0 compatibility
#ifdef USE_SERIAL_PORT
#define _MIDI_SERIAL_PORT USE_SERIAL_PORT
#else
#define _MIDI_SERIAL_PORT MIDI_DEFAULT_SERIAL_PORT
#endif

//////////////////////////
// MIDI Pin assign
// 2 : GND
// 4 : +5V(Vcc) with 220ohm
// 5 : TX
//////////////////////////

USB Usb;
USBH_MIDI Midi(&Usb);

void MIDI_poll();
void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime);

void setup()
{
MIDI.begin(MIDI_CHANNEL_OMNI);

//Workaround for non UHS2.0 Shield
pinMode(7,OUTPUT);
digitalWrite(7,HIGH);

if (Usb.Init() == -1) {
while(1); //halt
}//if (Usb.Init() == -1…
delay( 200 );
}

void loop()
{
unsigned long t1;
uint8_t msg[4];

Usb.Task();
t1 = micros();
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
{
MIDI_poll();
if (MIDI.read()) {
msg[0] = MIDI.getType();
if( msg[0] == 0xf0 ) { //SysEX
//TODO
//SysEx implementation is not yet.
}else{
msg[1] = MIDI.getData1();
msg[2] = MIDI.getData2();
Midi.SendData(msg, 0);
}
}
}
//delay(1ms)
doDelay(t1, micros(), 1000);
}

// Poll USB MIDI Controler and send to serial MIDI
void MIDI_poll()
{
byte outBuf[ 3 ];
uint8_t size;

if( (size=Midi.RcvData(outBuf)) > 0 ){
//MIDI Output
_MIDI_SERIAL_PORT.write(outBuf, size);
}
}

// Delay time (max 16383 us)
void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime)
{
unsigned long t3;

if( t1 > t2 ){
t3 = (4294967295 - t1 + t2);
}else{
t3 = t2 - t1;
}

if( t3 < delayTime ){
delayMicroseconds(delayTime - t3);
}
}

Please read the forum rules. They tell how to post code right so the forum software doesn't mangle it.

Here you create your object and you call it Midi.

USBH_MIDI  Midi(&Usb);

But later when you call begin on it you try to use it as MIDI. C++ is case sensitive. MIDI is not the same as Midi.

Delta_G:
I’m starting to think common sense might actually be a super power these days.

I feel a change of signature coming on. :smiley:

Be sure to install the MIDI serial library mentioned in the source code.

* http://playground.arduino.cc/Main/MIDILibrary

The bidirectional_converter creates two MIDI ports which could be named better. Midi is the USB MIDI port. MIDI is the serial MIDI port. The goal is to copy MIDI messages from the MIDI USB port to the MIDI serial port and vice versa.

Yes, i've installed the libraries correctly.

So, any idea to make it work? I'm pretty lost...

Starting with a fresh installation of IDE 1.8.4, use the IDE library manager to install USB Host Shield Library 2.0 by Oleg Mazurov, et al., version 1.3.1. Then install the MIDI Library by Forty Seven Effects, version 4.3.1.

Open the example starting from File | Examples | USB Host Shield Library 2.0 | USBH_MIDI | bidirectional_converter. The example compiles without errors.

The example source code is different from the version you have. You might be using an obsolete version so upgrade to the latest USB Host library. And use the example code included with the library.

The MIDI serial library is different from the one mentioned in your sketch. I installed the Forty Seven Effects version which is specified in the latest example comments. You may have to remove other MIDI serial libraries to get this to work.

gdsports: Starting with a fresh installation of IDE 1.8.4, use the IDE library manager to install USB Host Shield Library 2.0 by Oleg Mazurov, et al., version 1.3.1. Then install the MIDI Library by Forty Seven Effects, version 4.3.1.

Open the example starting from File | Examples | USB Host Shield Library 2.0 | USBH_MIDI | bidirectional_converter. The example compiles without errors.

The example source code is different from the version you have. You might be using an obsolete version so upgrade to the latest USB Host library. And use the example code included with the library.

The MIDI serial library is different from the one mentioned in your sketch. I installed the Forty Seven Effects version which is specified in the latest example comments. You may have to remove other MIDI serial libraries to get this to work.

Thank you very much! Done.

I think that is compiling correctly but there's a problem uploading. I'm facing this error:

Arduino: 1.8.4 (Windows 7), Board: "Arduino/Genuino Uno"

Sketch uses 11854 bytes (36%) of program storage space. Maximum is 32256 bytes.
Global variables use 623 bytes (30%) of dynamic memory, leaving 1425 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x94
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x94
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x94
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x94
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x94
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x94
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x94
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x94
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x94
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x94
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

UPDATE:

The sketch uploads correctly when I disconnect the USB Host Shield from the Arduino board.

Still not working but i'm getting closer.