TEENSY 3.1 – RX & TX for MIDI Circuit

Status
Not open for further replies.

nevvkid

Member
Hi there.
I made a breakout board which can hold a TEENSY 3.1 or Arduino UNO.
This board has MIDI input and output.
Now i tried to get the board working with the teensy plugged in. (UNO works like a charm.)
But so far i don't get it working.

The MIDI circuit uses the normal RX/TX lines on the UNO and RX1/TX1 with the TEENSY.
Do i have to change the code to use RX1/TX1 with the teensy?

Code:
#include <MIDI.h>

// Simple tutorial on how to receive and send MIDI messages.
// Here, when receiving any message on channel 4, the Arduino
// will blink a led and play back a note for 1 second.

MIDI_CREATE_DEFAULT_INSTANCE();

#define LED 13   		    // LED pin on Arduino Uno

void setup()
{
    pinMode(LED, OUTPUT);
    MIDI.begin(4);          // Launch MIDI and listen to channel 4
}

void loop()
{
    if (MIDI.read())                // If we have received a message
    {
        digitalWrite(LED,HIGH);
        MIDI.sendNoteOn(42,127,1);  // Send a Note (pitch 42, velo 127 on channel 1)
        delay(1000);		        // Wait for a second
        MIDI.sendNoteOff(42,0,1);   // Stop the note
        digitalWrite(LED,LOW);
    }
}

This is the BASIC IO Sample from the latest stable release of the arduino midi library > https://github.com/FortySevenEffects/arduino_midi_library/releases/tag/4.2

Does the teensy need a change on "MIDI.read"?
Maybe tell which Serial Pins to use?

Thank you!

Best, J
 
Which version of Arduino are you using?

I installed that v4.2 library, moved the existing v3.2 library out of the way, tried Arduino 1.0.6 with Teensyduino 1.20, board set to Arduino Uno and the MIDI_Basic_IO example failed to compile
Code:
Arduino: 1.0.6 + Td: 1.20 (Windows 7), Board: "Arduino Uno"
D:\Arduino\arduino-1.0.6-td120\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -ID:\Arduino\arduino-1.0.6-td120\hardware\arduino\cores\arduino -ID:\Arduino\arduino-1.0.6-td120\hardware\arduino\variants\standard -ID:\Arduino\arduino-1.0.6-td120\libraries\MIDI C:\Users\Chris\AppData\Local\Temp\build320908759231787698.tmp\MIDI_Basic_IO.cpp -o C:\Users\Chris\AppData\Local\Temp\build320908759231787698.tmp\MIDI_Basic_IO.cpp.o 

MIDI_Basic_IO:7: error: expected constructor, destructor, or type conversion before ';' token

If you are using Arduino 1.5.x, TeensyDino is not compatible with it. I see there is a separate src diectory which looks like a 1.5.x library to me.

I didn't try a clean install of Arduino 1.0.6 to see if MIDI 4.2 is compatible with it. Looking at the code ther are some useful additions compared to 3.2 but also the code looks a bit more abstracted and C++-ish which is not necessarily a benefit.

Edit: Clean install of Arduino 1.0.6, no teensyduino, MIDI 4.2 removed from sketches/libraries folder and put in arduino-1.0.6/libraries, same example fails to comile with the same error (board set to Uno).
 
Last edited:
It would also be useful to know what circuitry is on your breakout board, given that Uno is a 5V chip and Teensy 3.1 is a 3V3 chip (although 5V tolerant on digirtal inputs). What opto isolator are you using and what are the resistor values?
 
Hi Nantonos,

i am using Arduino 1.0.6 with Teensyduino 1.20 and v4.2 of the Arduino midi lib on a mac using yosemite - OSX 10.10.

Compiling for the UNO isn't a problem. Everything runs just fine.

1. One Teensy is powered by my breakoutboard - with a step-down delivering 5V to the VIN. (I did cut the VUSB from VIN)

The circuit on the breakoutboard looks like this:
midi-circuit.png

2. I tried to use a factory fresh teensy together with the sparkfun midi breakout. https://www.sparkfun.com/products/9598
Doesn't work either.

FYI the Basic IO Sample of v3.2 of the MIDI Lib coming with teensyduino does not compile for me.

Code:
#include <MIDI.h>
/*
  Basic I/O MIDI tutorial
  by Franky
  28/07/2009
*/

#define LED 13   		// LED pin on Arduino board

void setup() {
  pinMode(LED, OUTPUT);
  MIDI.begin(4);            	// Launch MIDI with default options
				// input channel is set to 4
}

void loop() {
  if (MIDI.read()) {
    digitalWrite(LED,HIGH);     // Blink the LED
    MIDI.sendNoteOn(42,127,1);  // Send a Note (pitch 42, velo 127 on channel 1)
    delay(1000);		// Wait for a second
    MIDI.sendNoteOff(42,0,1);   // Stop the note
    digitalWrite(LED,LOW);    	
  }
}

