Why am I getting a 'error MIDIUSB can only be used with an USB MCU' when compiling a MIDIUSB example on a newly opened brand make Arduino Leonardo?

Hello!

I don't understand this error. I think I'm having a compilation issue with the MIDIUSB (1.0.5) when attempting to upload to a newly bought, brand name Arduino Leonardo.

The error message reads:


FQBN: arduino:avr:leonardo
Using board 'leonardo' from platform in folder: /Users/avi/Library/Arduino15/packages/arduino/hardware/avr/1.8.6
Using core 'arduino' from platform in folder: /Users/avi/Library/Arduino15/packages/arduino/hardware/avr/1.8.6

Detecting libraries used...
/Users/avi/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Leonardo" -I/Users/avi/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino -I/Users/avi/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/variants/leonardo /Users/avi/Library/Caches/arduino/sketches/9107DFED6FA9D589AF64703BEE6F7AC4/sketch/MIDIUSB_read.ino.cpp -o /dev/null
Alternatives for MIDIUSB.h: [MIDIUSB@1.0.5]
ResolveLibrary(MIDIUSB.h)
  -> candidates: [MIDIUSB@1.0.5]
/Users/avi/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Leonardo" -I/Users/avi/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino -I/Users/avi/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/variants/leonardo -I/Users/avi/Documents/Arduino/libraries/MIDIUSB/src /Users/avi/Library/Caches/arduino/sketches/9107DFED6FA9D589AF64703BEE6F7AC4/sketch/MIDIUSB_read.ino.cpp -o /dev/null
Error while detecting libraries included by /Users/avi/Library/Caches/arduino/sketches/9107DFED6FA9D589AF64703BEE6F7AC4/sketch/MIDIUSB_read.ino.cpp
/Users/avi/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Leonardo" -I/Users/avi/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino -I/Users/avi/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/variants/leonardo -I/Users/avi/Documents/Arduino/libraries/MIDIUSB/src /Users/avi/Documents/Arduino/libraries/MIDIUSB/src/MIDIUSB.cpp -o /dev/null
Error while detecting libraries included by /Users/avi/Documents/Arduino/libraries/MIDIUSB/src/MIDIUSB.cpp
Generating function prototypes...
/Users/avi/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Leonardo" -I/Users/avi/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino -I/Users/avi/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/variants/leonardo -I/Users/avi/Documents/Arduino/libraries/MIDIUSB/src /Users/avi/Library/Caches/arduino/sketches/9107DFED6FA9D589AF64703BEE6F7AC4/sketch/MIDIUSB_read.ino.cpp -o /private/var/folders/0j/7b000wx91g1bcxv2pyr1j1l00000gn/T/1398982950/sketch_merged.cpp
In file included from /private/var/folders/0j/7b000wx91g1bcxv2pyr1j1l00000gn/T/.arduinoIDE-unsaved20241110-19249-ix52b1.e2c2j/MIDIUSB_read/MIDIUSB_read.ino:9:0:
/Users/avi/Documents/Arduino/libraries/MIDIUSB/src/MIDIUSB.h:18:2: error: #error MIDIUSB can only be used with an USB MCU.
 #error MIDIUSB can only be used with an USB MCU.
  ^~~~~
exit status 1

Compilation error: exit status 1

Why is this happening? The Leonardo is an ATmega32u4, so what's the problem here?
I am running Arduino IDE v. 2.3.4 and MIDIUSB 1.0.5. I am posting to this forum because I suspect that there is a compilation error, though I do not understand why.

Help much appreciated.

The read example compiles here for a Leonardo; IDE 2.3.4 on Windows 11. It has some warnings but they are not relevant to your current problem.

Which operating system are you using?

What I would try is to close the IDE and delete the following directories.

  1. /Users/avi/Library/Caches/arduino/sketches/
  2. /Users/avi/Library/Caches/arduino/cores/

It should be safe to delete those directories but make backups if in doubt.

Start the IDE again and try to compile.

If the above does not help, repeat the steps above, start the IDE and save the example to the sketchbook directory. Next try to compile again.


Because you do not have an upload problem, I've moved your topic to a more suitable location on the forum.

I'm not sure what example you are referring to...

I am on Mac OS Sonoma 14.2.1.

Thanks for your suggestion, however deleting caches does not resolve the error.

Your error refers to MIDIUSB_read.ino. So that was the read example that I was referring to.

I unfortunately have no other ideas.

Hi @hyphal-n0t. The unexpected error might have been caused by some unknown corruption or modification of the "Arduino AVR Boards" platform that adds support to Arduino IDE for the Leonardo board. If so, it should be possible to fix the problem by uninstalling and then reinstalling a fresh copy of the platform.

I'll provide instructions you can follow to do that:

  1. Select Tools > Board > Boards Manager... from the Arduino IDE menus to open the "Boards Manager" view in the left side panel.
  2. Scroll down through the list of boards platforms until you see the "Arduino AVR Boards" entry.
  3. Hover the mouse pointer over the "Arduino AVR Boards" entry.
    You will see a ●●● icon appear at the top right corner of the entry.
  4. Click the ●●● icon.
    A menu will open.
  5. Select "Remove" from the menu.
    An "Uninstall" dialog will open.
  6. Click the "YES" button in the "Uninstall" dialog.
    The dialog will close.
  7. Wait for the uninstall process to finish, as indicated by a notification at the bottom right corner of the Arduino IDE window:

    Successfully uninstalled platform ...

  8. Click the "INSTALL" button at the bottom of the "Arduino AVR Boards" entry.
  9. Wait for the installation process to finish, as indicated by a notification at the bottom right corner of the Arduino IDE window:

    Successfully installed platform ...

Now try compiling the MIDIUSB library example again. Hopefully this time it will work as expected.