Go Down

Topic: PS2 keyboard modification (Read 1 time) previous topic - next topic

netdudeuk

Jun 08, 2016, 11:50 am Last Edit: Jun 08, 2016, 12:26 pm by netdudeuk
Hi

I have a USB keyboard that works ok through a PS2 adapter.

I would like to make it cordless and decided that the Adafruit Bluefruit EZ-Key could be a good option.


There's an existing project to convert an IBM Model M keyboard using this device and an Arduino Micro -

https://learn.adafruit.com/convert-your-model-m-keyboard-to-bluetooth-with-bluefruit-ez-key-hid/overview


However, running up the same hardware with my own keyboard doesn't show me key presses.  I've looked at the source code but I don't know where it is failing.


Here's the output seen before I press a key -


started logging
[ Initializing PS2 matrix ]
setting global host driver
wFF [ack]
RESET_RESPONSE: rAA [ok]
KBD_ID:

Adafruit Bluefruit HID v1.2 5/12/2014

Attempt to connect to 9,dd,500e7e
Connected
NL:Y CL:N SL:N


When I press the main ENTER key, I get loads of output like this -


r5A rF0
CODESET_QUERY: wF0 [ack] w00 [codeset] FA [ack]
CODESET_RESPONSE: r02 02 [ok]
CODESET_REQUEST: wF0 [ack] w03 [ok]
CODESET_QUERY: wF0 [ack] w00 [codeset] FA [ack]
CODESET_RESPONSE: r02 02 [ok]
CODESET_REQUEST: wF0 [ack] w03 [ok]
CODESET_QUERY: wF0 [ack] w00 [codeset] FA [ack]
CODESET_RESPONSE: r02 02 [ok]
CODESET_REQUEST: wF0 [ack] w03 [ok]
CODESET_QUERY: wF0 [ack] w00 [codeset] FA [ack]
CODESET_RESPONSE: r02 02 [ok]
CODESET_REQUEST: wF0 [ack] w03 [ok]
CODESET_QUERY: wF0 [ack] w00 [codeset] FA [ack]
CODESET_RESPONSE: r02 02 [ok]
CODESET_REQUEST: wF0 [ack] w03 [ok]

and so on ...


The 5A F0 is encouraging as they do seem to relate to this key.

Any idea what the rest of the debug output implies and why I don't see the key press ?


My other option was to use something like this sketch -


Code: [Select]
#include <PS2Keyboard.h>

const int DataPin = 3;
const int IRQpin =  2;

PS2Keyboard keyboard;

void setup()
{
  keyboard.begin(DataPin, IRQpin);

  Serial.begin(9600);
  Serial1.begin(9600);

  // printabletest(); delay(200);

  // altkeystest();
  // nonprinting();
  //rawkeytest();

}

void loop()
{
    if (keyboard.available())
    {
      char c = keyboard.read();
      Serial1.print(c);

      // Serial.print(keyboard.get_iso8859_code(), HEX);
     
    }
 
}
 
void printabletest() {
  Serial.println("Testing printable 0x20-0x7E...");
  for (char c = 0x20; c <= 0x7E; c++)
  {
    Serial.write(c);
    Serial1.write(c);
    delay(10);
  }
 
  Serial1.write('\n');
  delay(3000);
  // Serial.read(); // eat one char
  Serial.println();
 
  for (uint16_t i=0; i<200; i++) {
    while (Serial.available())
      Serial.write(Serial.read());
    delay(10);
  }
}

void nonprinting() {
  Serial.println("Insert");
  Serial1.write(1); delay(1000);
  Serial.println("Home");
  Serial1.write(2); delay(1000);
  Serial.println("Page Up");
  Serial1.write(3); delay(1000);
  Serial.println("Delete");
  Serial1.write(4); delay(1000);
  Serial.println("End");
  Serial1.write(5); delay(1000);
  Serial.println("Page Down");
  Serial1.write(6); delay(1000);
  Serial.println("Right Arrow");
  Serial1.write(7); delay(1000);
  Serial.println("Backspace");
  Serial1.write(8); delay(1000);
  Serial.println("Tab");
  Serial1.write(9); delay(1000);
  Serial.println("Enter");
  Serial1.write(10); delay(1000);
  Serial.println("Left Arrow");
  Serial1.write(11); delay(1000);
  Serial.println("Down Arrow");
  Serial1.write(12); delay(1000);
  Serial.println("Enter");
  Serial1.write(13); delay(1000);
  Serial.println("Up Arrow");
  Serial1.write(14); delay(1000);

  for (uint8_t i=15; i<27; i++) {
    Serial.print("F"); Serial.println(i-14, DEC);
     Serial1.write(i); delay(500);
  }
  Serial.println("ESC");
  Serial1.write(27); delay(1000);
  Serial.println("Capslock");
  Serial1.write(28); delay(1000);
  Serial.println("Scroll lock");
  Serial1.write(29); delay(1000);
  Serial.println("Break");
  Serial1.write(30); delay(1000);
  Serial.println("Numlock");
  Serial1.write(31); delay(500);
 
}
void altkeystest() {
  Serial.println("Left Control\n");
  Serial1.write(0xE0);
  delay(500);
  Serial.println("Left Shift\n");
  Serial1.write(0xE1);
  delay(500);
  Serial.println("Left Alt\n");
  Serial1.write(0xE2);
  delay(500);
  Serial.println("Left GUI\n");
  Serial1.write(0xE3);
  delay(500);
  Serial.println("Right Control\n");
  Serial1.write(0xE4);
  delay(500);
  Serial.println("Right Shift\n");
  Serial1.write(0xE5);
  delay(500);
  Serial.println("Right Alt\n");
  Serial1.write(0xE6);
  delay(500);
  Serial.println("Right GUI\n");
  Serial1.write(0xE7);
  delay(500);
}

void keyCommand(uint8_t modifiers, uint8_t keycode1, uint8_t keycode2 = 0, uint8_t keycode3 = 0,
                uint8_t keycode4 = 0, uint8_t keycode5 = 0, uint8_t keycode6 = 0) {
  Serial1.write(0xFD);       // our command
  Serial1.write(modifiers);  // modifier!
  Serial1.write((byte)0x00); // 0x00 
  Serial1.write(keycode1);   // key code #1
  Serial1.write(keycode2); // key code #2
  Serial1.write(keycode3); // key code #3
  Serial1.write(keycode4); // key code #4
  Serial1.write(keycode5); // key code #5
  Serial1.write(keycode6); // key code #6
}

void rawkeytest() {
  // test sending a single 'a' (keycode 4)
  keyCommand(0, 4);
  delay(100);
  keyCommand(0, 0);
}



Please ignore the spare code in there, although it does show some of the other options available with the EZ-Key.

It does work to an extent.  I can type into my PC.


However, I cannot do the CTRLs, ALTs, etc, etc


This example code would let me send such keys -

Code: [Select]

void setup() {
   Keyboard.begin();
}

void loop() {
   delay(10000);
   Keyboard.press(KEY_LEFT_CTRL);
   Keyboard.press(KEY_LEFT_ALT);
   Keyboard.press(KEY_DELETE);
   // delay(100);
   Keyboard.releaseAll();
}



However, that works independently of the keyboard.


So, a few options, none of them perfect.


To get full functionality, it looks like I need to be able to read the scan codes and then maybe convert them to something else for the EZ-Key.  Or something like that.

Anyone got any ideas please ?

Thanks




Go Up