Not finding "Adafruit_USBD_MIDI.h" at all

The problem I have is that when compiling code with the TinyUSB library from Adafruit with IDE 2.3.4 the message always appears: fatal error: Adafruit_USBD_MIDI.h: No such file or directory
I use Mac OSX Sequoia.
even though I did install the boards for the RP2040 I'm using as well as the library "Adafruit TinyUSB library" I checked and the missing file is present in a subfolder of the library, so it's there. But it can't find it. Libraries are in the sketch folder.
I uninstalled Arduino and all related files multiple times but I always get the same error. I also tried this on a different computer. Not working.
I ran out of ideas.
Help would be greatly appreciated.

Sounds like an error in the library. Where can I find the sketch you are compiling so I can try.

Any chance that your is located in a directory that contains non-ascii characters.

Sure!

#include <Adafruit_TinyUSB.h>      // TinyUSB-Bibliothek für USB-Funktionen (CDC, MIDI, etc.)
#include <Adafruit_USBD_MIDI.h>    // USB-MIDI-Schnittstelle
#include <arduinoFFT.h>            // ArduinoFFT-Bibliothek für FFT-Funktionen

// MIDI Schnittstellen
Adafruit_USBD_CDC usb_serial;       // USB-Serial (CDC) Schnittstelle
Adafruit_USBD_MIDI usb_midi;        // USB-MIDI-Schnittstelle

// Funktionsprototypen
bool sendNoteOn(byte pitch, byte velocity);
bool sendNoteOff(byte pitch, byte velocity = 0);

// FFT Konfiguration
#define SAMPLES 256             // Anzahl der FFT-Samples (muss Potenz von 2 sein, z.B., 128, 256, 512, ...)
#define SAMPLING_FREQUENCY 1000 // Abtastrate in Hz (angepasst auf dein Setup)

// Onset-Erkennungsparameter
const float thresholdFactor = 1.5; // Faktor zur Anpassung des Schwellenwerts
float baseEnergy = 0.0;            // Basisenergie zur Normalisierung
bool firstRun = true;

// GPIO-Pins
const int audioPin = 26;            // Analogeingang A0 (GPIO26) des Pico
const int ledPin = 15;              // Beispiel-Pin für LED

// Dynamikvariablen
unsigned long lastOnsetTime = 0;    // Zeitpunkt des letzten Onsets
const unsigned long minOnsetInterval = 100; // Minimale Zeit zwischen Onsets (ms)
const unsigned long midiNoteDuration = 300; // MIDI-Noten-Dauer (ms)
bool noteOnActive = false;

// FFT Objekte
arduinoFFT FFT = arduinoFFT();

// Sample Arrays
double vReal[SAMPLES];
double vImag[SAMPLES];

// Zeitpunkt für Sampling
unsigned long samplingPeriod;
unsigned long lastSampleTime = 0;

void setup() {
  pinMode(audioPin, INPUT);
  pinMode(ledPin, OUTPUT);

  TinyUSBDevice.begin();
  usb_serial.begin(115200);
  usb_midi.begin();
  usb_serial.println("Setup complete. Ready for Onsets.");

  // Berechne Sampling-Periode
  samplingPeriod = 1000000 / SAMPLING_FREQUENCY; // in Mikrosekunden
}

