C Program
An Application


Picture of the keypad The Qtronix Scorpius 22 keypad has the keys found in the "numeric" part of a standard keyboard. It has an RS-232 interface with a 9-pin connector. This note describes the keypad, its key codes, and simple application using the keypad.

The keypad is available from Jameco for $39.95 in their catalog #993. The unit evaluated was purchased from a local store (T-Zone) for 22 dollars.

Auxiliary keypads are also available which plug in-line with a normal keyboard using a PS2 style connector. These units are a better choice if you really want a numeric keyboard for your console or X-window applications. Currently serial devices can not be conveniently used as auxiliary keyboards under Linux

A PIC 17C54 is at the heart of the keypad. The modem control lines on the serial port supply power for the 17C54 and the green NumLock LED. The photo below is of the circuitry in the keypad.

Picture of the keypad circuitry


It looks like the keypad uses RTS and DTR to power the serial port. DTR needs to be set to +12 volts and RTS must be set to -12 volts. The port should be configured for 8 data bits, no parity, and one stop bit (8,N,1) at 9600 baud. The unit sends a single byte for each keystroke. The keypad has three modifier keys: Shift, Fn, and NumLock. NumLock is modal with a green LED to indicate state. Fn and Shift are chord keys like the shift key on most keyboards. The table below shows the key codes for all keys for each of the modifiers.
Keypad Key Codes (in hex)
Key FnNumShift


C Program

The following C program opens the port, sets the modem control lines and reads a single keystroke from the keypad. The output is a two character hex number which represents the keycode.

/*  keypad : reads a single key code from a Qtronix serial keypad */
/*  Usage:  keypad <serial port>                                  */
/*     eg:  keypad /dev/ttyS0                                     */

#include <stdio.h>
#include <termio.h>
#include <sys/fcntl.h>

main (int argc, char *argv[])
    struct  termios    tbuf;
    int                fd_dev;
    int                sm;  /* state of the modem lines */
    unsigned char      buf;

    if (( fd_dev = open(argv[1], (O_RDWR | O_NDELAY), 0)) < 0 ) {
        printf("Unable to open tty port specified\n");

    tbuf.c_cflag = CS8|CREAD|B9600|CLOCAL;
    tbuf.c_iflag = IGNBRK;
    tbuf.c_oflag = 0;
    tbuf.c_lflag = 0;
    tbuf.c_cc[VMIN] = 1; /* character-by-character input */
    tbuf.c_cc[VTIME]= 0; /* no delay waiting for characters */
    if (tcsetattr(fd_dev, TCSANOW, &tbuf) < 0) {
        printf("%s: Unable to set device '%s' parameters\n",argv[0], argv[1]);
    if (( fd_dev = open(argv[1], (O_RDWR), 0)) < 0 ) {
        printf("Unable to open tty port specified\n");

    sm = TIOCM_DTR;
    if(ioctl(fd_dev, TIOCMBIS, &sm) == -1) {
        printf("Unable to set modem control lines\n");

    read(fd_dev, &buf, 1);
    printf("%02x\n", buf);


An Application

This is a description of the author's use of the Qtronix serial keypad.

One of my PCs boots from a SanDisk flash disk into OpenDOS and then into loadlin and Linux. The root file system is on a RAM disk. There are no fans on the CPU or power supply so the computer has no moving parts. This machine is meant to be less a PC and more an appliance. It has a modem, printer, Palm Pilot cradle, and a text-to-speech board, as well as the CD-writer and other I/O devices. It does not have a monitor or keyboard.

The serial keypad is used to set-up ('7') and tear-down ('8') a PPP link to my ISP. If "NumLock" is on, the command about to be executed is spoken by the text-to-speech board. The '4' key is used to speak the time.

The script file
# A script to read a Qtronix serial keypad and
# execute commands based on the key pressed.
# 'NumLock' usually implies a spoken response

while  true
    # Sleep waiting for a keypress
    KEY=`./keypad /dev/ttyS4`

    case $KEY in
      85 | 97 )    # Either '4' or 'NumLock 4' 
        speak `date +%k%t%M`
      88)    # Both '5' and 'NumLock 5' 
        speak `/usr/local/bin/temperature` degrees
      9c)    # '7' key
        /usr/sbin/dip .aim
      8c)    # 'NumLock 7' key
        speak "Setting up P P P link"
        speak `/usr/sbin/dip .aim`
      99)    # '8' key
        /usr/sbin/dip -k
      87)    # 'NumLock 8' key
        speak "Tearing down P P P link"
        speak `/usr/sbin/dip -k`
        echo $KEY is not implemented