Hi all,
I think I am misunderstanding some basic things about Serial communications. What I am trying to do is use the MIDI library (this one: https://github.com/FortySevenEffects/arduino_midi_library) for communication via DIN input using Serial2 pins on the Teensy. I am trying to do this in a library that I am writing. My problem is that the 'begin' method seems to interfere with the settings for serial monitoring, such that I am no longer able to have diagnostic printouts.
Note that I have verified my hardware setup and have verified that I can use the MIDI library to receive input from the hardware.
Here is code (sketch and .h and .cpp files invoked) that will reproduce the issue. I am using Teensy 3.2.
Sketch:
Here's a .h file for a dummy library just to showcase the problem:
Here is the .cpp file.
If I run this code as it is shown above, I get my serial printouts:
serial printout from sketch
printout from within test method
(repeated infinitely)
If I uncomment the line "THISMIDI.begin(MIDI_CHANNEL_OMNI);" that begins the MIDI monitoring, serial monitoring also ceases and I am no longer able to write messages to the serial monitor from within my sketch or from within the class.
I am relatively new to Arduino and Teensy programming and I think there are some things I am not understanding about how the serial interfaces work and how default interfaces are handled when invoked from within a library. So maybe I am just doing something stupid here? Help?
I think I am misunderstanding some basic things about Serial communications. What I am trying to do is use the MIDI library (this one: https://github.com/FortySevenEffects/arduino_midi_library) for communication via DIN input using Serial2 pins on the Teensy. I am trying to do this in a library that I am writing. My problem is that the 'begin' method seems to interfere with the settings for serial monitoring, such that I am no longer able to have diagnostic printouts.
Note that I have verified my hardware setup and have verified that I can use the MIDI library to receive input from the hardware.
Here is code (sketch and .h and .cpp files invoked) that will reproduce the issue. I am using Teensy 3.2.
Sketch:
Code:
#include <test.h>
test t;
void setup() {
Serial.begin(115200);
}
void loop() {
Serial.println("serial printout from sketch");
t.dosomething();
delay(1000);
}
Here's a .h file for a dummy library just to showcase the problem:
Code:
// test.h
#include <MIDI.h>
class test
{
public:
test(void);
void dosomething(void);
//this is the MIDI interface that I want... Serial2 pins:
midi::MidiInterface<HardwareSerial> THISMIDI = midi::MidiInterface<HardwareSerial>((HardwareSerial&)Serial2);
};
Here is the .cpp file.
Code:
#include "test.h"
test::test(void){
//the line below, if uncommented, will cause Serial monitoring to cease
// THISMIDI.begin(MIDI_CHANNEL_OMNI);
}
void test::dosomething(void){
Serial.println("printout from within test method");
}
If I run this code as it is shown above, I get my serial printouts:
serial printout from sketch
printout from within test method
(repeated infinitely)
If I uncomment the line "THISMIDI.begin(MIDI_CHANNEL_OMNI);" that begins the MIDI monitoring, serial monitoring also ceases and I am no longer able to write messages to the serial monitor from within my sketch or from within the class.
I am relatively new to Arduino and Teensy programming and I think there are some things I am not understanding about how the serial interfaces work and how default interfaces are handled when invoked from within a library. So maybe I am just doing something stupid here? Help?