void loop() {
  unsigned long currentMicros = micros();

  // Samples sammeln
  for (int i = 0; i < SAMPLES; i++) {
    // Warte bis zur nächsten Sampling-Periode
    while (micros() - currentMicros < samplingPeriod) {
      // Nichts tun
    }
    currentMicros += samplingPeriod;

    // Lese das analoge Signal und skaliere es auf +/-1.0
    int rawValue = analogRead(audioPin);
    double scaledValue = (rawValue - 2048) / 2048.0; // Annahme: ADC von 0 bis 4095, zentriert bei 2048

    vReal[i] = scaledValue;
    vImag[i] = 0.0; // Imaginary part ist 0
  }

  // Führe die FFT durch
  FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
  FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD);
  FFT.ComplexToMagnitude(vReal, vImag, SAMPLES);

  // Analysiere die Energie im relevanten Frequenzbereich (z.B., 50 Hz bis 150 Hz für E2)
  float energy = 0.0;
  int peakBin = FFT.MajorPeak(vReal, SAMPLES); // Suche die dominierende Frequenz
  float frequency = (peakBin * SAMPLING_FREQUENCY) / SAMPLES;

  // Definiere die Ziel-Frequenzen für die tiefe E-Saite und ihre Harmonischen
  float targetFrequencies[] = {82.41, 164.81, 247.21}; // E2, E3, E4
  int numTargets = sizeof(targetFrequencies) / sizeof(targetFrequencies[0]);
  float bandwidth = 5.0; // Hz

  for (int i = 0; i < numTargets; i++) {
    float target = targetFrequencies[i];
    for (int bin = 0; bin < SAMPLES / 2; bin++) { // Nur positive Frequenzen
      float freq = (bin * SAMPLING_FREQUENCY) / SAMPLES;
      if (abs(freq - target) <= bandwidth) {
        energy += vReal[bin];
      }
    }
  }

  // Initialisiere die Basisenergie
  if (firstRun) {
    baseEnergy = energy;
    firstRun = false;
  }

  // Onset-Erkennung basierend auf der Energie
  if (!noteOnActive && energy > (baseEnergy * thresholdFactor) && (millis() - lastOnsetTime > minOnsetInterval)) {
    usb_serial.println("Onset detected via FFT!");
    digitalWrite(ledPin, HIGH); // LED einschalten
    if (sendNoteOn(40, 127)) { // Sende MIDI-Note (E2)
      noteOnActive = true;
      lastOnsetTime = millis();
    }
  }

  // Note-Off senden, wenn die MIDI-Notendauer abgelaufen ist
  if (noteOnActive && (millis() - lastOnsetTime >= midiNoteDuration)) {
    if (sendNoteOff(40, 0)) { // Velocity auf 0 setzen
      noteOnActive = false;
      digitalWrite(ledPin, LOW); // LED ausschalten
      usb_serial.println("Note Off sent via FFT.");
    }
  }

  // Optional: Aktualisiere die Basisenergie periodisch, um sich an veränderte Bedingungen anzupassen
  if (millis() - lastOnsetTime > 1000) { // Alle 1 Sekunde
    baseEnergy = 0.95 * baseEnergy + 0.05 * energy; // Exponentielle Glättung
  }

  // Optional: Debug-Ausgabe für Serial Plotter
  usb_serial.print(energy);
  usb_serial.print(",");
  usb_serial.print(baseEnergy * thresholdFactor);
  usb_serial.print(",");
  usb_serial.print(noteOnActive ? 1 : 0);
  usb_serial.println();
}

// ====================================================================
// Hilfsfunktionen
// ====================================================================

// MIDI Note-On senden
bool sendNoteOn(byte pitch, byte velocity) {
  uint8_t noteOn[] = {0x90, pitch, velocity};
  if (usb_midi.write(noteOn, sizeof(noteOn))) {
    usb_midi.flush();
    return true;
  }
  return false;
}

// MIDI Note-Off senden
bool sendNoteOff(byte pitch, byte velocity) {
  uint8_t noteOff[] = {0x80, pitch, velocity};
  if (usb_midi.write(noteOff, sizeof(noteOff))) {
    usb_midi.flush();
    return true;
  }
  return false;
}

What do you mean exactly?

Hi @oger.

You must use the relative path from the root of the library source folder in the #include directive.

Since the file is under the arduino/midi subfolder, you must change this line of your sketch:

to this

#include <arduino/midi/Adafruit_USBD_MIDI.h>    // USB-MIDI-Schnittstelle

After making that change, try compiling or uploading your sketch again. Hopefully the "Adafruit_USBD_MIDI.h: No such file or directory" error will no longer occur.

