Currently trying to get a teensy 3.5 to spam a series of notes in a loop over USB and hardware serial, which I am pretty sure it can do.

I have a MIDI circuit set up as per the specifications here: https://www.pjrc.com/teensy/td_libs_MIDI.html And currently have it booping a looping grouping of notes through massive embedded in ableton over a 5 PIN DIN circuit feeding into a generic MIDI 5 Pin DIN -> USB converter.

 #include <MIDI.h>

#define HWSerial Serial1
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
const int channel = 1;

void setup() {

  HWSerial.begin(9600);
  MIDI.begin();
}

void loop() {
  int note;
  for (note=10; note <= 127; note++) {
    MIDI.sendNoteOn(note, 100, channel);
    delay(200);
    MIDI.sendNoteOff(note, 100, channel);
  }
  delay(2000);
}

I am lead to believe that when working with the USB serial output on the teensy you simply refer to the port as 'Serial' and for the others it's 'Serial1', 'Serial2', and so on.

I have tried using serial in place of the arguments within MIDI_CREATE_INSTANCE and also tried using MIDI_CREATE_DEFAULT_INSTANCE which should do this setup on the default serial port, which I assume is USB? (This worked fine on my arduino mega setup where I was using the 16u2 chip as a serial -> USB midi converter as per this method: https://github.com/ddiakopoulos/hiduino)

I'm just a little stumped as I have managed to get the code to compile using default instance and it appears as a midi device in windows device manager and also in ableton when I set USB Type: Serial + MIDI from arduinos tools dropdown box but does not output any notes :(

Can anyone help me get this working?

I'm currently toying with:

    #include <MIDI.h>

const int channel = 1;

void setup() 
{

}

void loop() 
{
  int note;
  for (note=20; note <= 63; note++) // Range was changed from 10:127 to save eardrums. 
  {
    usbMIDI.sendNoteOn(note, 100, channel);
    delay(200);
    usbMIDI.sendNoteOff(note, 100, channel);
  }
  delay(2000);
}

but get

    C:\Users\Jamie\AppData\Local\Temp\arduino_build_144363/..\arduino_cache_283435\core\core_teensy_avr_teensy35_usb_serialmidi,speed_120,opt_o2std,keys_en-us_4939f5412a75a8560acb0f9e98268f02.a(pins_teensy.c.o): In function `_init_Teensyduino_internal_':

C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/pins_teensy.c:582: undefined reference to `analog_init'

collect2.exe: error: ld returned 1 exit status

Error compiling for board Teensy 3.5.

and if I try inluding 'usbMIDI' I get

F:\GigaTech\MMMM_Beta_Code\debug\TeensyUSBMIDILoopTest\TeensyUSBMIDILoopTest.ino:1:21: fatal error: usbMIDI.h: No such file or directory

compilation terminated.

Error compiling for board Teensy 3.5.

although midiUSB is definitely installed :S


------------------------------C O N T I N U E D ----------------------------

Ok so I now have a working sketch for both USB and Hardware MIDI comms but I can't seem to get them to work simultaneously. My code for the hardware is as shown above, and the USB method is below:

 #include <MIDI.h>

MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
const int channel = 1;

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

void loop() {
  int note;
  for (note=10; note <= 127; note++) 
  {
    usbMIDI.sendNoteOn(note, 100, channel);
    delay(200);
    usbMIDI.sendNoteOff(note, 100, channel);
  }
  delay(2000);
}

I sort of assumed it would be possible to do something like this:

 #include <MIDI.h>

#define HWSerial Serial1
MIDI_CREATE_INSTANCE(HardwareSerial, Serial, MIDI); // 5 Pin DIN Out
const int channel = 1;

void setup() 
{  
  HWSerial.begin(9600);
  MIDI.begin();  
}

void loop() {
  int note;
  for (note=20; note <= 63; note++) // Range was changed from 10:127 to save eardrums. 
  {
    usbMIDI.sendNoteOn(note, 100, channel);
    MIDI.sendNoteOn(note, 100, channel);
    delay(200);
    usbMIDI.sendNoteOff(note, 100, channel);
    MIDI.sendNoteOff(note, 100, channel);
  }
  delay(2000);
}

But It doesn't seem to work. The code compiles and uploads just fine, however, ableton only sees MIDI messages coming over the teensy usb port and not through my MIDI receiver. I wondered if this is because the two are both being routed to my PC via a usb port but this shouldn't be a problem surely. I have also tried assigning the USB and hardware MIDI sends to different channels but to no avail.

I would love to get these both working simultaneously.

migrated from electronics.stackexchange.com Jun 4 at 15:29

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • Why are the logs full of mentions of "avr" for a board that does not use any sort of AVR chip??? Is this really bad naming and file locations in a plugin, or is the selected board configuration all mixed up? – Chris Stratton Jun 4 at 17:24

Just use usbMidi.

#include <MIDI.h>

MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
const int channel = 1;

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

void loop() {
  int note;
  for (note=10; note <= 127; note++) {
    MIDI.sendNoteOn(note, 100, channel);
    usbMIDI.sendNoteOn(note, 100, channel);
    delay(200);
    MIDI.sendNoteOff(note, 100, channel);
    usbMIDI.sendNoteOff(note, 100, channel);
  }
  delay(2000);
}
  • I've been trying to do it this way as that's how I had it working with the arduino mega implementation but I just get this error: C:\Users\Jamie\AppData\Local\Temp\arduino_build_144363/..\arduino_cache_283435\core\core_teensy_avr_teensy35_usb_serialmidi,speed_120,opt_o2std,keys_en-us_4939f5412a75a8560acb0f9e98268f02.a(pins_teensy.c.o): In function _init_Teensyduino_internal_': C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/pins_teensy.c:582: undefined reference to analog_init' collect2.exe: error: ld returned 1 exit status Error compiling for board Teensy 3.5. – GigaJoules Jun 4 at 16:22
  • I'm pretty sure there is a proper way to do this, by opening another port with very similiar implementation to the hardware output code, but cant seem to get it right – GigaJoules Jun 4 at 16:23
  • The code I posted compiles just fine for me (Arduino 1.8.1, Teensyduino 1.41, Teensy 3.5, USB: Serial+MIDI). This is the proper way. Forget everything about MIDI USB on the Mega, it is completely different from the Teensy. – tttapa Jun 4 at 16:32
  • Strange, I tried a literal copy / paste of that code you posted and get: C:\Users\Jamie\AppData\Local\Temp\arduino_build_144363/..\arduino_cache_283435\core\core_teensy_avr_teensy35_usb_serialmidi,speed_120,opt_o2std,keys_en-us_4939f5412a75a8560acb0f9e98268f02.a(pins_teensy.c.o): In function _init_Teensyduino_internal_': C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/pins_teensy.c:582: undefined reference to analog_init' collect2.exe: error: ld returned 1 exit status Error compiling for board Teensy 3.5. – GigaJoules Jun 4 at 16:38
  • 1
    Yes, this has worked beautifully (Got held up by windows updates), I'll test tomorrow using both methods simultaneously, thanks! – GigaJoules Jun 4 at 18:06

So I managed to get both working sumultaneously!

It seems that no declaration of a MIDI instance is necessary for teensy MIDI over USB, and I had a small error in my code, Said function declaration should read 'Serial1' not 'Serial'.

Working code is below! :)

#include <MIDI.h>

#define HWSerial Serial1
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI); // 5 Pin DIN Out
const int HWChannel = 2;
const int USBChannel = 1;

void setup() 
{  
  HWSerial.begin(9600);
  MIDI.begin();  
}

void loop() {
  int note;
  for (note=20; note <= 63; note++) // Range was changed from 10:127 to save eardrums. 
  {
    usbMIDI.sendNoteOn(note, 100, USBChannel);
    MIDI.sendNoteOn(note, 100, HWChannel);
    delay(200);
    usbMIDI.sendNoteOff(note, 100, USBChannel);
    MIDI.sendNoteOff(note, 100, HWChannel);
  }
  delay(2000);
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.