MIDI over serial between different microcotrollers

Hi there,

I was thinking of making a midi controller that has a host, such as a leonardo board, to transmit midi over usb using serial reads from a controller that doesn't have usb by default, such as an uno.

for example, the code that would be programmed on the uno would be

`#include <Control_Surface.h>

AnalogMultiplex<8> mux {A0, {2, 3, 4}};

CCPotentiometer potentiometers[] {
{mux.pin(0), {0x00, CHANNEL_1}},
{mux.pin(1), {0x01, CHANNEL_1}},
{mux.pin(2), {0x02, CHANNEL_1}},
{mux.pin(3), {0x03, CHANNEL_1}},
{mux.pin(4), {0x04, CHANNEL_1}},
{mux.pin(5), {0x05, CHANNEL_1}},
{mux.pin(6), {0x06, CHANNEL_1}},
{mux.pin(7), {0x07, CHANNEL_1}},
};

void setup() {
Control_Surface.begin();
}

void loop() {
Control_Surface.loop();
}`

What code would I need to write to the leonardo to make this transmit the data over its usb to use in midi software? and what would be needed to be added to the uno code?
is it even possible? and if so is it feasible for chaining midi or is it not worth it due to speed limitations etc?

You add a MIDI over USB interface and a serial MIDI interface, and then connect the two:

USBMIDI_Interface usb_midi;
HardwareSerialMIDI_Interface ser_midi{Serial1, 115200};
MIDI_Pipe ser_to_usb;

void setup() {
  usb_midi.setAsDefault(); // Used by Control Surface itself
  ser_midi >> ser_to_usb >> usb_midi;
  Control_Surface.begin();
}

Please see Control Surface: MIDI Tutorial for details.

You force it to use a serial MIDI interface as the default (and only) interface.

HardwareSerialMIDI_Interface midi{Serial, 115200};

This is not correct, the template argument of AnalogMultiplex is the number of address lines, not the number of inputs, so it should be 3, not 8. See Control Surface: AnalogMultiplex< N > Class Template Reference.

1 Like

Thanks for your input

I'm attempting with a single potentiometer until I get it to work. I've put the code on the arduino uno as follows;

#include <Control_Surface.h>

HardwareSerialMIDI_Interface midi {Serial, 115200};

CCPotentiometer pot1 {A0, {0x00}};

void setup() {
  midi.begin();
}
 
void loop() {
  midi.update();
}

and the leonardo code

#include <Control_Surface.h>

USBMIDI_Interface usb_midi;
HardwareSerialMIDI_Interface ser_midi{Serial1, 115200};
MIDI_Pipe ser_to_usb;

void setup() {
  usb_midi.setAsDefault(); // Used by Control Surface itself
  ser_midi >> ser_to_usb >> usb_midi;
  ser_midi.begin();
  Control_Surface.begin();
}

void loop() {
  ser_midi.update();
  Control_Surface.loop();
}

and the boards are connected as follows (assume the top arduino is the leonardo)

however I get no reading from the leonardo through midi monitoring software, have you any idea what the issue is? I assume I am missing something

You have to call Control_Surface.begin() and .update() in the Uno sketch.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.