I tried it, but it still couldn't find it.
Here is my path where the file resides:

Please post your updated sketch.

I'm going to ask you to provide the full verbose output from a compilation.


:exclamation: This procedure is not intended to solve the problem. The purpose is to gather more information.


Please do this:

  1. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  2. Check the box next to "Show verbose output during: ☐ compile" in the "Preferences" dialog.
  3. Click the "OK" button.
    The "Preferences" dialog will close.
  4. Select Sketch > Verify/Compile from the Arduino IDE menus.
  5. Wait for the compilation to fail.
  6. You will see a "Compilation error: ..." notification at the bottom right corner of the Arduino IDE window. Click the "COPY ERROR MESSAGES" button on that notification.
  7. Open a forum reply here by clicking the "Reply" button.
  8. Click the <CODE/> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
  9. Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
    This will paste the compilation output into the code block.
  10. Move the cursor outside of the code block markup before you add any additional text to your reply.
  11. Click the "Reply" button to post the output.

In case the output is longer than the forum software will allow to be added to a post, you can instead save it to a .txt file and then attach that file to a reply here.

Click here for attachment instructions

  1. Open any text editor program.
  2. Paste the copied output into the text editor.
  3. Save the file in .txt format.
  4. Open a forum reply here by clicking the "Reply" button.
  5. Click the "Upload" icon (Upload icon) on the post composer toolbar:

    The "Open" dialog will open.
  6. Select the .txt file you saved from the "Open" dialog.
  7. Click the "Open" button.
    The dialog will close.
  8. Click the "Reply" button to publish the post.

Alternatively, instead of using the "Upload" icon on the post composer toolbar as described in steps (5) - (7) above, you can simply drag and drop the .txt file onto the post composer field to attach it.


FQBN: rp2040:rp2040:adafruit_feather:usbstack=tinyusb
Using board 'adafruit_feather' from platform in folder: /Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1
Using core 'rp2040' from platform in folder: /Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1

Detecting libraries used...
/Users/steve/Library/Arduino15/packages/rp2040/tools/pqt-gcc/4.0.1-8ec9d6f/bin/arm-none-eabi-g++ -I /Users/steve/Library/Caches/arduino/sketches/DC60B06F7B64424E95EA55E4DCBAA7F0/core -c -Werror=return-type -Wno-psabi -DUSE_TINYUSB -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/libraries/Adafruit_TinyUSB_Arduino/src/arduino -DUSBD_PID=0x80f1 -DUSBD_VID=0x239a -DUSBD_MAX_POWER_MA=250 -DUSB_MANUFACTURER="Adafruit" -DUSB_PRODUCT="Feather RP2040" -DLWIP_IPV6=0 -DLWIP_IPV4=1 -DLWIP_IGMP=1 -DLWIP_CHECKSUM_CTRL_PER_NETIF=1 -DARDUINO_VARIANT="adafruit_feather" -DPICO_FLASH_SIZE_BYTES=8388608 @/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/lib/rp2040/platform_def.txt -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions -iprefix/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/ @/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/lib/rp2040/platform_inc.txt @/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/lib/core_inc.txt -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/include -fno-rtti -std=gnu++17 -g -pipe -w -x c++ -E -CC -DF_CPU=133000000L -DARDUINO=10607 -DARDUINO_ADAFRUIT_FEATHER_RP2040 -DBOARD_NAME="ADAFRUIT_FEATHER_RP2040" -DARDUINO_ARCH_RP2040 -Os -DWIFICC=CYW43_COUNTRY_WORLDWIDE -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/cores/rp2040 -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/variants/adafruit_feather /Users/steve/Library/Caches/arduino/sketches/DC60B06F7B64424E95EA55E4DCBAA7F0/sketch/FFT.ino.cpp -o /dev/null
Alternatives for Adafruit_TinyUSB.h: [Adafruit TinyUSB Library@3.4.2 Adafruit TinyUSB Library@3.4.2 Adafruit TinyUSB Library@3.4.2]
ResolveLibrary(Adafruit_TinyUSB.h)
  -> candidates: [Adafruit TinyUSB Library@3.4.2 Adafruit TinyUSB Library@3.4.2 Adafruit TinyUSB Library@3.4.2]
