www.NewsDownload.co.uk Page 14

Raspberry Pi GPIO Keypad Driver

2012-12-05 11:54 By Jason Birch

A generic GPIO keypad driver for Linux on the Raspberry Pi, to allow macro strings, key presses, scrolling, pointer movement, pointer clicks and other operations.

License
The package contains a license file, read the license file before use.

Driver
Linux driver for a Microsoft XBox ChatPad, PSP Joystick, or a keypad of switches connected to the GPIO pins of a Raspberry Pi computer. The driver is configurable to allow each switch to be assigned a function. Functions can be text macros, key-presses, character selection, horizontal and vertical scrolling, pointer movement, mouse clicks and other operations. LED indicators can be used to display the currently selected keypad mode.

Details of how to make the XBox ChatPad hardware can be found here.

Details of how to make the PSP Joystick hardware can be found here.

Details of how to make the switch hardware can be found here.

The driver has been tested with terminal mode, LXDE on Raspbian and Window Maker on Arch Linux. It simulates keyboard and mouse operations and is intended to be configured and used with various applications running under the Linux Kernel.

The following files are distributed in the package:

README.txt            - Information about the package.
License.txt           - User license agreement.
License.dat           - License file.
RemoteKeypad          - Linux driver application.
RemoteKeypad.ini      - Driver configuration file.
install.sh            - Install script.
uninstall.sh          - Uninstall script.
RemoteKeypadDriver.sh - Driver start-up script.


Configure
The package comes with the configuration file set to use all available GPIO pins, PSP Joystick and an XBox ChatPad. The configuration file can be edited in a text editor. Lines in the configuration file beginning with a # character are comment lines.

The configuration file can be modified while the driver is in use, and the driver will automatically read the configuration file if it is altered. Only save a complete configuration file and never save a partially modified configuration file.

If you are not using an XBox ChatPad you can disable it in the configuration file by setting the value for ENABLE_XBOX_CHATPAD to FALSE. The ChatPad uses pins 14 and 15 as a UART device.

If you are using an XBox ChatPad it is very important that the system clock is set to it's default value of 250MHz in the /boot/config.txt file, in order for the UART baud rate to be set correctly. Do this by specifically setting the value to 250, or omitting the setting from the /boot/config.txt file.

If you are not using a PSP Joystick you can disable it in the configuration file by setting the value for ENABLE_ANALOG_JOYSTICK to FALSE. The Joystick uses pins 7, 8, 9, 10, 11 as an SPI device.

There are two example settings in the configuration file. One to use as an absolute device for example as a joystick in MAME, and one as a relative device for example a pointer mover in X Windows.

If you are using the PSP Joystick, the first time the driver is started it will automatically calibrate the joystick. To calibrate the joystick, ensure the joystick is centered when the driver is started. Then after the driver is started, rotate the joystick to it's extremes several times clockwise and then several times anti clockwise. Then stop the driver by pressing Ctrl+C or removing the running.dat file. The driver will have created a joystick.cal file which it will use each time the driver is started from now on. If you ever want to re-calibrate the joystick just remove the joystick.cal file and use the same process again. The joystick should only need to be re-calibrated if the joystick is replaced or if the joystick wasn't centered properly at the start of the calibration process.

The sensitivity of the joystick can be adjusted by altering the maximum scale for the joystick axis: ANALOG_JOYSTICK_-X_?, ANALOG_JOYSTICK_+X_?, ANALOG_JOYSTICK_-Y_?, ANALOG_JOYSTICK_+Y_?
And the dead area in the center of the joystick: ANALOG_JOYSTICK_CENTER_?

If you want some of the GPIO pins for other uses, rename the required pins to the value -1 in the setting GPIO_PINS and MODE_INDICATOR_GPIO_PINS. The values should not be removed from this setting, as the order and position of each value represents the key number, used later in the configuration file. The order of the lines in the configuration file should not be altered either for the same reason.

No lines should be removed or commented from the configuration file. The operation of any of the keys can be altered by changing the value of any of the KEY_? settings. There are examples of settings at the end of the configuration file.

VIDEO OF XBOX CHATPAD SUPPORT


CALIBRATING FOUR PSP JOYSTICKS


VIDEO OF GPIO SWITCH SUPPORT


Install
Copy the driver software to the Raspberry Pi from a remote computer, or download the driver directly onto the Raspberry Pi from a web browser:
scp RemoteKeypadDriver.tar.gz \
root@[IP_ADDRESS]:/root/

Login to the Raspberry Pi, either locally or remotely:
ssh root@[IP_ADDRESS]

Unpack the driver:
tar -xf RemoteKeypadDriver.tar.gz

Run the install script:
cd /root/RemoteKeypadDriver/
chmod +x install.sh
./install.sh

If joystick(s) are configured, run the driver now manually to calibrate the joystick(s). Press Ctrl+C to complete the calibration process.
NOTE: After the calibration process on the Pixel OS there is an issue with the terminal, just close the terminal and it will be OK.
./RemoteKeypad

Reboot the Raspberry Pi to activate the driver:
reboot

Uninstall
Run the uninstall script:
cd /root/RemoteKeypadDriver/
chmod +x uninstall.sh
./uninstall.sh

Operation
To lock shift, circle, square or MSN mode press the mode key twice. MSN mode has special features:
1 - ALT + F1 (In terminal select terminal 1).
2 - ALT + F1 (In terminal select terminal 2).
3 - ALT + F1 (In terminal select terminal 3).
4 - ALT + F1 (In terminal select terminal 4).
5 - ALT + F1 (In terminal select terminal 5).
Z - CRTL + Z (In terminal suspend process).
C - CRTL + C (In terminal terminate process).
S - CRTL + S (Save).
A - CRTL + A (Select all).
X - CRTL + X (Cut).
C - CRTL + C (Copy).
V - CRTL + V (Paste).
Q - Scroll Up.
W - Scroll Down.
E - Scroll Left.
R - Scroll Right.
6 - Left Click.
7 - Middle Click.
8 - Right Click.
Y - Pointer up left.
U - Pointer up.
I - Pointer up right.
H - Left.
K - Right.
B - Pointer down left.
N - Pointer down.
M - Pointer down right.

Download
V1.00 2012-12-05 - Support for GPIO switches.
V1.01 2012-12-20 - Added support for XBox ChatPad.
V1.02 2012-12-24 - Added support for Key Lock Mode
                   indicators. Improved stability for
                   Chatpad support.
V1.03 2013-03-31 - Added support for PSP Analog Joystick.
V1.04 2015-08-30 - Timing configuration in INI file.
V1.05 2016-09-30 - Fixed ChatPad key swamp issue.
                   Added display for calibration.
                   Raspberry Pi 2, 3, Zero compatible.
V1.06 2016-10-03 - Added support for MCP3004, MCP3008.
                   Up to four analog joysticks.
                   Updated calibration display.
V1.07 2016-10-10 - Pi Zero Compatibility Fixed.
V1.08 2017-01-07 - New Pixel OS Compatibility Fixed.

Tested
 Raspberry Pi (Original)
 Raspberry Pi 2
 Raspberry Pi 3
 Raspberry Pi Zero

Download the driver package here.

Loading...