In a Linux operating system all 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 applications running which communicates each other using inter process communication methods. This project demonstrates how to control a process which can turn on and off the LEDs of the Raspberrypi with the help of another process by writing into a pipe file.
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:
Fig. 2: Block Diagram Of LED Control Using Pipe File
Project Source Code
####include <bcm2835.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <string.h>
#define OUT_PIN1 RPI_GPIO_P1_15
#define OUT_PIN2 RPI_V2_GPIO_P1_13
#define OUT_PIN3 RPI_GPIO_P1_12
#define OUT_PIN4 RPI_GPIO_P1_11
#define OUR_INPUT_FIFO_NAME "/tmp/my_fifo"
void set_pins_output ( void );
void set_output_pins_low ( void );
unsigned char rx_buffer [ 256 ];
int our_input_fifo_filestream = -1;
int main ()
result = mkfifo ( OUR_INPUT_FIFO_NAME, 0777 );
our_input_fifo_filestream = open ( OUR_INPUT_FIFO_NAME, ( O_RDONLY | O_NONBLOCK ) );
while ( 1 )
rx_length = read ( our_input_fifo_filestream, ( void* ) rx_buffer, 255 );
if ( rx_length > 0 )
rx_buffer [ rx_length ] = '