{"id":245,"date":"2013-02-09T22:04:50","date_gmt":"2013-02-09T21:04:50","guid":{"rendered":"http:\/\/labalec.fr\/erwan\/?p=245"},"modified":"2014-05-09T23:05:53","modified_gmt":"2014-05-09T21:05:53","slug":"arduino-ps2-keyboard","status":"publish","type":"post","link":"https:\/\/labalec.fr\/erwan\/?p=245","title":{"rendered":"Arduino : use a PS2 keyboard"},"content":{"rendered":"<p>This time lets play with Arduino and a ps2 keyboard.<\/p>\n<p>For the record here comes the ps2 male connectors :<\/p>\n<p><a href=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/ps2_male.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/ps2_male.png\" alt=\"ps2_male\" width=\"249\" height=\"203\" class=\"alignnone size-full wp-image-246\" \/><\/a><\/p>\n<p><strong>A quick schema<\/strong> :<\/p>\n<p><a href=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/ps2_keyboard_bb.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/ps2_keyboard_bb-225x300.png\" alt=\"ps2_keyboard_bb\" width=\"225\" height=\"300\" class=\"alignnone size-medium wp-image-247\" srcset=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/ps2_keyboard_bb-225x300.png 225w, https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/ps2_keyboard_bb-769x1024.png 769w, https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/ps2_keyboard_bb.png 1024w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><\/p>\n<p><strong>The sketch :<\/strong><\/p>\n<pre>\r\n#include <PS2Keyboard.h>\r\n\r\n#define KBD_CLK_PIN  3\r\n#define KBD_DATA_PIN 4\r\n\r\nPS2Keyboard keyboard;\r\n\r\nvoid setup ( )\r\n{\r\nkeyboard.begin(KBD_DATA_PIN);\r\n  Serial.begin(9600);\r\n  delay(1000);\r\n}\r\n\r\nvoid loop ( )\r\n{\r\n  if(keyboard.available()) {\r\n    \/\/ reading the \"extra\" bits is optional\r\n    byte   extra = keyboard.read_extra(); \/\/ must read extra before reading the character byte\r\n    char c = keyboard.read();\r\n    boolean ctrl = extra & 1;  \/\/ <ctrl> is bit 0\r\n    boolean  alt = extra & 2;  \/\/  <alt> is bit 1\r\n    if (ctrl) Serial.print('^');\r\n    if (alt)  Serial.print('_');\r\n    \/\/if      (c==PS2_KC_UP)      Serial.print(\"up\\n\");\r\n    \/\/if (c==PS2_KC_DOWN)    Serial.print(\"down\\n\");\r\n    \/\/if (c==PS2_KC_BKSP)    Serial.print(\"backspace\\n\");\r\n    \/\/if (c==PS2_KC_ESC)   { Serial.print(\"escape and reset\\n\"); keyboard.reset(); }\r\n    Serial.print(c);   \/\/lets print last input char to our serial monitor\r\n  }   \r\n}\r\n<\/pre>\n<p>(the PS2Keyboard library : <a href=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/PS2Keyboard.zip\">PS2Keyboard<\/a>)<\/p>\n<p><strong>A picture<\/strong> (i used female &#8211; male proto wires so that I did not have to cut out my ps2 keyboard wire).<\/p>\n<p><a href=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/ps2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/ps2-300x225.jpg\" alt=\"ps2\" width=\"300\" height=\"225\" class=\"alignnone size-medium wp-image-248\" srcset=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/ps2-300x225.jpg 300w, https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/ps2.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This time lets play with Arduino and a ps2 keyboard. For the record here comes the ps2 male connectors : A quick schema : The sketch : #include #define KBD_CLK_PIN 3 #define KBD_DATA_PIN 4 PS2Keyboard keyboard; void setup ( ) { keyboard.begin(KBD_DATA_PIN); Serial.begin(9600); delay(1000); } void loop ( ) { if(keyboard.available()) { \/\/ reading the <a href='https:\/\/labalec.fr\/erwan\/?p=245' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-245","post","type-post","status-publish","format-standard","hentry","category-arduino","category-18-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/245","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=245"}],"version-history":[{"count":8,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/245\/revisions"}],"predecessor-version":[{"id":1218,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/245\/revisions\/1218"}],"wp:attachment":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}