/Users/steve/Library/Arduino15/packages/rp2040/tools/pqt-gcc/4.0.1-8ec9d6f/bin/arm-none-eabi-g++ -I /Users/steve/Library/Caches/arduino/sketches/DC60B06F7B64424E95EA55E4DCBAA7F0/core -c -Werror=return-type -Wno-psabi -DUSE_TINYUSB -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/libraries/Adafruit_TinyUSB_Arduino/src/arduino -DUSBD_PID=0x80f1 -DUSBD_VID=0x239a -DUSBD_MAX_POWER_MA=250 -DUSB_MANUFACTURER="Adafruit" -DUSB_PRODUCT="Feather RP2040" -DLWIP_IPV6=0 -DLWIP_IPV4=1 -DLWIP_IGMP=1 -DLWIP_CHECKSUM_CTRL_PER_NETIF=1 -DARDUINO_VARIANT="adafruit_feather" -DPICO_FLASH_SIZE_BYTES=8388608 @/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/lib/rp2040/platform_def.txt -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions -iprefix/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/ @/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/lib/rp2040/platform_inc.txt @/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/lib/core_inc.txt -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/include -fno-rtti -std=gnu++17 -g -pipe -w -x c++ -E -CC -DF_CPU=133000000L -DARDUINO=10607 -DARDUINO_ADAFRUIT_FEATHER_RP2040 -DBOARD_NAME="ADAFRUIT_FEATHER_RP2040" -DARDUINO_ARCH_RP2040 -Os -DWIFICC=CYW43_COUNTRY_WORLDWIDE -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/cores/rp2040 -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/variants/adafruit_feather -I/Users/steve/Documents/Arduino/libraries/Adafruit_TinyUSB_Library/src /Users/steve/Library/Caches/arduino/sketches/DC60B06F7B64424E95EA55E4DCBAA7F0/sketch/FFT.ino.cpp -o /dev/null
Alternatives for SPI.h: [SPI@1.0]
ResolveLibrary(SPI.h)
  -> candidates: [SPI@1.0]
/Users/steve/Library/Arduino15/packages/rp2040/tools/pqt-gcc/4.0.1-8ec9d6f/bin/arm-none-eabi-g++ -I /Users/steve/Library/Caches/arduino/sketches/DC60B06F7B64424E95EA55E4DCBAA7F0/core -c -Werror=return-type -Wno-psabi -DUSE_TINYUSB -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/libraries/Adafruit_TinyUSB_Arduino/src/arduino -DUSBD_PID=0x80f1 -DUSBD_VID=0x239a -DUSBD_MAX_POWER_MA=250 -DUSB_MANUFACTURER="Adafruit" -DUSB_PRODUCT="Feather RP2040" -DLWIP_IPV6=0 -DLWIP_IPV4=1 -DLWIP_IGMP=1 -DLWIP_CHECKSUM_CTRL_PER_NETIF=1 -DARDUINO_VARIANT="adafruit_feather" -DPICO_FLASH_SIZE_BYTES=8388608 @/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/lib/rp2040/platform_def.txt -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions -iprefix/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/ @/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/lib/rp2040/platform_inc.txt @/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/lib/core_inc.txt -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/include -fno-rtti -std=gnu++17 -g -pipe -w -x c++ -E -CC -DF_CPU=133000000L -DARDUINO=10607 -DARDUINO_ADAFRUIT_FEATHER_RP2040 -DBOARD_NAME="ADAFRUIT_FEATHER_RP2040" -DARDUINO_ARCH_RP2040 -Os -DWIFICC=CYW43_COUNTRY_WORLDWIDE -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/cores/rp2040 -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/variants/adafruit_feather -I/Users/steve/Documents/Arduino/libraries/Adafruit_TinyUSB_Library/src -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/libraries/SPI/src /Users/steve/Library/Caches/arduino/sketches/DC60B06F7B64424E95EA55E4DCBAA7F0/sketch/FFT.ino.cpp -o /dev/null
Alternatives for arduinoFFT.h: [arduinoFFT@2.0.4]
ResolveLibrary(arduinoFFT.h)
  -> candidates: [arduinoFFT@2.0.4]
