Go Down

Topic: MIDI Hairless error : +9.142 - Error: got unexpected data byte 0xa. (Read 170 times) previous topic - next topic

coenvanrooij

Hi!

I'm pretty new to Arduino and am trying to make a 'walking drumcomputer'. I've written a program using the MIDI library, but I get an error in the Hairless MIDI app.:  +9.142 - Error: got unexpected data byte 0xa.
This is with the option LoopMIDI Port. When I use USB2.0-MIDI I get the errors

Failed to open MIDI in port: RtMidiIn::openPort: error creating Windows MM MIDI input port.
and
FTDI drivers don't seem to be installed. Not attempting any FTDI latency tricks.


I googled and tried, but haven't succeeded tackling this problem. Any thoughts or suggestions are more than welcome!

My suspicions:
- MIDI baudrate is wrongly configured in MIDI library and Serial.begin(115200) doesn't fix this properly.
- FTDI drivers, though installed from .exe file, still don't seem to work
- MIDI notation not correct

my code:

Code: [Select]


#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();

const int sensor[] = {A1, A2, A3, A4, A5};
int threshold = 100;
int New [] = {0, 0, 0, 0, 0};
const int Led = 10;
void setup() {
  // put your setup code here, to run once:
 
MIDI.begin();
Serial.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
  int i;
  for (i = 1; i < 5; i++) {

    New[i] = analogRead(sensor[i]);
    if (New[i] > threshold) { // if piezo is hit hard enough
      switch (i) {

        case 1 :
          Serial.println (New[1]);
          MIDI.sendNoteOn(0X90, 0X5A, 127); // play MIDI note
          New[i] = 0; // prevent retrigger
          digitalWrite(Led, HIGH); // Led on
          delay(500);
          digitalWrite(Led, LOW); // Led off
          break;

        case 2 :
          Serial.println(New[i]);
          MIDI.sendNoteOn(0X90, 0X5A, 127);
          New[i] = 0;
          digitalWrite(Led, HIGH);
          delay(500);
          digitalWrite(Led, LOW);
         
          break;

        case 3 :
          Serial.println(New[i]);
          MIDI.sendNoteOn(0X90, 0X5A, 127);
          New[i] = 0;
          digitalWrite(Led, HIGH);
          delay(500);
          digitalWrite(Led, LOW);
         
          break;

        case 4 :
          Serial.println(New[i]);
          MIDI.sendNoteOn(0X90, 0X5A, 127);
          New[i] = 0;
          digitalWrite(Led, HIGH);
          delay(500);
          digitalWrite(Led, LOW);
         
          break;
          }
      delay(10);
      }
    }
  }



Thank you for commenting!

Greetz,

Coen

PieterP

You are using the wrong parameters, the correct syntax is:
Code: [Select]
MIDI::sendNoteOn(pitch, velocity, channel)

Pieter

coenvanrooij

Hi Pieter,

Thx for the quick answer! I've tried your comment, but get the same result...

Code: [Select]

void loop() {
  // put your main code here, to run repeatedly:
  int i;
  for (i = 1; i < 5; i++) {

    New[i] = analogRead(sensor[i]);
    if (New[i] > threshold) { // als piezo hard genoeg geraakt wordt

      switch (i) {

        case 1 :
          Serial.println (New[1]);
          MIDI.sendNoteOn(127, 0X50, 0X90); // speel MIDI noot
          New[i] = 0; // voorkomt retrigger
          digitalWrite(Led, HIGH); // Led aan
          delay(500);
          digitalWrite(Led, LOW); // Led uit
          break;

        case 2 :
          Serial.println(New[i]);
          MIDI.sendNoteOn(127, 0X50, 0X90); // speel MIDI noot
          New[i] = 0; // voorkomt retrigger
          digitalWrite(Led, HIGH);
          delay(500);
          digitalWrite(Led, LOW);
         
          break;

        case 3 :
          Serial.println(New[i]);
          MIDI.sendNoteOn(127, 0X50, 0X90); // speel MIDI noot
          New[i] = 0; // voorkomt retrigger
          digitalWrite(Led, HIGH);
          delay(500);
          digitalWrite(Led, LOW);
         
          break;

        case 4 :
          Serial.println(New[i]);
          MIDI.sendNoteOn(127, 0X50, 0X90); // speel MIDI noot
          New[i] = 0; // voorkomt retrigger
          digitalWrite(Led, HIGH);
          delay(500);
          digitalWrite(Led, LOW);
         
          break;
          }
      delay(10);
      }
    }
  }


Any other suggestions or did I misinterpretate your fix?


PieterP

Code: [Select]
MIDI.sendNoteOn(i, 0x7F, 1);
Should work (note i, 100% vel, on midi channel 1).

The problem is probably the other Serial.print(ln)'s in the sketch, they send data on the same serial connection as MIDI.

You can simplify your code by getting rid of the case switch.¨
Code: [Select]

void loop() {
  for (int i = 0; i < 5; i++) { // array index starts at 0

    New[i] = analogRead(sensor[i]);
    if (New[i] > threshold) { // als piezo hard genoeg geraakt wordt
      // Serial.println (New[1]); // Verwijder dit
      MIDI.sendNoteOn(i, 0x7F, 1); // speel de i-de MIDI noot (http://www.midimountain.com/midi/midi_note_numbers.html) met een aanslagsterkte van 100% op MIDI-kanaal 1
      // New[i] = 0; // voorkomt retrigger // is niet nodig
      digitalWrite(Led, HIGH); // Led aan
      delay(500); // is vrij lang, 15ms is meer dan genoeg
      digitalWrite(Led, LOW); // Led uit

      // delay(10); // niet meer nodig omdat je er hierboven al één hebt
    }
  }
}


Pieter

coenvanrooij

Ah! It's starting to work and the code is much simpler than I imagined it. I do get MIDI messages, but there seems to be a lot of noise. Even without triggering the piezo's, messages get through like :
+171.582 - Serial In: System Message #8
+181.826 - Serial In: Ch 1: Program change 0

after boosting up the threshold, it got better, but after some fiddling around, I keep getting loads of this message: +5.937 - MIDI In: System Message #8

If this works properly, I can get on with connecting to Ableton...


PieterP

Have you tried an example sketch, like this one?
Code: [Select]
#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();

static const unsigned ledPin = 13;      // LED pin on Arduino Uno

void setup(){
    pinMode(ledPin, OUTPUT);
    MIDI.begin();
}
void loop() {
  digitalWrite(ledPin, HIGH);
  MIDI.sendNoteOn(42, 127, 1);    // Send a Note (pitch 42, velo 127 on channel 1)
  delay(1000);                // Wait for a second
  MIDI.sendNoteOff(42, 0, 1);     // Stop the note
  digitalWrite(ledPin, LOW);
  delay(1000)
}


You can change the baud rate in <MIDI library>/src/midi_Settings.h.

Pieter

Go Up