Hi guys and girls!
I'm building a project where I plan to capture incoming MIDI messages and show them on a TFT screen. I used the code on https://www.pjrc.com/teensy/td_libs_MIDI.html and commented out some stuff to really get to the bare essentials (always good for troubleshooting).
I am using a Teensy LC with a classic 6N138 setup. I have added a LED to show activity. I get some MIDI values in the serial console (much less than there are in the MIDI song I use, but showing the right MIDI channel, so it is picking up something) but after a couple of seconds the capturing stops and the serial console does not get any additional info. The activity LED continues to work, so the signal is good. In my code you see the inactivity part commented out, but when it was not, it never got to that part. It is as if the Teensy freezes.
Any idea what could be causing this?
I'm building a project where I plan to capture incoming MIDI messages and show them on a TFT screen. I used the code on https://www.pjrc.com/teensy/td_libs_MIDI.html and commented out some stuff to really get to the bare essentials (always good for troubleshooting).
I am using a Teensy LC with a classic 6N138 setup. I have added a LED to show activity. I get some MIDI values in the serial console (much less than there are in the MIDI song I use, but showing the right MIDI channel, so it is picking up something) but after a couple of seconds the capturing stops and the serial console does not get any additional info. The activity LED continues to work, so the signal is good. In my code you see the inactivity part commented out, but when it was not, it never got to that part. It is as if the Teensy freezes.
Any idea what could be causing this?
Code:
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <MIDI.h>
#define sclk 13 // SCLK can also use pin 14
#define mosi 11 // MOSI can also use pin 7
#define cs 10 // CS & DC can use pins 2, 6, 9, 10, 15, 20, 21, 22, 23
#define dc 15 // but certain pairs must NOT be used: 2+10, 6+9, 20+23, 21+22
#define rst 9 // RST can use any pin
//#define sdcs 4
#define HWSERIAL Serial1
Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, mosi, sclk, rst);
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
void setup() {
//Serial.begin(9600);
//Serial.print("Hello! ST7735 TFT Test");
MIDI.begin(MIDI_CHANNEL_OMNI);
//Serial.begin(57600);
Serial.begin(9600);
Serial.println("MIDI Input Test");
///tft.initR(INITR_GREENTAB); // initialize a ST7735R chip, green tab
//Serial.println(time, DEC);
//delay(500);
///tft.invertDisplay(true);
///tft.setRotation(1);
///drawtext("Hello World!", ST7735_WHITE);
//tft.println("test");
//delay(1000);
}
unsigned long t=0;
void loop() {
//Serial.println("Keep Alive");
int type, note, velocity, channel, d1, d2;
if (MIDI.read()) { // Is there a MIDI message incoming ?
byte type = MIDI.getType();
switch (type) {
case midi::NoteOn:
note = MIDI.getData1();
velocity = MIDI.getData2();
channel = MIDI.getChannel();
if (velocity > 0) {
Serial.println(String("Note On: ch=") + channel + ", note=" + note + ", velocity=" + velocity);
} else {
Serial.println(String("Note Off: ch=") + channel + ", note=" + note);
}
break;
case midi::NoteOff:
note = MIDI.getData1();
velocity = MIDI.getData2();
channel = MIDI.getChannel();
Serial.println(String("Note Off: ch=") + channel + ", note=" + note + ", velocity=" + velocity);
break;
///default:
/// d1 = MIDI.getData1();
/// d2 = MIDI.getData2();
/// Serial.println(String("Message, type=") + type + ", data = " + d1 + " " + d2);
}
///t = millis();
}
///if (millis() - t > 10000) {
/// t += 10000;
/// Serial.println("(inactivity)");
///}
}
///void drawtext(const char *text, uint16_t color) {
/// tft.fillScreen(ST7735_BLACK);
/// tft.setCursor(0, 0);
/// tft.setTextColor(color);
/// tft.setTextWrap(true);
/// tft.setTextSize(2);
/// tft.print(text);
///}