Browse over 10,000 Electronics Projects

Gesture recognition with Raspberry Pi and GestIC

Gesture recognition with Raspberry Pi and GestIC
Use your ← → (arrow) keys to browse

find /usr | grep -i gpio


In figure, highlights the feedback to the command sent; in this case it turns out that it is updated to the latest release. If the library’s release precedes 0.5.11, please update it by means of the following command:


sudo apt-get update

sudo apt-get upgrade


or use the following ones:

sudo apt-get install python-rpi.gpio

sudo apt-get install python3-rpi.gpio

Figura 2sistemata


Now, let’s move onto the configuration of the I2C peripheral, made available by Raspberry Pi; let’s proceed with the installation of the Python “smbus” Python library for the management of the I2C bus:


sudo apt-get install python-smbus


to be followed by the I2C tools:


sudo apt-get install i2c-tools


We will then have to enable the I2C bus support on the part of the kernel; to do so it is needed to recall the configuration window, by typing in the following command:


sudo raspi-config


As it can be seen in figure, let’s select the “Advanced Options” entry, and then:

in the new screen, let’s select the “A7 I2C Enable/Disable automatic loading” entry, as in figure;


Figura 4sistemata


in the following screens, we will have to answer, in sequence: “Yes”, “Ok”,  “Yes” and finally “Ok” again;

let’s exit the configuration window by choosing the “Finish” entry.

Let’s execute now the system reboot by executing the command:


sudo reboot


Figura 3sistemata


After having rebooted Raspberry Pi, let’s open the “modules” file with a generic text editor, by means of the command:


sudo nano /etc/modules


At this stage we will have to add, if they are missing, the two following lines:





Figura 5sistemata


Finally, it is needed to verify if in your distribution there is the following file:





If so, please open it with a text editor by using the following command:

sudo nano /etc/modprobe.d/raspi-blacklist.conf


and, if they are found, please comment (by using the “#” character) the following instructions:


blacklist spi-bcm2708

blacklist i2c-bcm2708


At this stage, there is nothing else to do but to reboot Raspberry Pi  again, and to verify that the I2C communication is active; to do so please execute the following command:


sudo i2cdetect -y 1


If everything reached a successful ending, the command sent will return a table as the one shown in figure. In practice, the command analyzes the I2C bus, looking for peripherals; and in our case it located the MGC3130 integrated circuit, having 0x42 as address.

The configuration for the I2C hardware and its relative management library is now complete; it is now needed to download and install a Python module that simulates the keyboard buttons pressure, so that it is possible to associate one gesture to a key, for example the function keys: F1, F2, etc.


Figura 6sistemata


The module to be downloaded can be found at the following link:


Please download the .zip file and extract it in a directory: for example “home” or, if you prefer, in a directory purposely created by you.

Among the extracted files you will find one, named “”, that you will need in order to install the module of your distribution and to make it available in Python’s path, so that it may be possible to include it in your own projects.

Thus please type in the following command:


python install


If all the dependences have been verified, the module will be installed and immediately made available, so that it may be integrated in your projects. It may happen, however, that not all the dependences are respected and that there is need to install the additional “pi3d” module, that can be downloaded here.

As for the previous one, please download, unpack and finally install it by typing in the following command:

python install


Finally, it could be needed to install the “xlib” library for Python, that can be installed by means of the following command:

sudo apt-get install python-xlib


Well, once arrived at this stage we have everything we need to introduce and study the management library of the MGC3130 integrated circuit, developed in Python.

MGC3130 and the library for Raspberry Pi

Let’s talk now about the library, written in Python and needed to manage the MGC3130 integrated circuit; it is made along the lines of the one we already presented for Arduino. Let’s start by specifying something on the subject of the data structures management in Python, that are needed to manage the data flow coming from the MGC3130 integrated circuit. In Python, the data structures are built in a way that is slightly different than if they were written in the C programming language: as follows we will thus refer a comparison between the data structure, written in C for Arduino, and the new library, written in Python for Raspberry Pi. As you will remember from the previous episode, the data structure used for Arduino is created in the way shown in Listing 1 next.

Use your ← → (arrow) keys to browse