Hello,
I am tinkering with a Teensy 4.0 in PlatformIO, VSCode. I tried to write a simple patch, so that the Teensy sends some measured values via Midi. I was doing this using the already instantiated usb_midi_class-object called usbMidi (Declared in framework-aruinoteensy/cors/teensy4/usb_midi.h). Unfortunately both Intellisense and the Compiler say ‘usbMidi’ was not declared in this scope.
I tried boiling the project down to the crucial lines to showcase the problem.
platformio.ini:
[env:teensy40]
platform = teensy
board = teensy40
framework = arduino
build_flags = -D USB_MIDI
main.cpp:
#include <Arduino.h>
#include <MIDIUSB.h>
#include <MIDI.h>
#include <MIDI.hpp>
#include <usb_midi.h>
void setup() {
usbMidi.begin();
}
void loop() {
}
The above #includes are a chronological representation of my attempts to solve the problem: At the beginning, only Arduino.h was included and compiled and step by step the others where added and tested to compile. I even tried adding #define USB_MIDI before the #includes. The resulting error I get from the compiler in all cases:
src\main.cpp: In function 'void setup()':
src\main.cpp:77:3: error: 'usbMidi' was not declared in this scope
usbMidi.begin();
^
*** [.pio\build\teensy40\src\main.cpp.o] Error 1
=========================================================== [FAILED] Took 2.35 seconds ===========================================================
(The line-number in the above message shows 77, because there’s a lot of commented out code, that I removed for this post)
I tried to use the PlatformIO:Clean option and recompile, Rebuild Intellisense Index, Update Project Libraries, Update All and nothing works. I looked into the usb_midi.h and saw that the macro MIDI_INTERFACE is displayed #defined and activates all the code. It is defined in usb_desc.h under the condition that USB_MIDI is #defined, which also shows up active. I tried saving multiple times, reopening the project, restarting vscode, the computer… I created new projects trying to use usbMidi. No success.
Strangely enough, another project I coded in January still compiles with precisely all the same settings in the platformio.ini and using usbMidi in other cpp-files linked by included header-files. The latter cpp-files only #include <Arduino.h> and none of the other ones.
At this point I don’t know what to do. Can anybody help me? Maybe I overlooked a crucial detail? Thank you!