I have a Due + Rugged Circuits MIDI shield + 1.8 TFT LCD w/SD card & Joystick. I have a simple sketch to test reliability of the inbound MIDI data pasted below. The issue is that it's reporting wrong note numbers & velocity AND it takes multiple tries to get a note On to be reported.
I had a similar issue with a Mega 2560: it would take multiple tries for a specific note to be recognized, I always thought it was due to my code. But now it does the same on the Due. I'm using MIDI OX to send a note through a USB/MIDI converter (Roland UM-1) into the rugged circuits MIDI shield (link to their schematic):
My first concern as the 3.3 voltage of the Due with MIDI (which prefers 5v), but I can tell you that it plays MIDI just fine (so far). Also, the shield has a 74HC125D (for what I assume is to deal with the voltage difference). I'm not an electronics expert, but I'm tyring to learn. Is there something in the schematic which could explain the inability of the hardware to reliably receive MIDI input ?
Here's an example of the issue
example
( I send 144 30 100, F# 1)
printed on the TFT:
144 28 64
sent: 144 72 100 (C5)
printed: 144 0 64
sent: 144 65 100 (F4)
printed: 144 1 64
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#define SD_CS 4 // Chip select line for SD card
#define TFT_CS 10 // Chip select line for TFT display
#define TFT_DC 8 // Data/command line for TFT
#define TFT_RST 0 // Reset line for TFT (or connect to +5V)
#define ADA_JOYSTICK 3
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
byte count = 0;
int theBytes[3];
void setup() {
// Set MIDI baud rate:
Serial.begin(31250);
// Serial.begin(57600);
pinMode(A5, OUTPUT); // sets the digital pin as output, D19 on Rugged circuits MIDI shield = A5 on Mega/Due.
digitalWrite(A5, HIGH);
tft.initR( INITR_BLACKTAB ); // "tab color" from screen protector; there's RED and GREEN, too.
//tft.initR(INITR_GREENTAB);
tft.fillScreen(ST7735_BLACK);
}
void loop() {
// // play notes from F#-0 (0x1E) to F#-5 (0x5A):
// for (int note = 0x1E; note < 0x5A; note ++) {
// //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
// noteOn(0x90, note, 0x45);
// delay(100);
// //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
// noteOn(0x90, note, 0x00);
// delay(100);
// }
while (Serial.available() > 2){
for (int i=0; i<3; i++) {
theBytes[i] = Serial.read();
}
byte indata = theBytes[0];
byte inNote = theBytes[1];
byte invelocity = theBytes[2];
//tft.print(indata);
//tft.print(" ");
if (indata >=144 && indata <= 159){ //144 is simply 0x90 or MIDI noteOn, there are 15 (0-15) possible channels so the max is 159 or 0x9F. I only care about NoteOn status messages.
tft.print(indata);
tft.print(" ");
byte commandByte = indata;//read first byte
tft.print(inNote);
tft.print(" ");
// byte invelocity = Serial.read();//read final byte
tft.println(invelocity);
byte inchannel = (commandByte - 144);
// HandleNoteOn(commandByte, inNote, invelocity);
}
} //new while end bracket
}
// plays a MIDI note. Doesn't check to see that
// cmd is greater than 127, or that data values are less than 127:
void noteOn(int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}