Mega MIDI over USB, controller, keyboard

Presently Leonardo but Mega in 3 days...

I have this from examples. works fine. USB CONNECTION. NOT SERIAL!!!

  1. Do not know how to change it to (edit) C2 (for organ pedals for virtual organ via GrandOrgue) C2 and 36 ?
  2. Do not know how to generalize this to play 25 or 32 notes up from (edit) C2. Continuous NOT MATRIX. NOT SERIAL. Pins 2-12, 14- etc etc...
    maybe something like for (int x = 0; x <= 127; x ++) {
    if (x > 12 && x < 15) { // create jump in values
    continue;
    but how to insert that???
    THANKS!!!

ex_02_button.ino

/*
This is an example of the "Digital" class of the MIDI_controller library.
Connect a push buttons to digital pin 2. Connect the other pin of the button to the ground, 
a pull-up resistor is not necessary, because the internal one will be used. 
This button will play MIDI note C4 when pressed.
Map it in your DAW or DJ software.

Written by tttapa, 08/09/2017
https://github.com/tttapa/MIDI_controller
*/

#include <MIDI_Controller.h> // Include the library

const uint8_t velocity = 0b1111111; // Maximum velocity (0b1111111 = 0x7F = 127)
const uint8_t C4 = 60;              // Note number 60 is defined as middle C in the MIDI specification

// Create a new instance of the class 'Digital', called 'button', on pin 2, that sends MIDI messages with note 'C4' (60) on channel 1, with velocity 127
Digital button(2, C4, 1, velocity);

void setup() {}

void loop() {
  // Refresh the button (check whether the button's state has changed since last time, if so, send it over MIDI)
  MIDI_Controller.refresh();
}

The Arduino Mega does not support MIDI over USB natively. See Control Surface: MIDI over USB.

I'm not sure what you mean by that.

Again, you'll have to clearly explain what you want to achieve (in words, not code).

The MIDI_Controller library is no longer supported. You should use the Control Surface library instead. Specifically, see Control Surface: NoteButton.ino and Control Surface: NoteButtons< NumButtons > Class Template Reference.

Thanks for your reply.
I want to create a sketch that triggers the musical MIDI notes [36-60] that is, C2 through C4. Each of these 25 notes is a switch: I connect pin 2 to ground through switch1("Digital button1") There is an easier way to code this for pins
[2-12],[14-27] I simply do not know it. Could you share it with me?
For the second variable, instead of creating a constant as I have below, I could use an integer j=36 and then increase it by one for each subsequent note, but I do not know C programming so do not know how to do that.
Thanks.

The code for the first 3 notes is as follows. This is recognized via USB in GrandOrgue and plays the appropriate notes.

#include <MIDI_Controller.h> // Include the library

const uint8_t velocity = 0b1111111; // Maximum velocity (0b1111111 = 0x7F = 127)
const uint8_t C2 = 36;              // Note number 60 is defined as middle C in the MIDI specification
const uint8_t C2s = 37;
const uint8_t D2 = 38;

// Create a new instance of the class 'Digital', called 'button', on pin 2, that sends MIDI messages with note 'C4' (60) on channel 1, with velocity 127
Digital button1(2, C2, 1, velocity);
Digital button2(3, C2s, 1, velocity);
Digital button3(4, D2, 1, velocity);

void setup() {}

void loop() {
  // Refresh the button (check whether the button's state has changed since last time, if so, send it over MIDI)
  MIDI_Controller.refresh();
}

There is, see the links I posted in my previous reply.

#include <Control_Surface.h>

USBMIDI_Interface midi;

NoteButtons<25> buttons{
  {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, // pins
   14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27},
  MIDI_Notes::C(2), // address of first button
  1, // address increment from one button to the next
};

void setup() {
  Control_Surface.begin();  // Initialize Control Surface
}

void loop() {
  Control_Surface.loop();  // Update the Control Surface
}

EDIT there may be some confusion here in that I want it to output [37,60] (the number of the midi note and not the note itself...

Huge thanks for that!!! However, I went to

and got the zip, and in the Arduino app /Sketch/Include Library/add zip library and clicked on the zip.(it added it) Then I copied your code above into a new sketch, compiled and uploaded fine but when I tell GrandOrgue to listen, it does not hear it. (my breadboard is set up with 3 switches, pins 2,3,4 and to Gnd. What am I missing? Again, HUGE THANKS!!!

See my earlier reply:

that says
Arduino Mega 2560 :white_check_mark: :x:⁽¹⁾ :x: :x:
which says it can only do it over serial.

edit and notebutton can not do it on mega. so ahat am I doing with this on a mega?
Boards:
AVR, AVR USB, Nano Every, Due, Nano 33 IoT, Nano 33 BLE, UNO R4, Pi Pico, Teensy 3.x, ESP32, ESP8266

If I can't do it on a mega, how can I extend a Leonardo 9since there don't seem to be any MIDI USB capable boards with more pins like the mega. And Arduino's sit says the Mega can, but compiling it says it can't.

Off the top of my head, one option might be using the Mega's serial to output MIDI to a USB Midi adapter.

Exactly. This means that if you want to be able to access the Mega as a MIDI device in GrandOrgue, you'll either have to use 1) a 5-pin DIN MIDI to USB interface/adapter, or 2) an application on your computer like Hairless that creates a virtual MIDI port for you and translates back and forth to serial MIDI, or 3) you'll need to flash custom firmware to your Mega's USB chip (which is a hassle, because it means that you can no longer upload Arduino code to it). Again, see the MIDI over USB page for more details.

It can, the Mega is part of the “AVR” family of boards. It just won't show up as a MIDI over USB device on your computer, instead falling back to MIDI over serial.

Sure, you can use port expanders like the MCP23017 or multiplexers.
The Teensy 4.1 has more pins and supports MIDI over USB. There's also the Arduino Due, but I wouldn't recommend it.

What do you mean?

break break.
I misunderstood.
I thought that the Mega was a midi usb board because I thought Arduino said it did but on reading more closely it doesn't.
My bad.

Back to Leonardo. a matrix 6x6 Using 2,3,4,5,6,7 and A0,A1,A2,A3,A4,A5. That will give me 36. Most I would need is 32 (32 key organ pedal board. I can set up the matrix with digital pins (and diodes on the wiring) but don't know how to set it up using the analog pins as digital. Remember this is only a (36)switch(es) that sends a MIDI code [37,60].
So for
const uint8_t velocity = 0b1111111; // Maximum velocity (0b1111111 = 0x7F = 127)
const uint8_t addresses[4][3] = { // the note numbers corresponding to the buttons in the matrix
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 },
{ 10, 11, 12 }
// or rather { 37, 38, 39},{ 40, 41, 42}... etc
};

I would need
ButtonMatrix<4, 3> buttonmatrix({2, 3, 4, 5}, {6, 7, 8}, addresses, 1, velocity);

void setup() {}

void loop() {
// Refresh the buttons (check whether the states have changed since last time, if so, send it over MIDI)
MIDI_Controller.refresh();
}
So trying to figure out what I would need on my Leonardo for the analogue pins:
ButtonMatrix<6, 6> buttonmatrix({2, 3, 4, 5,6,7}, {A0,A1,A2,A3,A4,A5}, addresses, 1, velocity);

would it be that simple?
THANKS!

Yup! Code for Leonardo simply modifying Arduino/File/Examples/MIDI Controller/EX.11.Button_Matrix .

/*
This is an example of the "ButtonMatrix" class of the MIDI_controller library.
Connect a 4 × 3 matrix of buttons with the rows to pins 2, 3, 4 and 5,
and the columns to pins 6, 7 and 8.
Pull-up resistors are not necessary, because the internal ones will be used.

If you want to be able to press multiple buttons at once, add a diode
in series with each button, as shown in the schematic on the Wiki:
Hardware · tttapa/MIDI_controller Wiki · GitHub

The note numbers are specified in the 'addresses' array.
Map accordingly in your DAW or DJ software.

Written by tttapa, 24/09/2017
GitHub - tttapa/MIDI_controller: This is a library for creating a MIDI controller using an Arduino or Teensy board.

modified to 6x6 by kris333

*/

#include "MIDI_Controller.h" // Include the library

const uint8_t velocity = 0b1111111; // Maximum velocity (0b1111111 = 0x7F = 127)
const uint8_t addresses[6][6] = { // the note numbers corresponding to the buttons in the matrix
{ 36, 37, 38, 39, 40, 41},
{ 42, 43, 44, 45, 46, 47},
{ 48, 49, 50, 51, 52, 53},
{ 54, 55, 56, 57, 58, 59},
{ 60, 61, 62, 63, 64, 65},
{ 66, 67, 68, 69, 70, 71},
};

// Create a new instance of the class 'ButtonMatrix', called 'buttonmatrix', with dimensions 4 rows and 3 columns, with the rows connected to pins 2, 3, 4 and 5
// and the columns connected to pins 6, 7 and 8, that sends MIDI messages with the notes specified in 'addresses' on MIDI channel 1, with velocity 127
ButtonMatrix<6, 6> buttonmatrix({2, 3, 4, 5, 6, 7}, { A0, A1, A2, A3, A4, A5}, addresses, 1, velocity);

void setup() {}

void loop() {
// Refresh the buttons (check whether the states have changed since last time, if so, send it over MIDI)
MIDI_Controller.refresh();
}

  1. there are cables on Amazon that connect a5-pin to a USB but I have no idea if that would work in this situation. I don't know how to wire a 5 pin to the Mega.
  2. I have no idea how to call or include/use hairless/

Why wouldn't you recommend the Due? Thanks.

“Analog” pins are just normal digital pins that additionally support analog inputs as well. You can use them as ordinary digital pins.

As mentioned earlier, the MIDI library is no longer supported. You should use the Control Surface library instead: Control Surface: NoteButtonMatrix.ino

It would most likely work (although some of the cheap ones are terribly designed and might not work). It's a cumbersome solution, though.

In your Arduino code (using Control Surface, not MIDI_Controller), you simply replace the line USBMIDI_Interface midi by HairlessMIDI_Interface midi.

Then you just run the Hairless application on your PC, and select the Arduino's serial/COM port from the menu.

Because Arduino does a poor job supporting it. It's compiler hasn't been updated in well over a decade, and it has some really annoying bugs and missing features. The hardware is probably fine, the software ... not so much.
The Control Surface library does support it, and users have reported success on GitHub, but I've never personally tested it on a Due.

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