Does MIDI Library 2.6 work with Teensy3.0?

Status
Not open for further replies.

foam_FORM

Well-known member
Does anyone know if MIDI library 3.2 is necessary for Teensy 3.0 or should 2.6 work just fine? The reason I ask is because I am having errors compiling with 3.2 (even when I comment out the line that deals with "word")
 
3.2 compiled for me once I had commented the line with word. This is with Arduino 1.0.4.
I can't try it out right now though.

Pete
 
The reason I ask is because I am having errors compiling with 3.2 (even when I comment out the line that deals with "word")

You could include the actual error in your message (use copy and paste) or a screenshot.

MIDI 2.6 and 3.2 are on my to-do list to test (right now, I'm working on the Time library, which is turning out to be much more difficult than I'd anticipated). It looks like I loaned my MIDI test board to someone and never got it back, so I might have to build another one or hook it up on a breadboard.
 
I've done a quick and dirty test of Midi 2.6 and the MIDI_Input_Test_Teensy sketch works most of the time. Midi 3.2 didn't work.
I can't test the midi output yet - it's getting late. Manaña.

Pete
 
Works for me

I can't replicate the "didn't work". On a fresh install of Arduino 1.0.4 plus Teensyduino 1.13 (Win 7 64bit) I moved libraries/MIDI (which is version 2.6) out of the way, then downloaded MIDI 3.2 from sourceforge and put the MIDI folder inside libraries.

I then edited MIDI.h as follows:
change Serial to Serial1
Code:
#define USE_SERIAL_PORT         Serial1      // Change the number (to Serial1 for example) if you want
                                            // to use a different serial port for MIDI I/O.
comment out the definition of word
Code:
typedef uint8_t byte;
// typedef uint16_t word;

Examples > MIDI > MIDI_basic_IO. Select Teensy 3.0 under boards (USB type was keyboard+mouse+joystick). Compile. No errors. Upload. No errors, reboot ok.

I haven't breadboarded a DIN socket etc to check it actually sends anything,, but it certainly compiles without error.
 
I've done a quick and dirty test of Midi 2.6 and the MIDI_Input_Test_Teensy sketch works most of the time. Midi 3.2 didn't work.

I don't have a MIDI_Input_Test_Teensy sketch in MIDI 3.2. Where does it come from? Do you have both 2.6 and 3.2 installed at once and if so, how do you know which one is being used?

3.2 has three examples - MIDI_BASIC_IO, MIDI_Callbacks and MIDI_Input. All three compile correctly with the board set to Teensy 3.0 (or 2.0, just checked that too).

Edit: OK, found that example in the 2.6 directory I had moved out of the way. Compiled with 3.2. No errors.
 
I don't have a MIDI_Input_Test_Teensy sketch in MIDI 3.2. Where does it come from? Do you have both 2.6 and 3.2 installed at once and if so, how do you know which one is being used?

3.2 has three examples - MIDI_BASIC_IO, MIDI_Callbacks and MIDI_Input. All three compile correctly with the board set to Teensy 3.0 (or 2.0, just checked that too).

Edit: OK, found that example in the 2.6 directory I had moved out of the way. Compiled with 3.2. No errors.

Yes, I have made sure that I only have one MIDI library in there at once since they both have the same MIDI.h title

I made the suggested modifications to MIDI.h from Arduino MIDI Library 3.2 (Sourceforge) and am getting the same error message:

In file included from C:\Users\Spartan's Lounge\Documents\arduino-1.0.3\hardware\teensy\cores\teensy3/WProgram.h:15:0,
from C:\Users\Spartan's Lounge\Documents\arduino-1.0.3\hardware\teensy\cores\teensy3/Arduino.h:1,
from simple_midi_sequence___pjrc.ino:3:
C:\Users\Spartan's Lounge\Documents\arduino-1.0.3\hardware\teensy\cores\teensy3/wiring.h:89:22: error: conflicting declaration 'typedef unsigned int word'
In file included from simple_midi_sequence___pjrc.ino:1:0:
C:\Users\Spartan's Lounge\Documents\arduino-1.0.3\libraries\MIDI/MIDI.h:65:18: error: 'word' has a previous declaration as 'typedef uint16_t word'

