Arduino midi pedalboard

Hello,

Im new to arduino so I am not that familiar with it, during the quarantine I decided to give it a shot. I plan on building an organ midi pedalboard with 32 keys, so I'm trying to figure out the schematic considering that only arduino mega has enough ports to support 32 keys. Also, which version of arduino should i choose? I would prefer to not have to buy a midi to usb interface if thats possible, therefore the version should support native midi over usb.

Thanks in advance

so I'm trying to figure out the schematic considering that only arduino mega has enough ports to support 32 keys.

Any Arduino can support as many input keys as you like by the use of expansion chips like shift registers or port expanders.

If you are doing something with MIDI you are best using the Leonardo or the Micro because these two can support a USB connection to the computer that looks like a USB input. The alternative is to use a "helper" application on the receiving computer like "Hairless", this will convert the serial input into a virtual MIDI interface.

Assuming you don't want a velocity sensitive key then this should be simple.

Thank you for the reply,
I ordered the Leonardo. Now I'm checking the code required for this project and I think I will be using 2 libraries, Midiusb and MIDI_controller. If I understood correctly, I will use the code from example 11, used for button matrices. The problem I'm facing now is that I want to use the usb port instead of a midi interface, so in order send the midi packet from usb I need, somehow, to add to the code of ex 11 the MidiUSB.sendMIDI(midiEventPacket_t event) function from the Midiusb library.

Example 11 :

/*
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:
https://github.com/tttapa/MIDI_controller/wiki/Hardware
The note numbers are specified in the 'addresses' array.
Map accordingly in your DAW or DJ software.
Written by tttapa, 24/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 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 }
};

// 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<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();
}

The MIDI_Controller library has been replaced by the Control Surface library. I highly recommend you use that library instead.
For example: NoteButtonMatrix.ino

There is no need to use MidiUSB.sendMIDI directly, just use the right MIDI Interface. If you want MIDI over USB, just use the MIDIUSB_Interface, as shown in the example.

Pieter

PieterP:
The MIDI_Controller library has been replaced by the Control Surface library. I highly recommend you use that library instead.
For example: NoteButtonMatrix.ino

There is no need to use MidiUSB.sendMIDI directly, just use the right MIDI Interface. If you want MIDI over USB, just use the MIDIUSB_Interface, as shown in the example.

Pieter

Thank you very much for the reply, thats exactly what I was looking for.

Hi, I'm sorry if it's trivial, but I'm new and I consider using an arduino to build an organ midi pedal. I have the idea:
I will make a wooden pedals and assemble a diode matrix for 32 keys. I want to play more tones at the same time. I will connect the diode matrix to the Arduino UNO and I will connect Arduino via USB to the computer, where it will appear to me as a midi device and I will be able to play pedals in the Grand Orgue program in Linux Ubuntu. I don't need a midi connector. Usb from Arduino would suffice.
I don't want to build complicated circuits. Only diode matrix and arduino.
The question is: is it possible with Arduino UNO?
Thank you.

1 Like

An Arduino Uno is not a good choice if you want to use MIDI over USB, because it has no native USB support. See Control Surface: MIDI over USB.

miltiadesard:
Hello,

Im new to arduino so I am not that familiar with it, during the quarantine I decided to give it a shot. I plan on building an organ midi pedalboard with 32 keys, so I'm trying to figure out the schematic considering that only arduino mega has enough ports to support 32 keys. Also, which version of arduino should i choose? I would prefer to not have to buy a midi to usb interface if thats possible, therefore the version should support native midi over usb.

Thanks in advance

And a pedal board only has to be duo-phonic so the old analog resistor string trick can be used,
implying 2 analog inputs are enough to detect 1 or 2 notes. https://amsynths.co.uk/wp-content/uploads/2019/11/ARP2500KeyboardDiagram.jpg

1 Like

To expand on this, mainly because its a very clever circuit, as well as appropriate to this project.

Here's an 8 note simplified version:

A0 is weakly pulled to ground until a pedal is pressed. Then the A0 line's voltage is set by the
voltage divider chain, thus identifying which pedal - something close to 1.5V means note D for
instance.

If while D is pressed the F pedal is also pressed, the A0 line stays at 1.5V (since the divider
chain is driven from a constant current source, shorted out a part of it won't change the current
or the voltages below the short.

However the A1 voltage, normally at 4.0V will be pulled down - F and D notes are 3 resistors
apart, so when they are both pressed 1.5 volts worth of the chain is shorted out, so A1 voltage
drops 1.5V.

So the interval controls the drop in A1 voltage, and the lower of the two notes controls A0 voltage,
and its simple in software to convert this back to a pair of notes.

The only thing to be careful of is that the voltages have stabilized (should you read them mid-transition),
which means reading repeatedly until the value is stable (and the 1M resistor might be too high
in practice, slowing down the release, even 10k will work here, although the voltages in the divider will be pulled down a tad).

For a 25 note pedalboard use a spacing of 0.2V perhaps? And the constant current source needs to
be good enough, a Wilson current mirror might be suitable (setting the current from another resistor
to ground, making the whole setup ratiometric).

For some reason I read 32 as 25, so I'd suggest 120mV per semitone, perhaps using 120 ohm resistors
and 1mA constant current?

Or go for the port expander route and a switch matrix. You won't need diodes for duo-phonic

I am interested in this too, and was thinking of doing it with 3 4051 mux/demuxers. I only want 24 keys, so 3 should do it, I just don’t know how to code the multiplexer into it.

If you want MIDI, you could probably use the piece of code from notes and volts (just search notesandvolts 3), and you’ll come up with a great tutorial if you want MIDI.

I do not want MIDI however, and instead want to use the tone library, and just don’t know how to implement it with multiplexers (I can do it without, I just don’t have enough I/O ports, so I’ve thought of using the mega, but I already bought the 4051s)

1 Like

You could try something like this:

#include <Arduino_Helpers.h> // https://github.com/tttapa/Arduino-Helpers
#include <AH/Hardware/Button.hpp> // Button
#include <AH/Hardware/ExtendedInputOutput/AnalogMultiplex.hpp> // CD74HC4051
#include <AH/Containers/ArrayHelpers.hpp> // cat, copyAs

// Pin with speaker connected:
const uint8_t tonePin = 13;

// Instantiate an array of multiplexers.
CD74HC4051 muxes[] = {
  {
    10,        // Input pin
    {2, 3, 4}, // Address pins S0, S1, S2
  }, {
    11,        // Input pin
    {2, 3, 4}, // Address pins S0, S1, S2
  }, {
    12,        // Input pin
    {2, 3, 4}, // Address pins S0, S1, S2
  },
};

// Convert arrays of pins of the muxes to one big array of buttons:
Array<Button, 24> buttons = copyAs<Button>(cat(muxes[0].pins(),
                                               cat(muxes[1].pins(),
                                                   muxes[2].pins())));
// Explanation: 
//
// "muxes[i].pins()" returns the array of pin numbers of the i-th
//     multiplexer.
// "cat" concatenates two arrays.
// "copyAs<Button>" converts an array of pin numbers to an array
//     of Button objects.
//
// The internal pull-up resistors will be used, so connect all buttons
// between a pin of the multiplexer and ground.

// Frequencies in Hz:
Array<unsigned int, 24> tones = {
   440,   466,   494,   523,   554,   587,   622,   659,   
   698,   740,   784,   831,   880,   932,   988,  1047,
  1109,  1175,  1245,  1319,  1397,  1480,  1568,  1661,
};

void setup() {
  // Initialize multiplexers and buttons
  for (auto &mux : muxes) 
    mux.begin();
  for (auto &button : buttons)
    button.begin();
}

void loop() {
  static_assert(buttons.length == tones.length, 
                "Need the same number of buttons as tones");
  static uint8_t activeTone = 0;
  // Loop over all buttons
  for (uint8_t i = 0; i < buttons.length; ++i) {
    // Read the button
    switch (buttons[i].update()) {
      // If it's pressed, play a tone
      case Button::Falling:
        tone(tonePin, tones[i]);
        activeTone = i;
        break;
      // If it's released, stop the tone
      case Button::Rising:
        if (activeTone == i)
          noTone(tonePin);
        break;
      default: break;
    }
  }
}