Showing following Error:
" This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.6 + Td: 1.20 (Mac OS X), Board: "Teensy 3.1"
MIDI_Basic_IO.pde: In function 'void setup()':
MIDI_Basic_IO:12: error: 'MIDI' was not declared in this scope
MIDI_Basic_IO.pde: In function 'void loop()':
MIDI_Basic_IO:17: error: 'MIDI' was not declared in this scope"
 
OK this may be a Teesyduino issue.

A) Arduino 1.0.6 fresh (from zip), Sketch > Import Library, point to arduino_midi_library-master.zip downloaded from GitHub. MIDI_Basic_IO example comiles correctly for Uno. Library is installed under sketches/libraries. It looks as if import, rather than just moving the directory, is needed.

b) Arduino 1.0.6 + TeensyDuino, Sketch > Import Library, point to arduino_midi_library-master.zip downloaded from GitHub which fails because it is already there. MIDI_Basic_IO example fails to compile correctly for Uno.

Code:
Arduino: 1.0.6 + Td: 1.20 (Windows 7), Board: "Arduino Uno"
D:\Arduino\arduino-1.0.6-td120\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -ID:\Arduino\arduino-1.0.6-td120\hardware\arduino\cores\arduino -ID:\Arduino\arduino-1.0.6-td120\hardware\arduino\variants\standard -ID:\Arduino\arduino-1.0.6-td120\libraries\MIDI C:\Users\Chris\AppData\Local\Temp\build5868637255104533569.tmp\MIDI_Basic_IO.cpp -o C:\Users\Chris\AppData\Local\Temp\build5868637255104533569.tmp\MIDI_Basic_IO.cpp.o 

MIDI_Basic_IO:7: error: expected constructor, destructor, or type conversion before ';' token

Edit: No, this was because the GitHub latest repo does not work, but a packaged tagged release does work.
 
Last edited:
Thanks for the heads-up about the tagged download version of 4.2. I removed all other MIDI versions from sketches/libraries.
Arduino 1.0.6+TD1.20, import MIDI 4.2.
Arduino Uno, example compiles correctly.
Teensy 2.0, example compiles correctly.
Teensy 3.1, example compiles correctly.

I don't have a MIDI DIN setup on breadboard handy to test with, but it looks as if the library comiles fine with Arduino and Teensy boards (both AVR and ARM based).
 
Looking at the MIDI 4.2 library code, I see that Serial1 will already be automatically selected for any board that has a real USB chip (as opposed to a serial-to-USB converter like most Arduino boards):

Code:
/*! \brief Create an instance of the library attached to a serial port.
 You can use HardwareSerial or SoftwareSerial for the serial port.
 Example: MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, midi2);
 Then call midi2.begin(), midi2.read() etc..
 */
#define MIDI_CREATE_INSTANCE(Type, SerialPort, Name)                            \
    midi::MidiInterface<Type> Name((Type&)SerialPort);

#if defined(ARDUINO_SAM_DUE) || defined(USBCON)
    // Leonardo, Due and other USB boards use Serial1 by default.
    #define MIDI_CREATE_DEFAULT_INSTANCE()                                      \
        MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
#else
    /*! \brief Create an instance of the library with default name, serial port
    and settings, for compatibility with sketches written with pre-v4.2 MIDI Lib,
    or if you don't bother using custom names, serial port or settings.
    */
    #define MIDI_CREATE_DEFAULT_INSTANCE()                                      \
        MIDI_CREATE_INSTANCE(HardwareSerial, Serial,  MIDI);
#endif

provided Teensy boards have USBCON defined, that is.
 
So. I soldered another circuit. Tested with UNO V on 3.3V Pin on UNO.
Works fine.

Same circuit. Soldered to new teensy 3.1 board.
Nothing happens.

Tried PINS 0,4,9 for Input > RX

Seems like something is seriously broken?
 
That code needs to be edited. USBCON is an AVR-only register.

Newer versions of Arduino have a well-defined name for identifying when the board is based on USB serial. It's SERIAL_PORT_USBVIRTUAL.

That code should probably look like this:

Code:
#if defined(SERIAL_PORT_USBVIRTUAL) || defined(USBCON)

If anyone's been in contact with author if this library, please pass this on.
 
Ok. Confirmed. It is a software problem.
I did reinstall Arduino 1.0.6 and Teensyduino 1.20.

The Basic IO Sample coming with Teensyduino works.

Now i changed the Code in the v4.2 of the library like you wrote @paul.
Now it works with my test setup and my custom breakout board.

Does this have any other effects for the lib?
I can contact the author or make a pull request.
 
Status
Not open for further replies.
Back
Top