I have an old 61 Key keyboard that I'm trying to add a MIDI Out to but I'm having problems.
I'm Following This guide. Now I have the exact same PSR-150 that he does but I don't think the tutorial he is showing and the code/circuit he is using the same. His setup shows a 6X11 Matrix but in reality, it's a 11X6 Pulldown(i assume not sure how to tell if it's pull-up or pulldown).
I have altered the code to the best of my knowledge but when I press a key it shows the whole section(6 notes) in the serial monitor.
Here is the code.
#define NUM_ROWS 11
#define NUM_COLS 6
#define NOTE_ON_CMD 0x90
#define NOTE_OFF_CMD 0x80
#define NOTE_VELOCITY 127
//MIDI baud rate
#define SERIAL_RATE 115200
// Pin Definitions
// Row input pins
const int row1Pin = 2;
const int row2Pin = 3;
const int row3Pin = 4;
const int row4Pin = 5;
const int row5Pin = 6;
const int row6Pin = 7;
const int row7Pin = 8;
const int row8Pin = 9;
const int row9Pin = 10;
const int row10Pin = 11;
const int row11Pin = 12;
// 74HC595 pins
const int dataPin = 14;
const int latchPin = 15;
const int clockPin = 16;
boolean keyPressed[NUM_ROWS][NUM_COLS];
uint8_t keyToMidiMap[NUM_ROWS][NUM_COLS];
// bitmasks for scanning columns
int bits[] =
{
B00000001,
B00000010,
B00000100,
B00001000,
B00010000,
B00100000,
B01000000,
B10000000
};
void setup()
{
int note = 31;
for(int colCtr = 0; colCtr < NUM_COLS; ++colCtr)
{
for(int rowCtr = 0; rowCtr < NUM_ROWS; ++rowCtr)
{
keyPressed[rowCtr][colCtr] = false;
keyToMidiMap[rowCtr][colCtr] = note;
note++;
}
}
// setup pins output/input mode
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(row1Pin, INPUT);
pinMode(row2Pin, INPUT);
pinMode(row3Pin, INPUT);
pinMode(row4Pin, INPUT);
pinMode(row5Pin, INPUT);
pinMode(row6Pin, INPUT);
pinMode(row7Pin, INPUT);
pinMode(row8Pin, INPUT);
pinMode(row9Pin, INPUT);
pinMode(row10Pin, INPUT);
pinMode(row11Pin, INPUT);
Serial.begin(SERIAL_RATE);
}
void loop()
{
for (int colCtr = 0; colCtr < NUM_COLS; ++colCtr)
{
//scan next column
scanColumn(colCtr);
//get row values at this column
int rowValue[NUM_ROWS];
rowValue[0] = digitalRead(row1Pin);
rowValue[1] = digitalRead(row2Pin);
rowValue[2] = digitalRead(row3Pin);
rowValue[3] = digitalRead(row4Pin);
rowValue[4] = digitalRead(row5Pin);
rowValue[5] = digitalRead(row6Pin);
rowValue[6] = digitalRead(row7Pin);
rowValue[7] = digitalRead(row8Pin);
rowValue[8] = digitalRead(row9Pin);
rowValue[9] = digitalRead(row10Pin);
rowValue[10] = digitalRead(row11Pin);
// process keys pressed
for(int rowCtr=0; rowCtr<NUM_ROWS; ++rowCtr)
{
if(rowValue[rowCtr] != 0 && !keyPressed[rowCtr][colCtr])
{
keyPressed[rowCtr][colCtr] = true;
noteOn(rowCtr,colCtr);
}
}
// process keys released
for(int rowCtr=0; rowCtr<NUM_ROWS; ++rowCtr)
{
if(rowValue[rowCtr] == 0 && keyPressed[rowCtr][colCtr])
{
keyPressed[rowCtr][colCtr] = false;
noteOff(rowCtr,colCtr);
}
}
}
}
void scanColumn(int colNum)
{
digitalWrite(latchPin, LOW);
if(0 <= colNum && colNum <= 7)
{
shiftOut(dataPin, clockPin, MSBFIRST, B00000000); //right sr
//shiftOut(dataPin, clockPin, MSBFIRST, bits[colNum]); //left sr
}
else
{
shiftOut(dataPin, clockPin, MSBFIRST, bits[colNum-8]); //right sr
//shiftOut(dataPin, clockPin, MSBFIRST, B00000000); //left sr
}
digitalWrite(latchPin, HIGH);
}
void noteOn(int row, int col)
{
Serial.print("note on number ");
Serial.println(keyToMidiMap[row][col]);
//Serial.write(NOTE_ON_CMD);
//Serial.write(keyToMidiMap[row][col]);
//Serial.write(NOTE_VELOCITY);
}
void noteOff(int row, int col)
{
Serial.print("Note off number ");
Serial.println(keyToMidiMap[row][col]);
//Serial.write(NOTE_OFF_CMD);
//Serial.write(keyToMidiMap[row][col]);
//Serial.write(NOTE_VELOCITY);
}
Here Is what I found for the key matrix by using my multimeter in diode mode.
Here is what the sections look like and the input pin that each section is mapped to.
Here is my circuit.
I might have wired the output pins in the wrong order as they go (from right to left on the keyboard 1,3,5,7,9,2) but in the shift register, I think I will need to flip that around. But all that is going to change is the sequence of the keys.
Any help will be much appreciated.
Note in the original code he was using 2 shift registers for the outputs but i should be able to just use this right ?
void scanColumn(int colNum)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, B00000000); //right sr
//shiftOut(dataPin, clockPin, MSBFIRST, bits[colNum]); //left sr
digitalWrite(latchPin, HIGH);
}
Note 2: Inthe comments from Instructables some people were saying that you cant play 2 notes at the same time from the same group. EX: I can play G2 & G3 at the same time but G3 & A3 since they are part of the same group (input pin 14)
Again any thanks will be appreciated.