The Graphical User Interface (GUI) helps the user to communicate with the system effortlessly. The GUI is considered as the front end of an application. In a Linux operating system each hardware device is represented as a file. The device can be controlled by simply reading and writing into that file. The hardware of an operating system is on the one side and the user trying to access the hardware is on the other side, and in between them there might be several layers of process running which communicates each other using inter process communication methods. The GUI is the process which the user can use to communicate with all these process layers and finally communicate with the Hardware. This project demonstrates how to create a GUI using the QT which can control the LEDs connected to the Raspberrypi board.
The Raspberry pi is a device which uses the Broadcom controller chip which is a SoC (System on Chip). This SoC has the ARM11 processor which runs on 700 MHz at its core. The operating systems like Archlinux ARM, OpenELEC, Pidora, Raspbmc, RISC OS and the Raspbian and also Ubuntu versions are available for the Raspberrypi board. Linux operating systems especially Ubuntu is preferred for all kind of programming and development. The Raspberrypi is a board actually designed for helping computer education for remote schools but it is a nice platform for programmers especially beginners to explore various coding techniques.
This project basically requires two programs which are meant to send data in between them, and a named pipe which will be created by anyone of them. The entire system can be represented with the help of the following diagram:
In the above figure LED_CONTROL is the process which creates the NAMED PIPE and always trying to read data from the pipe. The process LED_GUI is the process which has been created using QT and when it runs, it will create a GUI window with a few buttons corresponding to each LEDs. As the user clicks on those buttons, the GUI writes a corresponding code to the NAMED PIPE.
The functions used in the coding of the LED_CONTROL for creating the NAMED PIPE and for the reading and writing operations are explained in the following section.
mkfifo ()
The function mkfifo() creates a temporary file at the required directory with the required access permissions set on it. The prototype of the function is declared as the following;
int mkfifo ( const char *pathname, mode_t mode );
The first argument is the required pathname of the directory where the named pipe needs to be created. The second argument is the user permission that needs to be set on the file. Using the value 0777 as the second argument allows permission to all users of the system to read from and write into that named pipe. For using this function in the C code, two header files <sys/types.h> and <sys/stat.h> should be included.
mkfifo (“/tmp/my_fifo”, 0777 );
The above function call creates a named pipe called “my_fifo” in the location “/tmp” with access permission to all the users of the system.
open ()
The open () function opens a particular file at a specified path with the required flags set and it returns a file descriptor corresponding to that file to the process which called the open function. Using that file descriptor the process can access the file.
The prototype for the open () function is declared as the following;
int open ( const char *pathname, int flags );
The first argument is the path of the location where the file needs to be opened exists and the second parameter is the flags that need to be set for the file. The flags that set on the file decide the way in which the file can be accessed.
open ( “/tmp/my_fifo”, ( O_RDONLY | O_NONBLOCK ) );
The above function call opens the file named “my_fifo” in the location “/tmp” with the flags set to access the file as Read Only. The function call will returns a small positive integer value called file descriptor using which the process can access the file. The header files needed to be included when using this function is <sys/types.h> and <fcntl.h>.
I am an experienced technical writer with a Master's degree in computer science from BZU Multan University. I have written for various industries, mainly home automation, and engineering. I have a clear and simple writing style and am skilled in using infographics and diagrams. I am a great researcher and is able to present information in a well-organized and logical manner.
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt out if you wish.ACCEPTCheck Privacy Policy
Manage consent
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.