PS/2 Keyboard 3dprinter Controler

This project allow fast and easy control of about any 3dprinter directly from a PS/2 Keyboard.  

Why do this ? Because the LCD controller and the the single control knob on it, make it fastidious to do simple tasks, specially when you do frequent upgrade/mods/tuning or repairs on your 3d printer.     

At first , I've try to do it with  an Arduino USB Shield and a USB keyboard , But I didn't manage it to make it work, probably because of the USB hub most USB keyboard have inside.  PS/2 keyboard are way simpler to interface anyway , And It  actually surprised me a lot that  there are plenty of brand new ones to chose from (if you don't have an old one lying around) . You can even find some wireless! The best part is that this is only the beginning, because I'm pretty sure this would be all directly feasible directly on the 3d printer board itself without the external arduino.  It is a prety simple code. Stay tuned ! 

 My Prusa i3 Printer  is using a Ramp 1.4 board on a 2560 Arduino  it could work with many other printer using g-code input, as soon as you find the Microcontroler RS-232 G-Code RX pin 
 I've use another  2560 Arduino to do the project. a smaller arduino could do it , But You may have to modify code to use only one or another uart 
 This project use the PS/2 Teensy/Arduino Library
 You may also need basic soldering skills. 


Code :  (or get Arduino file down the page) 
 *  PS/2 keyboard interface to control RepRap/Prusa-i3
 *  Based on library (version 2.4)
 *  Hardware setup: 
 *    For Arduino 2560 (shurly easy to adapt to others boards ) 
 *    Com1 for debug 
 *    Com3 to send commands to Ramp Arduino    Arduino2560-TX3-Pin14 to Ramp-RX-Pin0   
 *    PS2 Key board hook to gdn/5v/pin18/pin19
 *  Software functionalities
 *    x        Zero x        
 *    y        Zero y
 *    z        Zero z
 *    Tab      Zero xyz  
 *    Home     Zero xyz   (need to modify PS"Keyboard.h (#define PS2_HOME 0) to 1  
 *    ->       move X right 
 *    <-       move X left
 *    up       move Y back
 *    down     move Y front
 *    Page-up  move Z up 
 *    Page-dw  move Z down 
 *    1        set moves to 1 mm 
 *    2        set moves to 10  mm 
 *    3        set moves to 100 mm
 *    f        Toggle Fan on / fan off 
 *    p        Preheat PLA 190 / 60 
 *    a        Preheat ABS 210 / 110
 *    o-0      Heat off      
 *    e        Extrude 10mm
 *    r        Reverse 10mm
#include <PS2Keyboard.h>
const int ps2DataPin = 18;
const int ps2IRQpin =  19;
unsigned int move_dist =1;
unsigned int fan_speed =0;
PS2Keyboard keyboard;

void setup() {
  /*PS2Keyboard  requries both pins specified for begin()    keyboard.begin(data_pin, irq_pin);
     Valid irq pins:
     Arduino Uno:  2, 3
     Arduino Due:  All pins, except 13 (LED)
     Arduino Mega: 2, 3, 18, 19, 20, 21  */ 
  keyboard.begin(ps2DataPin, ps2IRQpin);     
  Serial.begin(115200); //debug port
  Serial.println("Keyboard Test :");
  Serial3.begin(250000);//port to printer 

void loop() {
  if (keyboard.available()) {
    char c =;      
    if      (c == PS2_ENTER)     {Serial.println();       } # 
    else if (c == 'x')            {Serial.println(" Home-X ");           Serial3.println("G28 X0");  }
    else if (c == 'y')            {Serial.println(" Home-Y ");           Serial3.println("G28 Y0");  }
    else if (c == 'z')            {Serial.println(" Home-Z ");           Serial3.println("G28 Z0");  }
    else if (c == PS2_TAB)        {Serial.println(" Home-All ");         Serial3.println("G28");  }
    else if (c == PS2_HOME)       {Serial.println(" Home-All ");         Serial3.println("G28");  }    // (nead to modify PS2Keyboard.h (#define PS2_HOME 0) to 1  
    else if (c == PS2_LEFTARROW)  {Serial.println(" Move-X-Left ");        Serial3.println("G91"); if(move_dist==1) Serial3.println("G1 X1 F6000") ; if(move_dist==10) Serial3.println("G1 X10 F6000") ;  if(move_dist==100) Serial3.println("G1 X100 F6000") ;  Serial3.println("G90");  }
    else if (c == PS2_RIGHTARROW) {Serial.println(" Move-X-Right ");       Serial3.println("G91"); if(move_dist==1) Serial3.println("G1 X-1 F6000"); if(move_dist==10) Serial3.println("G1 X-10 F6000");  if(move_dist==100) Serial3.println("G1 X-100 F6000");  Serial3.println("G90");  }              
    else if (c == PS2_UPARROW)    {Serial.println(" Move-Y-Up ");          Serial3.println("G91"); if(move_dist==1) Serial3.println("G1 Y1 F6000") ; if(move_dist==10) Serial3.println("G1 Y10 F6000") ;  if(move_dist==100) Serial3.println("G1 Y100 F6000") ;  Serial3.println("G90");  }
    else if (c == PS2_DOWNARROW)  {Serial.println(" Move-Y-Down ");        Serial3.println("G91"); if(move_dist==1) Serial3.println("G1 Y-1 F6000"); if(move_dist==10) Serial3.println("G1 Y-10 F6000");  if(move_dist==100) Serial3.println("G1 Y-100 F6000");  Serial3.println("G90");  }              
    else if (c == PS2_PAGEUP)     {Serial.println(" Move-Z-Up ");          Serial3.println("G91"); if(move_dist==1) Serial3.println("G1 Z1 F6000") ; if(move_dist==10) Serial3.println("G1 Z10 F6000") ;  if(move_dist==100) Serial3.println("G1 Z100 F6000") ;  Serial3.println("G90");  }
    else if (c == PS2_PAGEDOWN)   {Serial.println(" Move-Z-Down ");        Serial3.println("G91"); if(move_dist==1) Serial3.println("G1 Z-1 F6000"); if(move_dist==10) Serial3.println("G1 Z-10 F6000");  if(move_dist==100) Serial3.println("G1 Z-100 F6000");  Serial3.println("G90");  }              
    else if (c == 'e')            {Serial.println(" Extrude ");            Serial3.println("G91"); if(move_dist==1) Serial3.println("G1 E1 F300")  ; if(move_dist==10) Serial3.println("G1 E10 F300") ;  if(move_dist==100) Serial3.println("G1 E100 F300") ;  Serial3.println("G90");  }
    else if (c == 'r')            {Serial.println(" Retract ");            Serial3.println("G91"); if(move_dist==1) Serial3.println("G1 E1 F300")  ; if(move_dist==10) Serial3.println("G1 E-10 F300");  if(move_dist==100) Serial3.println("G1 E-10 F300");  Serial3.println("G90");  }              

    else if (c == '1')           {Serial.println(" Move-Dist = 1mm");    move_dist=1;      }
    else if (c == '2')           {Serial.println(" Move-Dist = 10mm");   move_dist=10;     }
    else if (c == '3')           {Serial.println(" Move-Dist = 100mm");  move_dist=100;    }

    else if (c == 'p')           {Serial.println(" Pre-Heat PLA");  Serial3.println("M140 S60");   Serial3.println("M104 S190");   }
    else if (c == 'a')           {Serial.println(" Pre-Heat ABS");  Serial3.println("M140 S110");  Serial3.println("M104 S200");   }
    else if (c == 'o')           {Serial.println(" Heat OFF");  Serial3.println("M140 S0");  Serial3.println("M104 S0");   }
    else if (c == '0')           {Serial.println(" Heat OFF");  Serial3.println("M140 S0");  Serial3.println("M104 S0");   }
    else if (c == 'f')           {     if(fan_speed==0  ){ fan_speed=255; Serial.println("Fan ON") ; Serial3.println("M106 S200 B1"      );  }  
                                  else if(fan_speed==255){ fan_speed=0  ; Serial.println("Fan OFF"); Serial3.println("M106 S0     ");  } }
    else if (c == PS2_ESC)       {Serial.println(" Emerg Stop");  Serial3.println("M112");    }
    else                         {Serial.print(c);        }// otherwise, just print all normal characters


Jean-François Payeur,
Nov 22, 2016, 4:46 PM