/Users/steve/Library/Arduino15/packages/rp2040/tools/pqt-gcc/4.0.1-8ec9d6f/bin/arm-none-eabi-g++ -I /Users/steve/Library/Caches/arduino/sketches/DC60B06F7B64424E95EA55E4DCBAA7F0/core -c -Werror=return-type -Wno-psabi -DUSE_TINYUSB -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/libraries/Adafruit_TinyUSB_Arduino/src/arduino -DUSBD_PID=0x80f1 -DUSBD_VID=0x239a -DUSBD_MAX_POWER_MA=250 -DUSB_MANUFACTURER="Adafruit" -DUSB_PRODUCT="Feather RP2040" -DLWIP_IPV6=0 -DLWIP_IPV4=1 -DLWIP_IGMP=1 -DLWIP_CHECKSUM_CTRL_PER_NETIF=1 -DARDUINO_VARIANT="adafruit_feather" -DPICO_FLASH_SIZE_BYTES=8388608 @/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/lib/rp2040/platform_def.txt -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions -iprefix/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/ @/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/lib/rp2040/platform_inc.txt @/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/lib/core_inc.txt -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/include -fno-rtti -std=gnu++17 -g -pipe -w -x c++ -E -CC -DF_CPU=133000000L -DARDUINO=10607 -DARDUINO_ADAFRUIT_FEATHER_RP2040 -DBOARD_NAME="ADAFRUIT_FEATHER_RP2040" -DARDUINO_ARCH_RP2040 -Os -DWIFICC=CYW43_COUNTRY_WORLDWIDE -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/cores/rp2040 -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/variants/adafruit_feather -I/Users/steve/Documents/Arduino/libraries/Adafruit_TinyUSB_Library/src -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/libraries/SPI/src -I/Users/steve/Documents/Arduino/libraries/arduinoFFT/src /Users/steve/Library/Caches/arduino/sketches/DC60B06F7B64424E95EA55E4DCBAA7F0/sketch/FFT.ino.cpp -o /dev/null
/Users/steve/Documents/Arduino/libraries/Adafruit_TinyUSB_Library/src/Adafruit_USBD_MIDI.cpp:29:10: fatal error: Adafruit_USBD_MIDI.h: No such file or directory
   29 | #include "Adafruit_USBD_MIDI.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
/Users/steve/Library/Arduino15/packages/rp2040/tools/pqt-gcc/4.0.1-8ec9d6f/bin/arm-none-eabi-g++ -I /Users/steve/Library/Caches/arduino/sketches/DC60B06F7B64424E95EA55E4DCBAA7F0/core -c -Werror=return-type -Wno-psabi -DUSE_TINYUSB -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/libraries/Adafruit_TinyUSB_Arduino/src/arduino -DUSBD_PID=0x80f1 -DUSBD_VID=0x239a -DUSBD_MAX_POWER_MA=250 -DUSB_MANUFACTURER="Adafruit" -DUSB_PRODUCT="Feather RP2040" -DLWIP_IPV6=0 -DLWIP_IPV4=1 -DLWIP_IGMP=1 -DLWIP_CHECKSUM_CTRL_PER_NETIF=1 -DARDUINO_VARIANT="adafruit_feather" -DPICO_FLASH_SIZE_BYTES=8388608 @/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/lib/rp2040/platform_def.txt -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions -iprefix/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/ @/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/lib/rp2040/platform_inc.txt @/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/lib/core_inc.txt -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/include -fno-rtti -std=gnu++17 -g -pipe -w -x c++ -E -CC -DF_CPU=133000000L -DARDUINO=10607 -DARDUINO_ADAFRUIT_FEATHER_RP2040 -DBOARD_NAME="ADAFRUIT_FEATHER_RP2040" -DARDUINO_ARCH_RP2040 -Os -DWIFICC=CYW43_COUNTRY_WORLDWIDE -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/cores/rp2040 -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/variants/adafruit_feather -I/Users/steve/Documents/Arduino/libraries/Adafruit_TinyUSB_Library/src -I/Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/libraries/SPI/src -I/Users/steve/Documents/Arduino/libraries/arduinoFFT/src /Users/steve/Documents/Arduino/libraries/Adafruit_TinyUSB_Library/src/Adafruit_USBD_MIDI.cpp -o /dev/null
Alternatives for Adafruit_USBD_MIDI.h: []
ResolveLibrary(Adafruit_USBD_MIDI.h)
  -> candidates: []
