A Piano With Banana As Keyboard Powered by PcDuino

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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: 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 0×110-0×116 refers to the press code of the mouse, where 0×110 (BTM_LEFT) means the left button of the mouse, 0×111 (BTN_RIGHT) means the right button of the mouse, 0×112 (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: Step 2: Hardware Setup

Hardware List:

  1. 1 x pcDuino
  2. 1x Touch keyUSB shield
  3. Several clamp wires
  4. 5 bananas
  5. If your monitor doesn’t have speakers, you will also need a usb sound card and a speaker (or headset).
  6. 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

Step 3: Step 3: Sample Code Used to Make Banana As Keyboard

Step 4: Step 4: Test and Run

Install scratch:

 $sudo apt-get install pcduino-scratch

The scratch project can be downloaded here. (banana_piano).

  • Run the code (the sample code from previous section) used to make banana as keyboard.
  • Run the the banana project in scratch.
  • Enjoy!

Step 5: Customer Support

Support Fourm:


Support mail:


Be the First to Share


    • LED Strip Speed Challenge

      LED Strip Speed Challenge
    • Sculpting Challenge

      Sculpting Challenge
    • Clocks Contest

      Clocks Contest