I want to send Midi data through a 5-pin Din connector with Teensy LC. I attached a 47 ohm resistor 0.25w 5% on both pin 1(TX) and 3.3v. And i have ground connected to the middle DIN pin (have tested it, ground is there) I have double checked the schematic as to which pins on the DIN connector to connect them to and they seem to be accurate, like the pins aren't wrongly attached... I was thinking maybe 5% resistance might be the problem, like its too much? But I wanted to ask to see if someone knew. I tried using the example BASIC_IO from the arduino MIDI library and testing with a midi cable connected to an instrument capable of receiving midi (2 different instruments actually, which i have tested and they can receive midi sent from each other so I know the problem isnt on their side, but with the DIN jack or maybe something else on the Teensy side). I was unsuccessful using the example i also tried the one on the Midi Arduino page, unsuccessful as well.
Does any 5-pin DIN connector work as a Midi jack or is there a specific kind?
The code is for a midi bass pedal project (another one). I want the Teensy to be able to send both Midi from the DIN connector and usbMidi. (usbMidi works, have tested, just not the DIN midi):
Does any 5-pin DIN connector work as a Midi jack or is there a specific kind?
The code is for a midi bass pedal project (another one). I want the Teensy to be able to send both Midi from the DIN connector and usbMidi. (usbMidi works, have tested, just not the DIN midi):
HTML:
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
#define DEBOUNCE 1500
struct key
{
int pin;
int midiKey;
int debounce;
};
struct key keys[] =
{
{ 2, 24, 0 }, // C brown
{ 3, 25, 0 }, // Db red
{ 4, 26, 0 }, // D red
{ 5, 27, 0 }, // Eb orange
{ 6, 28, 0 }, // E orange
{ 7, 29, 0 }, // F yellow
{ 8, 30, 0 }, // Gb green
{ 9, 31, 0 }, // G green
{ 10, 32, 0 }, // Ab blue
{ 11, 33, 0 }, // A blue
{ 12, 34, 0 }, // Bb violet
{ 13, 35, 0 }, // B violet
{ A0, 36, 0 }, // high C brown
{ 0, 0, 0 } // end of list marker
};
const int octaveUp_button_pin = A2;
const int octaveDown_button_pin = A3;
const int velpin = A1;
int octave = 0;
int octave_prev = 0;
int octaveUp_Button_Voltage = 0;
int octaveDown_Button_Voltage = 0;
int last_octaveUp_Button_Voltage = 0;
int last_octaveDown_Button_Voltage = 0;
int time1;
int time2;
int interval;
bool velpin_state = {true};
bool velpin_prev_state = {true};
int channel = 3;
void setup() {
// put your setup code here, to run once:
for (int i = 0; keys[i].pin != 0; ++i)
{
pinMode(keys[i].pin, INPUT_PULLUP);
}
pinMode(octaveUp_button_pin, INPUT_PULLUP);
pinMode(octaveDown_button_pin, INPUT_PULLUP);
pinMode(velpin, INPUT_PULLUP);
MIDI.begin(3);
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Setup complete");
millis();
}
void noteOn(int midiKey)
{
Serial.print("Note On: ");
Serial.println(midiKey);
}
void noteOff(int midiKey)
{
Serial.print("Note Off: ");
Serial.println(midiKey);
MIDI.sendNoteOff(midiKey + octave, 0, channel);
usbMIDI.sendNoteOff(midiKey + octave, 0, channel);
}
void loop() {
// put your main code here, to run repeatedly:
//determine octave
if (octave > octave_prev) {
// midiInst.sendControlChange(AllNotesOff, 0, channel);
for (int i = 0; keys[i].pin != 0; ++i) {
noteOff(keys[i].midiKey + octave - 12);
} octave_prev = octave;
} else {
if (octave < octave_prev) {
// midiInst.sendControlChange(AllNotesOff, 0, channel);
for (int i = 0; keys[i].pin != 0; ++i) {
noteOff(keys[i].midiKey + octave + 12);
} octave_prev = octave;
} else {
octaveUp_Button_Voltage = digitalRead(octaveUp_button_pin);
// compare the buttonState to its previous state
if (octaveUp_Button_Voltage != last_octaveUp_Button_Voltage) {
// if the state has changed, increment the counter
if (octaveUp_Button_Voltage == LOW) {
// if the current state is HIGH then the button went from off to on:
if (octave < 24) {
octave += 12;
Serial.println("Octave Up +1 ");
Serial.print("(Transpose + ");
Serial.print(octave);
Serial.println(")");
}
} else {
// if the current state is LOW then the button went from on to off:
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
last_octaveUp_Button_Voltage = octaveUp_Button_Voltage;
// read the pushbutton input pin 2:
octaveDown_Button_Voltage = digitalRead(octaveDown_button_pin);
// compare the buttonState to its previous state
if (octaveDown_Button_Voltage != last_octaveDown_Button_Voltage) {
// if the state has changed, increment the counter
if (octaveDown_Button_Voltage == LOW) {
// if the current state is HIGH then the button went from off to on:
if (octave > -24) {
octave -= 12;
Serial.println("Octave Down -1 ");
Serial.print("Transpose + ");
Serial.print(octave);
Serial.println(")");
}
} else {
// if the current state is LOW then the button went from on to off:
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
last_octaveDown_Button_Voltage = octaveDown_Button_Voltage;
int value;
for (int i = 0; keys[i].pin != 0; ++i)
{
value = digitalRead(keys[i].pin);
if (keys[i].debounce == 0) // Key has been off
{
if (value == HIGH) // Key is now on
{
time1 = millis();
Serial.println(time1);
keys[i].debounce = DEBOUNCE; // Set the note off debounce counter
}
}
else // Key has been on
{
if (value == LOW) // Key has gone off
{
if (--keys[i].debounce == 0) // If Key has remained off for DEBOUNCE scans,
noteOff(keys[i].midiKey + octave);
}
else // Key has not gone off
keys[i].debounce = DEBOUNCE; // Reset debounce counter in case we got
// a small number of key off scans
velpin_state = digitalRead(velpin);
if (velpin_state != velpin_prev_state)
{
if (velpin_state == LOW)
{
time2 = millis();
Serial.println(time2);
interval = time2 - time1;
Serial.print("interval: ");
Serial.println(interval);
velocity = map(interval, 0, 700, 127, 0);
if (velocity < 0) {
velocity = 0; }
Serial.print("Velocity = ");
Serial.println(velocity);
noteOn(keys[i].midiKey + octave); // Send the MIDI note on message
MIDI.sendNoteOn(keys[i].midiKey + octave, velocity, channel);
usbMIDI.sendNoteOn(keys[i].midiKey + octave, velocity, channel);
}
}
velpin_prev_state = velpin_state;
}
}
}
}
}