I will say that I am using Arduino 1.03 but commenting out that line did allow me to compile once but the uploaded code did not output MIDI. I am not able to repeat even that result currently, however.
I have been using MIDI as the board type. Did you suggest to use keyboard+mouse+joystick? I am using MIDI for the board type and AVRISP mkII for my programmer. Is that all correct? Also 48hz clock speed...
 
The board type should be serial. The MIDI 2.6 and 3.2 libraries don't use the T3 as a USB MIDI device. They just read/write midi messages on the Serial port.

Pete
 
I am attempting to use MIDI IN actually to play notes on my laptop software via pushbuttons connected to the Teensy 3.0... I will try serial tonight after work (tomorrow morning) since I have actually been using MIDI as the board type this whole time. I have been using 47ohm resistors on the MIDI jack, but I am connected to VIN, not 3.3V so I have also tried 220ohm resistors. I will post hardware pictures if serial does not work.
 
What VIN are you running? If it's 5V, I would suggest you do not connect your MIDI Out resistors to them. Teensy 3's pins are not 5V tolerant. Make sure they are connected to 3.3V and use 47ohm.
 
The board type should be serial. The MIDI 2.6 and 3.2 libraries don't use the T3 as a USB MIDI device. They just read/write midi messages on the Serial port.
Agreeing with your second sentence and correcting the first, the USB type can be anything, since USB is not being used here. Setting it to Serial means you want a virtual serial-over-USB set up (for example, to display debug messages on the Serial monitor).
However, remember to edit MIDI.h to change Serial to Serial1 (or Serial2 or Serial3, depending on what pins you are using) since Serial is the Serial-over-USB one.
 
I am attempting to use MIDI IN actually to play notes on my laptop software via pushbuttons connected to the Teensy 3.0.
That would be MIDI Out, on the Teensy. Which you would connect to MIDI In on your laptop audio interface.
MIDI In on the Teensy would be the circuit with the optocoupler (which you would connect to MIDI Out on a keyboard or other controller).

I will try serial tonight after work (tomorrow morning) since I have actually been using MIDI as the board type this whole time.
The USB type does not matter here, since you are not using USB to connect.

I have been using 47ohm resistors on the MIDI jack, but I am connected to VIN, not 3.3V so I have also tried 220ohm resistors. I will post hardware pictures if serial does not work.
I would use the 3V3 pin. Vin is unregulated (and is connected to the USB 5-ish volts, if I recall correctly).
 
I breadboarded a DIN MIDI-Out, with a Teensy 3.0. Not having 50R resistors to hand, I used two 100R in parallel. The circuit was pin1 (Serial1 Tx) to 50R to DIN pin 4; DIN pin5 to 50R to 3V3 on Teensy; DIN pin 2 to GND.

The following example compiled (with MIDI 3.2), uploaded, and ran correctly. The MIDI Out was connected to the MIDI-I on my audio interface (Presonus AudioBox 44VSL). I checked first with MIDI-OX to see the MIDI stream, then ran it into a software instrument (Kontakt 5.0) to make sure it produced the expected sounds. All worked OK.

