Arduino Uno MIDI signals to Cubase

I want to send MIDI signals from my Arduino Uno to Cubase. I have ASIO4ALL driver but it doesnt recognize the USB port. Any advice? :slightly_smiling_face:

The Arduino Uno does not support MIDI over USB natively. See e.g. Control Surface: MIDI over USB for details and alternatives.

1 Like

show your sketch and your setup first. there are many possibilities to make MIDI on UNO (actually 3)

It's far from finished, but here is the sketch:

#define TRIG1 3
#define ECHO1 4
#define TRIG2 5
#define ECHO2 6
#define SPEAKER 9

long int distance1 = 0;
long int distance2 = 0;
int pitch = 0;
int volume = 0;
int mode = 0;

float scale[2][8] = {
    {60, 62, 64, 65, 67, 69, 71, 72},
    {60, 62, 63, 65, 67, 68, 70, 72}
};

char note_names[][14] = {
    "C", "C#", "D", "D#", "E", "F", "F#", "G",
    "G#", "A", "A#", "B", "C"
};

long int read_distance(int trig, int echo) {
    digitalWrite(trig, LOW);
    // delayMicroseconds(2);
    digitalWrite(trig, HIGH);
    delayMicroseconds(10);
    digitalWrite(trig, LOW);
    return 0.034 * pulseIn(echo, HIGH) / 2;
}

void play_sound(int pitch, int volume) {
    Serial.write(pitch);
    Serial.write(volume);
}

void silence() {
    Serial.write(128);
}

void setup() {
    pinMode(SPEAKER, OUTPUT);
    pinMode(TRIG1, OUTPUT);
    pinMode(ECHO1, INPUT_PULLUP);
    pinMode(TRIG2, OUTPUT);
    pinMode(ECHO2, INPUT_PULLUP);
    Serial.begin(9600);
    // Serial.begin(31250);
}

void loop() {
    distance1 = read_distance(TRIG1, ECHO1);

    distance2 = read_distance(TRIG2, ECHO2);

    volume = (distance2 - 5) / 36 * 100;

    if (distance1 >= 5 && distance1 <= 41) {
        pitch = (8.0 / 36.0 * (distance1 - 5)) + 60;
        play_sound(scale[mode][pitch], volume);
    } else {
        silence();
    }
}

I've connected two hc-sr04 ultrasonic sensors, one to determine pitch and the other one loudness.

Like most beginners you are trying to write too much too soon. Forget all the distance measurement stuff (which does contain errors) and just concentrate on sending some random MIDI note on and MIDI note off messages.

Your

Should also be passed the command and the channel number, and format the correct MIDI message.

void play_sound(byte command, byte channel, byte  pitch, byte volume) {
    Serial.write( command | channel); // merge the note message with the channel number. For MIDI channel 1 then use 0 as the chanel number you pass.
    Serial.write(pitch);
    Serial.write(volume);
}

Of course you have to define the command you want to send an the channel number in order to pass them into this function.
The MIDI Command for note on is 0x90 and note off is 0x80.
Also set the baud rate to 31250.

Here is some sample code that plays a single note for all the voices in the MIDI instrument you are trying to control.

/* Midi note fire - Grumpy Mike
 *
 * send MIDI serial data, automatically for a test
 * 
*/
#define midiChannel (char)0

void setup() {
 //  Setup serial
  Serial.begin(31250);  // MIDI speed

}

void loop() {
  int val;
  for(int ins=0; ins<127; ins++){ // one note from all the instruments
  voiceChange(ins); 
  val = random(20,100);
    noteSend(0x90, val, 127); // note on
    delay(200);
    noteSend(0x80, val, 127); // note off
   delay(800);
    } // end loop function
}

// sends voice change message
  void voiceChange(int i){
     Serial.write(0xC0); // program change message
     Serial.write(i); 
  }
//  plays a MIDI note
 void noteSend(char cmd, char data1, char data2) {
  cmd = cmd | char(midiChannel);  // merge channel number
  Serial.write(cmd);
  Serial.write(data1);
  Serial.write(data2);
}
1 Like

ok, you using Serial port, then you need:

  • MIDI Output shield(and MIDI-to-USB converter)

OR

  • the program "Hairless MIDI" on PC to redirect serial to MIDI input of PC

and then Cubase will see it.

1 Like