Let's see it in action first :
How does it work ?
I recycled part of a cheap ebay ps2-to-usb cable to get a female mini din connector.
I think you can get the same from dealextreme here.
The connections were clearly marked on that chinese pcb : Vdd, CLK, Data, GND
The color convention is :
red = Vdd
white = Clock
green = Data
black = Ground
So I connected these to my arduino nano shield (see photo), and used the teensy ps2keyboard library.
(excellent instructions on the teensy site, you could use any arduino).
Reused some arduino code from my bicycle drummer project, and... voila
a drum computer using the ps2 keyboard !
At fist I just implemented some drum sounds for testing purposes, and it works perfectly.
The source code is available on github.
The Kicad project with schematic and PCB layout for the Arduino Shield can be found here.
It is simple to integrate a ps2 keyboard in your own projects, add this code in your arduino sketch :
#include <PS2Keyboard.h>
const int DataPin = 2;
const int IRQpin = 3;
PS2Keyboard keyboard;
void setup() {
...
keyboard.begin(DataPin, IRQpin); // ps2 keyboard
...
}
void loop() {
...
if (keyboard.available()) {
// read the next key
char c = keyboard.read();
KeyboardHandler(c);
}
...
}
So the KeyboardHandler is where you can add features.
For this simple demo it recognizes 3 keys, and sends the right midi command :
void KeyboardHandler(char key)
{
if(key==' ')
{
midiwrite(0x99, _BASSDRUM_NOTE, 0x65);
return;
}
if(key==PS2_ENTER)
{
midiwrite(0x99,_CLOSEDHIHAT_NOTE, 0x65);
return;
}
if(key=='0')
{
midiwrite(0x99, _SNAREDRUM_NOTE, 0x65);
return;
}
}
See video for demo using the above KeyboardHandler code (low audio quality from camera mic):
A lot of features could be added to the keys, including instrument change, piano style key layout, sequences start/stop, effect enable disable,.... I will update the project log when I expand the features.
Here's one expansion already : I extended the ps/2 keyboard to notify key releases as well.
This allows to send note off on key release. I also added some more features like tap tempo beat, bass sequence toggle, lead instrument selection,... see video. I committed the update code to the repo.
See project log for some more details. A video recorded with my camera (low audio quality from camera mic) :
I found a way to record the audio directly : use virtual dub, and record audio from my soundcard's line in, and video from my webcam. A slight shift between video and audio, but most important : The sound is much better preserved, if you have good speaker you will sure hear the difference. I added short video to the front of this description.