Introduction: A Piano With Banana As Keyboard Powered by PcDuino

In this tutorial we will detail how to use Touch key USB Shield and pcDuino to implement a piano with banana as keyboard.

Step 1: How to Simulate Keyboard Input

(1) In order to inject keystrokes, we need to map the touch events from banana to standard keystrokes event, such as KEY_0, KEY_Z, etc, which corresponds to keystrokes from 0-9, X_Z. More specifically, we need to use a file ‘/dev/input/event/X’, and write a data structure named input_event to it to inject a certain keystroke. To find out all the input devices, we can use the following command: $cat /proc/bus/input/devices. We found out that in our case, event1 is the keyboard.

(2) Now that we found out the input file, we need to write the data structure input_event to it. The event is defined in /usr/include/linux/input.h. We need to fill it with the keystroke we want to inject. The structure is defined as following: struct input_event {

struct timeval time;

__u16 type;

__u16 code;

__s32 value;

}

type: The type of event.

EV_KEY: the keystroke event, for example, which key is pressed in keyboard, and if left button or right button of the mouse is pressed.

EV_REL: The relative coordinates, which mainly refers to the movement of mouse

EV_ABS: absolute coordinates, which mainly refers to the touch screen.

code: the code of event. If the type is EV_KEY, the code is the key code. Code 0-127 refers to the key of keyboard. Code 0x110-0x116 refers to the press code of the mouse, where 0x110 (BTM_LEFT) means the left button of the mouse, 0x111 (BTN_RIGHT) means the right button of the mouse, 0x112 (BTN_MIDDLE) means the middle button of the mouse. For other code, please refer to file “/usr/include/linux /input.h”.

Value: the value of the event. When the type is EV_KEY, when the key is pressed down, the value is 1, and 0 when it is released. If the type is EV_REL, the positive and negative value means the relative movement in two different directions.

Makey Makey use USB-HID to simulate keyboard event to the host PC. In pcDuino, scratch is running itself on pcDuino, so we can directly inject keystroke.

Step 2: Hardware Setup

Hardware List:

  • 1 x pcDuino
  • 1x Touch keyUSB shield
  • Several clamp wires
  • 5 bananas
  • If your monitor doesn’t have speakers, you will also need a usb sound card and a speaker (or headset).
  • In case you want to use USB sound card, you must modify the pcDunio audio output device.

Check the sound card of pcDuino:

ubuntu@ubuntu:~$ aplay -l
**** List of PLAYBACK Hardware Devices **** card 0: Device [Generic USB Audio Device], device 0: USB Audio [USB Audio]

Subdevices: 0/1

Subdevice #0: subdevice #0

card 1: sun4isndhdmi [sun4i-sndhdmi], device 0: SUN4I-HDMIAUDIO sndhdmi-0 []

Subdevices: 1/1

Subdevice #0: subdevice #0

From the above message you can see my pcDuino has two sound cards.
Note: You need to power on pcDuino with USB sound card installed in order for pcDuino to load the sound card drive automatically.

Configure pcDuino to use the usb sound card as sound card:

$vim /etc/asound.conf
default.pcm.card 0

default.pcm.device 0

default.ctl.card 0

Reboot pcDuino by using:
$ sudo reboot

Check the code from the original link(http://learn.linksprite.com/pcduino/arduino-ish-program/adc/pcduino-banana-piano/)