exit status 1

Compilation error: exit status 1
#include <Adafruit_TinyUSB.h>      // TinyUSB-Bibliothek für USB-Funktionen (CDC, MIDI, etc.)
#include <arduino/midi/Adafruit_USBD_MIDI.h>    // USB-MIDI-Schnittstelle
#include <arduinoFFT.h>            // ArduinoFFT-Bibliothek für FFT-Funktionen

// MIDI Schnittstellen
Adafruit_USBD_CDC usb_serial;       // USB-Serial (CDC) Schnittstelle
Adafruit_USBD_MIDI usb_midi;        // USB-MIDI-Schnittstelle

// Funktionsprototypen
bool sendNoteOn(byte pitch, byte velocity);
bool sendNoteOff(byte pitch, byte velocity = 0);

// FFT Konfiguration
#define SAMPLES 256             // Anzahl der FFT-Samples (muss Potenz von 2 sein, z.B., 128, 256, 512, ...)
#define SAMPLING_FREQUENCY 1000 // Abtastrate in Hz (angepasst auf dein Setup)

// Onset-Erkennungsparameter
const float thresholdFactor = 1.5; // Faktor zur Anpassung des Schwellenwerts
float baseEnergy = 0.0;            // Basisenergie zur Normalisierung
bool firstRun = true;

// GPIO-Pins
const int audioPin = 26;            // Analogeingang A0 (GPIO26) des Pico
const int ledPin = 15;              // Beispiel-Pin für LED

// Dynamikvariablen
unsigned long lastOnsetTime = 0;    // Zeitpunkt des letzten Onsets
const unsigned long minOnsetInterval = 100; // Minimale Zeit zwischen Onsets (ms)
const unsigned long midiNoteDuration = 300; // MIDI-Noten-Dauer (ms)
bool noteOnActive = false;

// FFT Objekte
arduinoFFT FFT = arduinoFFT();

// Sample Arrays
double vReal[SAMPLES];
double vImag[SAMPLES];

// Zeitpunkt für Sampling
unsigned long samplingPeriod;
unsigned long lastSampleTime = 0;

void setup() {
  pinMode(audioPin, INPUT);
  pinMode(ledPin, OUTPUT);

  TinyUSBDevice.begin();
  usb_serial.begin(115200);
  usb_midi.begin();
  usb_serial.println("Setup complete. Ready for Onsets.");

  // Berechne Sampling-Periode
  samplingPeriod = 1000000 / SAMPLING_FREQUENCY; // in Mikrosekunden
}