Code:
[COLOR=#7E7E7E]/*[/COLOR]
[COLOR=#7E7E7E]Teensy 3 with MIDI DIN and MIDI library 3.2.[/COLOR]
[COLOR=#7E7E7E] Edit MIDI.h to send MIDI to Serial1 (pin 1)[/COLOR]
[COLOR=#7E7E7E] */[/COLOR]

#include <[COLOR=#CC6600]MIDI[/COLOR].h>
#define LED 13               [COLOR=#7E7E7E]// LED pin on Arduino board[/COLOR]

[COLOR=#CC6600]byte[/COLOR] note;

[COLOR=#CC6600]void[/COLOR] [COLOR=#CC6600][B]setup[/B][/COLOR]() {
  [COLOR=#CC6600]MIDI[/COLOR].[COLOR=#CC6600]begin[/COLOR](1);   [COLOR=#7E7E7E]// Launch MIDI on channel 1[/COLOR]
  [COLOR=#CC6600]pinMode[/COLOR](LED, [COLOR=#006699]OUTPUT[/COLOR]);
  [COLOR=#CC6600]digitalWrite[/COLOR](LED,[COLOR=#006699]LOW[/COLOR]);   
  [COLOR=#CC6600]delay[/COLOR](2000);                [COLOR=#7E7E7E]// Wait for a bit  before starting[/COLOR]
}

[COLOR=#CC6600]void[/COLOR] [COLOR=#CC6600][B]loop[/B][/COLOR]() {
  note = [COLOR=#CC6600]random[/COLOR](32,70);
  [COLOR=#CC6600]digitalWrite[/COLOR](LED,[COLOR=#006699]HIGH[/COLOR]);       [COLOR=#7E7E7E]// Blink the LED[/COLOR]
  [COLOR=#CC6600]MIDI[/COLOR].[COLOR=#CC6600]sendNoteOn[/COLOR](note,92,1);   [COLOR=#7E7E7E]// Send a Note (pitch random, velo 3/4 on channel 1)[/COLOR]
  [COLOR=#CC6600]for[/COLOR] ([COLOR=#CC6600]int[/COLOR] i=0; i<3000; i+=20) {[COLOR=#7E7E7E]// MIDI pitch bend range is +- 8k[/COLOR]
    [COLOR=#CC6600]MIDI[/COLOR].[COLOR=#CC6600]sendPitchBend[/COLOR](i,1);    [COLOR=#7E7E7E]// swoop a bit[/COLOR]
    [COLOR=#CC6600]delay[/COLOR](12);
  }
  [COLOR=#CC6600]MIDI[/COLOR].[COLOR=#CC6600]sendNoteOff[/COLOR](note,0,1);   [COLOR=#7E7E7E]// Stop the note[/COLOR]
  [COLOR=#CC6600]digitalWrite[/COLOR](LED,[COLOR=#006699]LOW[/COLOR]);   
  [COLOR=#CC6600]delay[/COLOR](500);                [COLOR=#7E7E7E]// Wait for a bit between notes    [/COLOR]
}
 
Last edited:
I see that the MIDI library has moved to GitHub, and there is a MIDI 4.0 being prepared for release. There has been some refactoring, so instead of editing MIDI.h there is now a midi_Settings.h Also I see support for Leonardo, with USB being detected (the code assumes that means Leonardo) and MIDI assigned to Serial1. Its also now possible to instantiate multiple MIDI objects (there is an example with a MIDI merger).

This is the auto serial instantiation (no Teensy support)

Code:
// Default serial port configuration (if MIDI_AUTO_INSTANCIATE is set)



// Set the default port to use for MIDI.
#if MIDI_AUTO_INSTANCIATE
#   ifdef ARDUINO
#       ifdef USBCON
#           define MIDI_DEFAULT_SERIAL_PORT     Serial1 // For Leonardo
#       else
#           define MIDI_DEFAULT_SERIAL_PORT     Serial  // For other Arduinos
#       endif
#       define MIDI_DEFAULT_SERIAL_CLASS        HardwareSerial
#       include "Arduino.h"
#       include "HardwareSerial.h"
#   else
#       error Auto-instanciation disabled. Use MIDI_CREATE_INSTANCE macro.
#   endif
#endif
 
That would be MIDI Out, on the Teensy. Which you would connect to MIDI In on your laptop audio interface.
MIDI In on the Teensy would be the circuit with the optocoupler (which you would connect to MIDI Out on a keyboard or other controller).


The USB type does not matter here, since you are not using USB to connect.


I would use the 3V3 pin. Vin is unregulated (and is connected to the USB 5-ish volts, if I recall correctly).

Ah..yes. Sorry I meant MIDI OUT. I have been using out so far, not in. I am thinking my problem is the Voltage source. I will try 3.3V here soon but have another project I have to attend to for a day or so. Thanks so much! I will try out your example here soon, but last time I hit compile the same error came up telling be about the previous declaration of word, even though I had commented out the line with word and changed Serial to Serial1. I am using Arduino 1.03.....is it not refreshing/referencing the library correctly?
 
Check the libraries folder inside your sketch folder, as well as the main libraries folder. You might have a copy in there as well, in which case the edits to the one in the main libraries folder will have no effect *cough* happend to a freind of mine *cough*
 
Check the libraries folder inside your sketch folder, as well as the main libraries folder. You might have a copy in there as well, in which case the edits to the one in the main libraries folder will have no effect *cough* happend to a freind of mine *cough*


I don't think that is the problem, Nan. When I delete the MIDI library it tells me no such file exists, and there is no other library file in my sketch folder-- so I think that probably means it is referring to the file I am editing, but it doesn't seem to recognize the change when I comment out that line now. I tried //typedef and // typedef --with a space and without....no luck. Maybe it was because it was arduino 1.02 before when it was working but I honestly don't know anymore. I want to try out the 3.3v pin but if I can't get the library to compile there is little use for that. There must be a simple "tweak" I am missing.
 
Check the libraries folder inside your sketch folder, as well as the main libraries folder. You might have a copy in there as well, in which case the edits to the one in the main libraries folder will have no effect *cough* happend to a freind of mine *cough*

Nan, are you sure you are using 3.0 as your board type? I ask because I CAN get MIDI Library 3.2 to compile with 2.0 as the board type but with 3.0 I get the typedef error no matter what I do.
 
Absolutely sure. a) just checked b) am looking at Teensy 3.0 on breadboard hooked up to MIDI socket c) it wouldn't upload correctly, otherwise.

Can you copy and paste your exact error message? Also, if you go Help > Abou Arduino what is the version number? (I wonder igf you have multiple versions installed and the one you are editing is not the one you are using).
 
Absolutely sure. a) just checked b) am looking at Teensy 3.0 on breadboard hooked up to MIDI socket c) it wouldn't upload correctly, otherwise.

Can you copy and paste your exact error message? Also, if you go Help > Abou Arduino what is the version number? (I wonder igf you have multiple versions installed and the one you are editing is not the one you are using).

Well, if I use 2.0 for my board it does upload the code/library correctly and 3.0 will not...I cannot copy anything from the error message section-- it will only let me copy the code. It is the same error message that came before I commented out typedef like this: ;//typedef uint16_t word; that tells me word has been used in a previous declaration. It seems like the computer is having troubles updating the library changes but I am not sure why.
 
Absolutely sure. a) just checked b) am looking at Teensy 3.0 on breadboard hooked up to MIDI socket c) it wouldn't upload correctly, otherwise.

Can you copy and paste your exact error message? Also, if you go Help > Abou Arduino what is the version number? (I wonder igf you have multiple versions installed and the one you are editing is not the one you are using).

My Arduino version number is 1.04 now. I was using 1.03 at the time of the last post. Teensy 2.0 would compile but no MIDI signals again. I used 2 220ohm resistors and quadruple-checked EVERYTHING as far as hardware/code/libraries/redundancies/settings/etc.,/etc., that I can possibly find and still no MIDI. There has to be something very simple I am overlooking or else my CPU just has a weird bug/incompatibility. I am going to put this aside for a while and move on unless anyone has any final suggestions...I very much appreciate all of your help so far. @PaulStoffregen - please let me know when you have tested MIDI OUT on 3.0! I would be interested to see if you have any success with it.

@Nantonos: Either we living in parallel universes, am I just that noob, or you are pulling my leg because I am just that noob. I really hope it's not the third because that was a lot of time.
 
Status
Not open for further replies.
Back
Top