Hello, I'm a new user in this forum.
Recently I bought a book called "Arduino for musicians. A complete guide to Arduino and Teensy microcontrollers".
This book introduces the MIDI protocol and explains how to connect a input and output MIDI interface to MCUs.
I didn't used Teensy 3.2 before (but I frequently use Arduino), however I'm not able to make Teensy work properly as MIDI receiver.
Firstly I made a MIDI transmitter with an Arduino Uno. This is the code:
Then I've created a receiver with Teensy 3.2 (in the schematic there is 3.1 because i didn't find 3.2). The code is the same of the book:
Here I use the 3.3V instead of 5V for the pin 8 of the 6N138 (maybe it's a problem?).
When I connect Teensy to the USB port of the PC, I press the Teensy's program mode button, I select the board model from Arduino IDE and I select MIDI as USB Type.
After that I select hid#vid_16C0&pid_0485 MIDI from Tools->Ports and I compile the code.
There aren't errors so I open Serial Monitor in order to check what data is receiving but I see nothing..
Any suggestion?
Recently I bought a book called "Arduino for musicians. A complete guide to Arduino and Teensy microcontrollers".
This book introduces the MIDI protocol and explains how to connect a input and output MIDI interface to MCUs.
I didn't used Teensy 3.2 before (but I frequently use Arduino), however I'm not able to make Teensy work properly as MIDI receiver.
Firstly I made a MIDI transmitter with an Arduino Uno. This is the code:
Code:
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
const int velocity = 100;
const int channel = 1;
void setup() {
MIDI.begin(1); // channel 1 (default)
}
void loop() {
for( int i = 50; i < 70; i+=2){
MIDI.sendNoteOn(i, velocity, channel);
MIDI.sendNoteOn(i + 4, velocity, channel);
MIDI.sendNoteOn(i + 8, velocity, channel);
delay(125);
MIDI.sendNoteOff(i, 0, channel);
MIDI.sendNoteOff(i + 4, 0, channel);
MIDI.sendNoteOff(i + 8, 0, channel);
delay(125);
}
}
Then I've created a receiver with Teensy 3.2 (in the schematic there is 3.1 because i didn't find 3.2). The code is the same of the book:
Code:
void setup() {
Serial.begin(115200);
usbMIDI.setHandleNoteOff(OnNoteOff);
usbMIDI.setHandleNoteOn(OnNoteOn);
usbMIDI.setHandleVelocityChange(OnVelocityChange);
usbMIDI.setHandleControlChange(OnControlChange);
usbMIDI.setHandleProgramChange(OnProgramChange);
usbMIDI.setHandleAfterTouch(OnAfterTouch);
/*usbMIDI.setHandlePitchChange(OnPitchChange);*/ //gives errors?
}
void loop() {
usbMIDI.read();
}
void OnNoteOn(byte channel, byte note, byte velocity){
Serial.print("Note On, ch=");
Serial.print(channel, DEC);
Serial.print(", note=");
Serial.print(note, DEC);
Serial.print(", velocity=");
Serial.print(velocity, DEC);
Serial.println();
}
void OnNoteOff(byte channel, byte note, byte velocity){
Serial.print("Note Off, ch=");
Serial.print(channel, DEC);
Serial.print(", note=");
Serial.print(note, DEC);
Serial.print(", velocity=");
Serial.print(velocity, DEC);
Serial.println();
}
void OnVelocityChange(byte channel, byte note, byte velocity){
Serial.print("Velocity Change, ch=");
Serial.print(channel, DEC);
Serial.print(", note=");
Serial.print(note, DEC);
Serial.print(", velocity=");
Serial.print(velocity, DEC);
Serial.println();
}
void OnControlChange(byte channel, byte control, byte value){
Serial.print("Control Change, ch=");
Serial.print(channel, DEC);
Serial.print(", control=");
Serial.print(control, DEC);
Serial.print(", value=");
Serial.print(value, DEC);
Serial.println();
}
void OnProgramChange(byte channel, byte program){
Serial.print("Program Change, ch=");
Serial.print(channel, DEC);
Serial.print(", program=");
Serial.print(program, DEC);
Serial.println();
}
void OnAfterTouch(byte channel, byte pressure){
Serial.print("After Touch, ch=");
Serial.print(channel, DEC);
Serial.print(", pressure=");
Serial.print(pressure, DEC);
Serial.println();
}
// gives errors?
/*void OnPitchChange(uint8_t channel, uint16_t pitch){
Serial.print("Pitch Change, ch=");
Serial.print(channel, DEC);
Serial.print(", pitch=");
Serial.print(pitch, DEC);
Serial.println();
}*/
Here I use the 3.3V instead of 5V for the pin 8 of the 6N138 (maybe it's a problem?).
When I connect Teensy to the USB port of the PC, I press the Teensy's program mode button, I select the board model from Arduino IDE and I select MIDI as USB Type.
After that I select hid#vid_16C0&pid_0485 MIDI from Tools->Ports and I compile the code.
There aren't errors so I open Serial Monitor in order to check what data is receiving but I see nothing..
Any suggestion?