Close
0%
0%

PC Keyboard becomes synthesizer / drum computer

Converted an old PS2 keyboard into a synthesizer/drum computer/... using arduino nano.

Similar projects worth following
Converted an old PS2 keyboard into a drum machine using arduino nano.
I added key release handling to the teensy ps/2 keyboard library, to allow note on and note off
handling. Result : a playable keyboard synth with drum n bass sequencing and lead instrument selection.

The project can run standalone from a single 9V battery, or be powered through the arduino's usb connector. It uses a Dreamblaster S1 breakout board to generate the sound.
A cheap ps2 to usb cable was scavenged for the necessary connector.

All source code and the arduino shield schematic and pcb layout is available in the github repo.

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.

View all 6 components

  • Harry Potter PS/2 Mouse

    serdef08/01/2014 at 16:46 0 comments

    Hi,

    here are the PS/2 Harry Potter mouse details.

    The mouse glows red when you move it : it shines between the buttons and lights the harry potter logo, which is transparent.  Should I used it in this project, to control filters, pitch, balance, volume or reverb depth? 

    Or maybe it deserves a project on its own ? Maybe I should open it up, and try to mod it ?

    You judge, here are the photos:

     MOUSE NOT POWERED :

    MOUSE POWERED, NOT MOVING: 

    MOUSE POWERED + MOVING :

  • Bass Line instrument selection

    serdef07/27/2014 at 18:52 0 comments

    Implemented instrument selection for the bass line, using the '+' and '-' keys. Also found a way to record the audio directly, the next movies will have a much  better sound quality.

  • Added Filter Resonance Control

    serdef07/27/2014 at 16:27 0 comments

    Added a second potmeter to control filter resonance of the bassline. Had to place it horizontally to avoid obstructing the usb cable.

    new situation :

    pot1 : bass line filter cutoff control
    pot2 : bass line filter resonance control 

    This allows to shape your sound like an analog synth. But there's more ! You can not only filter synth like sounds such as the square and sawtooth synth leads.  You can apply to piano, flute, gunshot, applause, oooh choir, bird tweet, telephone ring, ... 

    Amazing effects :-). The code is updated in the repo.

     See photo for the new setup :

  • Synth implementation : key release handling

    serdef07/27/2014 at 14:02 0 comments

    The teensy ps/2 keyboard library was extended to support notification of key releases.

    I maintained backwards compatibility and added 2 new public methods :

    add 'rel' to the usual method, and provide an iskeyrelease bool parameter. 

    this parameters is referenced and set to true when the keypress was a release..

    Only a few keys are supported right now. I plan to refactor  the code to eliminate redundancy and implement full playable keyboard. 

    So the code below shows a simple example of sounding a synth sound as long as key 'c' is pressed.

    void loop() {

    ...

    if (keyboard.availablerel()) {

    // read the next key

    bool iskeyrelease = false;

    char c = keyboard.readrel(iskeyrelease);

    KeyboardHandler(c,iskeyrelease);

    }

    ..

    }

    #define _SYNTHPRESS_STATUSCODE 0x90

    #define _SYNTHRELEASE_STATUSCODE 0x80

    void KeyboardHandler(char key,bool iskeyrelease)

    {

      static bool c_pressed = false;
      byte synthstatuscode;
     byte volumecode;

     synthstatuscode = iskeyrelease ? _SYNTHRELEASE_STATUSCODE : _SYNTHPRESS_STATUSCODE;
     volumecode = iskeyrelease ? 0x00 : leadvolume;

       if(key=='c')

        {

           if(!c_pressed || iskeyrelease)

          {

            midiwrite(synthstatuscode, 40, volumecode);

          }

          c_pressed = !iskeyrelease;

          return;

       }

    }

View all 4 project logs

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates