Using pigpiod

The pigpio library described earlier (see Using pigpio) can be launched and used as a daemon.

Usage

To launch the daemon, use the following command:

ubuntu@rpi:~$ sudo pigpiod

To stop the daemon, stop the previous process:

ubuntu@rpi:~$ sudo killall pigpiod

To interface with pigpiod you need to use a different set of functions, declared in pigpiod_if2.h.

To compile code that interfaces with pigpiod, link with libpigpiod_if2 instead of libpigpio, as follows:

gcc -Wall -pthread -o io1212-4 io1212-4.c -lpigpiod_if2 -lrt

Example 2: Using inputs

An example of how to read an input using gpio_read() can be tested by substituting lines 81-89 above with the following snippet.

   int count = 20;
   int state = gpio_read(pi, Input_1);
   
   while(count) {
        while(state == gpio_read(pi, Input_1));
        state = gpio_read(pi, Input_1);
        gpio_write(pi, Output_1, state);
        sleep(1);
        count--;
   }

   gpio_write(pi, Output_1, 0);