void loop() {
  unsigned long currentMicros = micros();

  // Samples sammeln
  for (int i = 0; i < SAMPLES; i++) {
    // Warte bis zur nächsten Sampling-Periode
    while (micros() - currentMicros < samplingPeriod) {
      // Nichts tun
    }
    currentMicros += samplingPeriod;

    // Lese das analoge Signal und skaliere es auf +/-1.0
    int rawValue = analogRead(audioPin);
    double scaledValue = (rawValue - 2048) / 2048.0; // Annahme: ADC von 0 bis 4095, zentriert bei 2048

    vReal[i] = scaledValue;
    vImag[i] = 0.0; // Imaginary part ist 0
  }

  // Führe die FFT durch
  FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
  FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD);
  FFT.ComplexToMagnitude(vReal, vImag, SAMPLES);

  // Analysiere die Energie im relevanten Frequenzbereich (z.B., 50 Hz bis 150 Hz für E2)
  float energy = 0.0;
  int peakBin = FFT.MajorPeak(vReal, SAMPLES); // Suche die dominierende Frequenz
  float frequency = (peakBin * SAMPLING_FREQUENCY) / SAMPLES;

  // Definiere die Ziel-Frequenzen für die tiefe E-Saite und ihre Harmonischen
  float targetFrequencies[] = {82.41, 164.81, 247.21}; // E2, E3, E4
  int numTargets = sizeof(targetFrequencies) / sizeof(targetFrequencies[0]);
  float bandwidth = 5.0; // Hz

  for (int i = 0; i < numTargets; i++) {
    float target = targetFrequencies[i];
    for (int bin = 0; bin < SAMPLES / 2; bin++) { // Nur positive Frequenzen
      float freq = (bin * SAMPLING_FREQUENCY) / SAMPLES;
      if (abs(freq - target) <= bandwidth) {
        energy += vReal[bin];
      }
    }
  }

  // Initialisiere die Basisenergie
  if (firstRun) {
    baseEnergy = energy;
    firstRun = false;
  }

  // Onset-Erkennung basierend auf der Energie
  if (!noteOnActive && energy > (baseEnergy * thresholdFactor) && (millis() - lastOnsetTime > minOnsetInterval)) {
    usb_serial.println("Onset detected via FFT!");
    digitalWrite(ledPin, HIGH); // LED einschalten
    if (sendNoteOn(40, 127)) { // Sende MIDI-Note (E2)
      noteOnActive = true;
      lastOnsetTime = millis();
    }
  }

  // Note-Off senden, wenn die MIDI-Notendauer abgelaufen ist
  if (noteOnActive && (millis() - lastOnsetTime >= midiNoteDuration)) {
    if (sendNoteOff(40, 0)) { // Velocity auf 0 setzen
      noteOnActive = false;
      digitalWrite(ledPin, LOW); // LED ausschalten
      usb_serial.println("Note Off sent via FFT.");
    }
  }

  // Optional: Aktualisiere die Basisenergie periodisch, um sich an veränderte Bedingungen anzupassen
  if (millis() - lastOnsetTime > 1000) { // Alle 1 Sekunde
    baseEnergy = 0.95 * baseEnergy + 0.05 * energy; // Exponentielle Glättung
  }

  // Optional: Debug-Ausgabe für Serial Plotter
  usb_serial.print(energy);
  usb_serial.print(",");
  usb_serial.print(baseEnergy * thresholdFactor);
  usb_serial.print(",");
  usb_serial.print(noteOnActive ? 1 : 0);
  usb_serial.println();
}

// ====================================================================
// Hilfsfunktionen
// ====================================================================

// MIDI Note-On senden
bool sendNoteOn(byte pitch, byte velocity) {
  uint8_t noteOn[] = {0x90, pitch, velocity};
  if (usb_midi.write(noteOn, sizeof(noteOn))) {
    usb_midi.flush();
    return true;
  }
  return false;
}

// MIDI Note-Off senden
bool sendNoteOff(byte pitch, byte velocity) {
  uint8_t noteOff[] = {0x80, pitch, velocity};
  if (usb_midi.write(noteOff, sizeof(noteOff))) {
    usb_midi.flush();
    return true;
  }
  return false;
}

OK, I see the problem here:

I guess you copied the Adafruit_USBD_MIDI.cpp file to various locations in the library in hopes it would somehow fix the error, but what you did instead was break the library.

