Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: code needed for teensy 3.5 help please

  1. #1
    Junior Member
    Join Date
    Aug 2019
    Location
    Caboolture, queensland
    Posts
    4

    code needed for teensy 3.5 help please

    I have purchased a teensy board 3.5. A tech friend gave me his diagram of how to connect an organ pedal board to it. That stage has been successful and had the teensy board been recognized by windows settings as a usb midi.
    I have followed the instructions on the web site (https://www.pjrc.com/teensy/td_midi.html).

    Now i have no idea on what coding is needed and would love some help. I have 3 usb midi keyboard controllers that have also been plugged in and no problems with those. I have used the board manager and thats done sucessfully.

    I feel i am missing some coding into the arduino program. I have pressed the tick buttom and pressed the button on the board. For the first coupe of attempts the phase "hello world" kept repeating over and over. I have uninstalled the arduino program 3 times, on the 4th windows has accepted it as a usb midi. So please what am i missed??? you can respond to my email address hondacruiser2001@yahoo.com
    thanks in advance.

    Here is the coding i have copied so far from arduino. Also my 3 midi controller keyboards are showing in windows settings as masterkey 61. All three keyboards are names the same.


    /* Create a "class compliant " USB to 3 MIDI IN and 3 MIDI OUT interface.

    MIDI receive (6N138 optocoupler) input circuit and series resistor
    outputs need to be connected to Serial1, Serial2 and Serial3.

    You must select MIDIx4 from the "Tools > USB Type" menu

    This example code is in the public domain.
    */

    #include <MIDI.h>

    // Create the Serial MIDI ports
    MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI1);
    MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, MIDI2);
    MIDI_CREATE_INSTANCE(HardwareSerial, Serial3, MIDI3);

    // A variable to know how long the LED has been turned on
    elapsedMillis ledOnMillis;


    void setup() {
    Serial.begin(115200);
    pinMode(13, OUTPUT); // LED pin
    digitalWrite(13, LOW);
    MIDI1.begin(MIDI_CHANNEL_OMNI);
    MIDI2.begin(MIDI_CHANNEL_OMNI);
    MIDI3.begin(MIDI_CHANNEL_OMNI);
    }


    void loop() {
    bool activity = false;

    if (MIDI1.read()) {
    // get a MIDI IN1 (Serial) message
    byte type = MIDI1.getType();
    byte channel = MIDI1.getChannel();
    byte data1 = MIDI1.getData1();
    byte data2 = MIDI1.getData2();

    // forward the message to USB MIDI virtual cable #0
    if (type != midi::SystemExclusive) {
    // Normal messages, simply give the data to the usbMIDI.send()
    usbMIDI.send(type, data1, data2, channel, 0);
    } else {
    // SysEx messages are special. The message length is given in data1 & data2
    unsigned int SysExLength = data1 + data2 * 256;
    usbMIDI.sendSysEx(SysExLength, MIDI1.getSysExArray(), true, 0);
    }
    activity = true;
    }

    if (MIDI2.read()) {
    // get a MIDI IN2 (Serial) message
    byte type = MIDI2.getType();
    byte channel = MIDI2.getChannel();
    byte data1 = MIDI2.getData1();
    byte data2 = MIDI2.getData2();

    // forward the message to USB MIDI virtual cable #1
    if (type != midi::SystemExclusive) {
    // Normal messages, simply give the data to the usbMIDI.send()
    usbMIDI.send(type, data1, data2, channel, 1);
    } else {
    // SysEx messages are special. The message length is given in data1 & data2
    unsigned int SysExLength = data1 + data2 * 256;
    usbMIDI.sendSysEx(SysExLength, MIDI1.getSysExArray(), true, 1);
    }
    activity = true;
    }

    if (MIDI3.read()) {
    // get a MIDI IN1 (Serial) message
    byte type = MIDI3.getType();
    byte channel = MIDI3.getChannel();
    byte data1 = MIDI3.getData1();
    byte data2 = MIDI3.getData2();

    // forward the message to USB MIDI virtual cable #0
    if (type != midi::SystemExclusive) {
    // Normal messages, simply give the data to the usbMIDI.send()
    usbMIDI.send(type, data1, data2, channel, 2);
    } else {
    // SysEx messages are special. The message length is given in data1 & data2
    unsigned int SysExLength = data1 + data2 * 256;
    usbMIDI.sendSysEx(SysExLength, MIDI1.getSysExArray(), true, 2);
    }
    activity = true;
    }

    if (usbMIDI.read()) {
    // get the USB MIDI message, defined by these 5 numbers (except SysEX)
    byte type = usbMIDI.getType();
    byte channel = usbMIDI.getChannel();
    byte data1 = usbMIDI.getData1();
    byte data2 = usbMIDI.getData2();
    byte cable = usbMIDI.getCable();

    // forward this message to 1 of the 3 Serial MIDI OUT ports
    if (type != usbMIDI.SystemExclusive) {
    // Normal messages, first we must convert usbMIDI's type (an ordinary
    // byte) to the MIDI library's special MidiType.
    midi::MidiType mtype = (midi::MidiType)type;

    // Then simply give the data to the MIDI library send()
    switch (cable) {
    case 0:
    MIDI1.send(mtype, data1, data2, channel);
    break;
    case 1:
    MIDI2.send(mtype, data1, data2, channel);
    break;
    case 2:
    MIDI3.send(mtype, data1, data2, channel);
    break;
    }

    } else {
    // SysEx messages are special. The message length is given in data1 & data2
    unsigned int SysExLength = data1 + data2 * 256;
    switch (cable) {
    case 0:
    MIDI1.sendSysEx(SysExLength, usbMIDI.getSysExArray(), true);
    break;
    case 1:
    MIDI2.sendSysEx(SysExLength, usbMIDI.getSysExArray(), true);
    break;
    case 2:
    MIDI3.sendSysEx(SysExLength, usbMIDI.getSysExArray(), true);
    break;
    }
    }
    activity = true;
    }

    // blink the LED when any activity has happened
    if (activity) {
    digitalWriteFast(13, HIGH); // LED on
    ledOnMillis = 0;
    }
    if (ledOnMillis > 15) {
    digitalWriteFast(13, LOW); // LED off
    }

    }

  2. #2
    Member ETMoody3's Avatar
    Join Date
    Mar 2014
    Location
    New Ulm, Mn
    Posts
    75
    There has to be software on the Windows computer that completes the connection.

    Simply plugging your usb devices ( keyboards, controllers, Teensy) into the computer does NOT connect them. For instance, your Digital Audio Workstation completes this task.

    It is unclear from your message what the failure is, but without mention of software in windows it would appear to me that is why you’re not getting any data out of the 5 pin outputs on the Teensy. The code *looks* correct.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •