Multiplexing a music keyboard

Hi all, it's my first post here :grin:

I am trying to implement multiplexing for a 61 keys music keyboard, 5 octaves plus an additional C key; and selected the Arduino Mega 2560 board model.

The 13 keyboard's outputs are the keys grouped by note (C, B, A#,… , E, D#, D plus the additional C). The 10 inputs are the NO and NC contacts of the keys grouped by octave.

While understanding the principle used by the original synthesizer from the keyboard came, and programming the Arduino board are not problematic to me, I am facing an issue with a sort of feedback not supported by the micro-controller.

The Arduino must switch octaves to determine which keys are pressed. It is impossible to swap keyboard's inputs to outputs and feed them with constant 5V because of a presence of a diode on each key. So the 5V must come from the digital output.

The problem is that a digital input doesn't work when the voltage is supplied by a digital output for contact state detection.

I am afraid I must put a transistor-commanded 5V supply between the Arduino's digital outputs and my keyboard's inputs. I just hope someone will suggest anything easier…
While I consider the documentation to be scarce about these digital inputs/outputs, enlightenment about that subject will be appreciated.
As this application may be interesting, I will post the whole work if it succeeds.

Hi bogeyjammer,

The way you describe how the keyboard is connected sounds familliar. It souns like a matrix, and the use of diodes might even indicate charlieplexing. But it is hard to be sure. Can you draw a schematic for us? It does not need to include every note and octave. Just enough to give us the idea.

Paul

Sure

Reading your original post again, I still don't really understand all your questions and doubts, or why you believe transistors would be needed. So I will just describe how I would approach it and perhaps you will point out to me what i am missing.

You have an Arduino Mega, so plenty of outputs. Connect 13 outputs to the note connectors and another 5 to the NO octave connectors. Leave the NC connections unconnected. Also connect 13 10K resistors from the note connectors to ground.

Your sketch would then set all 5 of the octave outputs to ouput mode and low. The 13 note outputs woul be in input mode. For each octave output in turn, set that output to high and read the 13 inputs. Then set the octave output back to low and move to the next octave output and so on.

// Essai du fonctionnement d'un octave du clavier.
// Pas de modification d'intensité de LED

const int led = 13;
const int M1 = 38;

// Notes
const int C = 23;
const int B = 25;
const int Ad = 27;
const int A = 29;
const int Gd = 31;
const int G = 33;
const int Fd = 35;
const int F = 37;
const int E = 41;
const int Dd = 43;
const int D = 45;
const int Cd = 47;
const int CL = 49;
const int notes[13] = {CL, Cd, D, Dd, E, F, Fd, G, Gd, A, Ad, B, C};

// Loop
int note;
int test;
boolean detecte;

void setup()
{
  int index;
  pinMode(led, OUTPUT);
  for (index = 0; index < 13; index ++)
  {
    pinMode(notes[index], OUTPUT);
  }
  digitalWrite(M1, HIGH);
  Serial.begin(9600);
  Serial.print("demarrage\n");
}

void loop()
{
  // Lecture de l'état des entrées
  detecte = false;
  for (note = 0; note < 13; note++)
  {
    test = digitalRead(notes[note]);
    if (test == HIGH)
    {
      detecte = true;
      Serial.print(note);
      Serial.print("\n");
    }
  }
  if (detecte == true)
  {
    digitalWrite(led, HIGH);
  }
  else
  {
    digitalWrite(led, LOW);
  }
}

Well, your first diagram should not work. When the button is pressed, the input will read high, but when the button is not pressed, the input is floating and will probably not reliably read high or low. You could make this work by adding a 10K from the input to ground.

Your second diagram could work, but only if you set the input to pullup and the output is set to low. Then you could reliably read the switch.

Your third diagram will not work and could damage the arduino. What is this 5V source and which are its + and - connections? The input will simply read the 5V as either high or low depending on which way round you connect the 5V source, regardless of the button state. There could be a short curcuit between the 5V source and the Arduino output when the switch is pressed, damaging it.

Thanks for your answer. I apparently need study what are pullup and pulldown concepts as I've not found the logic of your explanation yet.
The third diagram shows a voltmeter, not a source.

EDIT : I've made a big mistake in my program, set inputs as outputs. Now I clearly see the floating phenomenon.
For what comes next, I'll install pull-down resistors, pull-ups would not work because of the presence of diodes in the keyboard.

Thanks for help.