You can fix this by uninstalling the messed up copy of the library and then installing a fresh copy. I'll provide instructions you can follow to do that:

  1. Select Sketch > Include Library > Manage Libraries... from the Arduino IDE menus to open the "Library Manager" view in the left side panel.
  2. Type Adafruit TinyUSB Library in the "Filter your search..." field.
  3. Find the "Adafruit TinyUSB Library" entry in the list of search results.
  4. Hover the mouse pointer over the "Adafruit TinyUSB Library" entry.
  5. You will see a ●●● icon appear near the top right corner of the library entry. Click on that icon.
    A context menu will open.
  6. Select "Remove" from the menu.
    An "Uninstall" dialog will open.
  7. Click the "YES" button in the "Uninstall" dialog to confirm that you want to uninstall the library.
    The dialog will close.
  8. Wait for the uninstall process to finish, as indicated by a notification at the bottom right corner of the Arduino IDE window:

    ⓘ Successfully uninstalled library ...

  9. Select the newest version from the drop-down version menu at the bottom of the "Adafruit TinyUSB Library" entry.
  10. Click the "INSTALL" button at the bottom of the "Adafruit TinyUSB Library" entry.
  11. Wait for the installation process to finish, as indicated by a notification at the bottom right corner of the Arduino IDE window:

    ⓘ Successfully installed library ...

After making that change, try compiling or uploading your sketch again. Hopefully the "Adafruit_USBD_MIDI.h: No such file or directory " error will no longer occur.

Thank you! That solved at least part of my problem.
However now it complains that there are multiple libraries installed. Appearantly the board package for the raspberry pie also installed a tinyUSB library. Also the naming for the arduinoFFT seem to conflict with lower case.. Here's the error: `/Users/steve/Documents/Arduino/FFT/FFT.ino:33:1: error: 'arduinoFFT' does not name a type; did you mean 'ArduinoFFT'?
33 | arduinoFFT FFT = arduinoFFT();
| ^~~~~~~~~~
| ArduinoFFT
/Users/steve/Documents/Arduino/FFT/FFT.ino: In function 'void loop()':
/Users/steve/Documents/Arduino/FFT/FFT.ino:76:3: error: 'FFT' was not declared in this scope
76 | FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
| ^~~
Multiple libraries were found for "Adafruit_TinyUSB.h"
Used: /Users/steve/Documents/Arduino/libraries/Adafruit_TinyUSB_Library
Not used: /Users/steve/Library/Arduino15/libraries/Adafruit_TinyUSB_Library
Not used: /Users/steve/Library/Arduino15/packages/rp2040/hardware/rp2040/4.4.1/libraries/Adafruit_TinyUSB_Arduino
exit status 1

Compilation error: 'arduinoFFT' does not name a type; did you mean 'ArduinoFFT'?`

The library is called arduinoFFT; the class inside it is ArduinoFFT. So you need to change

to ArduinoFFT FFT = ArduinoFFT();

This is progress at least!

This isn't necessarily a problem. Arduino IDE is only making sure you are aware of the fact that multiple libraries that matched your #include directive are installed. You should always pay attention to these messages, but you only need to worry about them if you see that the IDE chose a different library from the one you intended to be used. Arduino IDE uses a sophisticated algorithm for deciding which library to use in this case, so it usually does pick the appropriate library.

I'm not experienced enough with the "Raspberry Pi Pico/RP2040" boards platform to say whether it is important for you to use the copy of the library bundled with the platform, or if it is OK to use the version you get from Library Manager.

I also encountered this error when I tried to compile your sketch. It is not related to your use of the Library Manager installed Adafruit TinyUSB Library because I still encounter it even when I remove that library installation and use the version bundled with the Raspberry Pi Pico/RP2040 platform.

Did you find the ArduinoFFT code somewhere on the Internet? If so, please provide a link to where you found it. That might provide us with some information that will allow us to more effectively assist you.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.