Feedback!

Leonardo Keyboard

Views: 13487 Difficulty: 3 Status: Development
Leo_mini_key_str8

32 buttons for a fully-functioning hand-held USB keyboard.

Do you like little buttons? Then let this hand-held keyboard cuddle into your palm. The keyboard is built on top an Arduino Leonardo so you can reprogram to your hearts content. We have pulled out a bunch of pins to make it easily extensible. For example you can make it wireless by hooking up an XBEE or bluetooth module, or interface with any I2C device. This keyboard is built on top of the Arduino Leonardo so it is easy to program and hack!

The Leonardo Keyboard

Leo_mini_key_str8
The lozenge shaped Leonardo Keyboard fits ergonomically into your palm.

Leonardo Keyboard Arduino Code

Here is Arduino Leonardo code to use 4 shift registers hooked up to a total of 32 buttons as a USB keyboard.
 /* LucidTronix LEO Keyboard
 * works as standard USB keyboard
 * Tutorial and details at:
 * http://www.lucidtronix.com/tutorials/51
 *  This code requires Arduino Leonardo
 */ 
 
int dataPin = 4;
int clockPin = 5;
int latchPin = 6;

unsigned long last_press = 0;
unsigned long last_key_press = 0;

char* letters[] ={"abcdefgh","ijklmnop","qrstuvwx","yz -@#.@" };

int leds[] = {7,8,9};

int num_chars = 43;
int num_registers = 4;
byte button_states[] = {0x00,0x00,0x00,0x00};  //01001000
int cursor_index = 0;
int char_index = 0;
char cur_char = 'X';

boolean shifting = false;

void setup() {
  Serial.begin(9600);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT); 
  pinMode(dataPin, INPUT);
  for(int i = 0 ; i < 3; i++) pinMode(leds[i], OUTPUT);
  for(int i = 0 ; i < 3; i++) digitalWrite(leds[i], HIGH);
  delay(200);
  for(int i = 0 ; i < 3; i++) digitalWrite(leds[i], LOW);
  


}

void loop() {
  if (millis() - last_key_press > 450) read_keyboard();
  if ( shifting ) digitalWrite(leds[0], HIGH);
  else digitalWrite(leds[0], LOW);
  delay(350);
}


void read_keyboard(){
  //set it to 0 to transmit data serially  
  digitalWrite(latchPin,LOW);
  //while the shift register is in serial mode
  //collect each shift register into a byte
  //the register attached to the chip comes in first 
  for (int i = 0; i < num_registers; i++){
    button_states[i] = shiftIn(dataPin, clockPin);
  }
  boolean something_in = false;
  for (int i = 0; i < num_registers; i++){    
    something_in = translate_buttons_2_keys(button_states[i], letters[i]);
    if (something_in) last_key_press = millis(); 
  }
  digitalWrite(latchPin,HIGH);
}
boolean translate_buttons_2_keys(byte buttons, char* keys){
  for(int i = 0 ; i < 8; i++){
     if ( (1 << i) & buttons ){
       cur_char = keys[i];
       if (keys[i] == '-') Keyboard.write(KEY_RETURN);
       else if (keys[i] == '@') Keyboard.write(KEY_BACKSPACE);
       else if (keys[i] == '#' && shifting) Keyboard.release(KEY_LEFT_SHIFT); 
       else if (keys[i] == '#' && !shifting) Keyboard.press(KEY_LEFT_SHIFT);        
       else if (keys[i] == '|') Keyboard.write(21);
       else Keyboard.print(keys[i]);
       if (keys[i] == '#') shifting = !shifting;
       char_index++;
       return true;
     }     
  }
 return false; 
}
byte shiftIn(int myDataPin, int myClockPin) { 
  int i;
  int temp = 0;
  int pinState;
  byte myDataIn = 0;

  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, INPUT);

  for (i=7; i>=0; i--)
  {
    digitalWrite(myClockPin, 0);
    delayMicroseconds(20);
    temp = digitalRead(myDataPin);
    if (temp) {
      pinState = 1;
      myDataIn = myDataIn | (1 << i);
    }
    else {
      pinState = 0;
    }
    digitalWrite(myClockPin, 1);
  }
  return myDataIn;
}

Parts

Title Description # Cost Link Picture
PCB Leo Keyboard Printed Circuit Board for shift register based Leonardo Keyboard 1 $7.0 Link Leo_mini_keys_pcb
ATMEGA32U4-MU Integrated Circuits MCU AVR 32K FLASH 16MHZ 44-QFN Value: 2.7 V ~ 5.5 V 16MHz 1 $6.04 Link Screen_shot_2012-12-28_at_7.31.41_pm
USB Micro B Female Connector Micro USB Surface Mount, Right Angle, Horizontal 1 $0.72 Link 10103594-0001lf_sml
Voltage Regulator 3v3 SMD IC REG LDO 3.3V .15A SOT23 Up to 6V input output 3.3V 150mA (Max) Value: 3.3V 1 $0.46 Link Sot-23-3_pkg
Shift Register IC STATIC SHFT REG 8STG 16-TSSOP Parallel or Serial to Serial 3 V ~ 18 V Value: Parallel to Serial 4 $0.45 Link Screen_shot_2012-12-28_at_7.33.47_pm
Switch SWITCH SLIDE DPDT 6VDC 0.3A SMT Value: DPDT 1 $0.44 Link Mfg_js202011scqn
Button Tactile switch SMD SPST 0.05A 12V Value: SPST 33 $0.2 Link Fsm4jsma
Resistor Array RES ARRAY 10K OHM 4 RES 1206 Value: 10k 8 $0.12 Link Vishay_-_cra06s-8
LED SMD LED CHIPLED 645NM Red diffuse 1206. Green polarity indicator is opposite of normal. Value: 1.8v Red 4 $0.11 Link Lh_n974_pkg

    Comments:

    Missing_profile
    LordeYaYa
    Where is the EagleCAD file for this tutorial? I can't seem to find it anywhere.
    Sun, Jan 11 2015 3:04PM
Permalink: http://lucidtronix.com/tutorials/51
Handheld gaming machine, based on the Arduino Leonardo, equipped with joystick, SD card and more....
4 Daisy chained CD4021 shift registers gives us 32 inputs....
A QWERTY keyboard you build yourself....
Build your own clock with the MCP79410 chip and 4 7-Segment LED modules....
Keyboard kit using CD4021 shift registers and big through hole buttons....
Standalone programmable Heart-Shaped LED display....
The Wearable Wayfinder is a totally programmable, beautiful little computer for your wrist packed wit...
Write messages on Liquid Crystal Displays with potentiometers or keyboards....