Pages: 1 [2]   Go Down
Author Topic: PS2 Keyboard Emulator  (Read 8790 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, I thought as much :-)

Hardware wise, can I basically hook the port straight up to the arduino? Do I need to do something smarter? Finding lots of stuff about hooking up a keyboard to an arduino, but not the reverse....
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 36
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ive given up on the usb hid , as it wont compile.

so ive gone down the ps/2 route.

Ive also considered using serial ,  i only want to run the exe and dont want to install software or .net framework.



Just wondering if anyone has been able to act as a ps/2 keyboard yet ?

If so can you post your code that would be a big help.

cheer
luke

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My example of using ps2dev as a keyboard:

edit 'ps2dev.h'
Code:
comment out #include "WConstants.h"
and add a line #include <Wprogram.h>
...
//#include "WConstants.h"
#include <Wprogram.h>
...
here is code:
I used royboy's code http://siliconrepublic.blogspot.com
Code:
#include "ps2dev.h" // to emulate a PS/2 device

PS2dev keyboard(3,2); // PS2dev object (2:data, 3:clock)
int enabled = 0; // pseudo variable for state of "keyboard"

void ack() {
  //acknowledge commands
  while(keyboard.write(0xFA));
}

int keyboardcommand(int command) {
  unsigned char val;
  switch (command) {
  case 0xFF: //reset
    ack();
    //the while loop lets us wait for the host to be ready
    while(keyboard.write(0xAA)!=0);
    break;
  case 0xFE: //resend
    ack();
    break;
  case 0xF6: //set defaults
    //enter stream mode
    ack();
    break;
  case 0xF5: //disable data reporting
    //FM
    enabled = 0;
    ack();
    break;
  case 0xF4: //enable data reporting
    //FM
    enabled = 1;
    ack();
    break;
  case 0xF3: //set typematic rate
    ack();
    keyboard.read(&val); //do nothing with the rate
    ack();
    break;
  case 0xF2: //get device id
    ack();
    keyboard.write(0xAB);
    keyboard.write(0x83);
    break;
  case 0xF0: //set scan code set
    ack();
    keyboard.read(&val); //do nothing with the rate
    ack();
    break;
  case 0xEE: //echo
    //ack();
    keyboard.write(0xEE);
    break;
  case 0xED: //set/reset LEDs
    ack();
    keyboard.read(&val); //do nothing with the rate
    ack();
    break;
  }
}

void setup() {
  // send the keyboard start up
  while(keyboard.write(0xAA)!=0);
  delay(10);
}

void loop() {
  unsigned char c;
  //if host device wants to send a command:
  if( (digitalRead(3)==LOW) || (digitalRead(2) == LOW)) {
    while(keyboard.read(&c)) ;
    keyboardcommand(c);
  }
  else{ //send keypresses accordingly using scancodes
  // secancodes: http://www.computer-engineering.org/ps2keyboard/scancodes2.html
  keyboard.write(0x1C); // \
  keyboard.write(0xF0); //  |- send 'a'
  keyboard.write(0x1C); // /
  delay (1000); // wait 1 second
  }
}
« Last Edit: August 18, 2010, 08:56:42 am by Slasy » Logged

Pages: 1 [2]   Go Up
Jump to: