MIDI over USB Arduino Leonardo (TeeOnArdu)

Hi, Some time ago I built an Arduino MIDI controller, using the Leonardo, using the Teensy USBMIDI libraries for the ATmega32U4 by installing Georg Werner's TeeOnArdu software. This worked perfectly fine in the Arduino IDE 1.0.6, with the TeeOnArdu version of the 8th of May 2014, and I have been using this software combination ever since. Now I'm trying to get it work with the Arduino IDE 1.6.x, but without success ... Georg Werner's version was modified to work with the IDE 1.6 line, but now it works on neither the 1.0.6 nor the 1.6.x version. After reading Spark404's comment, I tried using his version. This works fine in Arduino 1.6.7: the MIDI examples compile without errors, the Leonardo is recognized as a MIDI device in all OSs, and it can send and receive messages. Success, right? Well, not quite ...

The library I wrote uses the precompiler to determine the board (It uses a completely different approach for MIDI over USB on the Uno, for example) using preprocessor directives like #if defined(__AVR_ATmega32U4__). My code relies on the PJRC Rotary Encoder Library as well, and this library uses #elif defined(__AVR_ATmega32U4__) && !defined(CORE_TEENSY) to set the right interrupts for the Leonardo. In Arduino 1.0.6, this worked, because when compiling for TeeOnArdu (Georg Werner's version from 2014), AVR_ATmega32U4 was defined, and CORE_TEENSY wasn't.

In Arduino 1.6.x however (using Spark404's version of TeeOnArdu), it is the opposite: CORE_TEENSY is set (this is fixed very easily) but more importantly, AVR_ATmega32U4 is not defined, which is a much bigger problem.

Is there a way I can edit the board definitions of TeeOnArdu, so that AVR_ATmega32U4 is defined? I do not understand what determines which of these defines are set, so if anyone could explain this, or at least point me to a page with the necessary information, that would help a lot.

Thanks in advance! Pieter

(P.S: The Instructable I wrote last year, using Arduino 1.0.6, can be found here.)

I seem to remember that the newest IDE has a simpler set of #define's which look more like the names of the boards. It was in the Arduino blog or maybe a tutorial in the playground? Definitely somewhere on Arduino.cc

Do you also have Teensy's or can you just hack the library until it works on just this one board and no others? (remove all #define code not relevant to your board.)

I solved it by comparing all files in the hardware/arduino folder with the ones in the hardware/TeeOnArdu. I suspected that it was a compiler option, and indeed, there was a flag -mmcu={build.mcu} in the platforms.txt file. Then I noticed that Arduino 1.6 had some new compile patterns, including these two:

## Preprocessor
preproc.includes.flags=-w -x c++ -M -MG -MP
recipe.preproc.includes="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} {preproc.includes.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}"

preproc.macros.flags=-w -x c++ -E -CC
recipe.preproc.macros="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} {preproc.macros.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{preprocessed_file_path}"

The TeeOnArdu's platforms.txt file didn't have these recipes, so build.mcu was not passed on to the preprocessor, resulting in AVR_ATmega32U4 being undefined. According to the documentation, it is defined by the compiler, based on the -mmcu option.

I ended up copying the whole Arduino platforms.txt file, just to make sure everything was up to date. After adding some -D options, to set some defines for the menu options specified in boards.txt, I was able to compile and upload blink. Midi still didn't work, so I replaced the entire core by the Arduino core. Then I enabled verbose output of the compiler, and added the necessary parts from TeeOnArdu, piece by piece, until everything compiled without errors...

It was quite time-consuming, but now both MIDI and Blink compile and upload fine, and I can see the MIDI messages on my computer.

Anyway, thanks for your reply :)