I was messing arround with PWM and wiringPi in C++ language, but I found out that there was a better library (might be the most updated) called pigpio. Since I was new to this I was trying to the the blinking test, to test out the functions. Now here is my problem, when I wrote the code to put digital pin to high and right after to low, with a delay in between, the led doesn't blink, it just stays in high value. The other problem I found out is that when I change for() cycle to an interval like for(i=0; i<10; i++) the code is executed like there is no interval, meaning the led should blink atleast 10 times but it doesn't blink even once.

I also tried PWM in that pin and doesn't work because of the problem with the for() cycle being executed instantly.

My code:

/* Libraries */
#include <iostream>
#include <pigpio.h>

/* Variables and Constants */
using namespace std;
#define LED 17
#define HIGH 0x1
#define LOW 0x0
/* Main function */

int main(void)
    cout << "Raspberry Pi initialized!" << endl;
    if (gpioInitialise() < 0) exit(1);

    gpioSetMode(LED, PI_OUTPUT); // 3.3V PIN

    for (;;)
        gpioWrite(LED, HIGH);
        gpioWrite(LED, LOW);



1 Answer 1


gpioDelay(500) is a 500µs pause, so your loop is executing 1000 times a second. The LED will appear to be always on (in effect at half power).

See gpioDelay().

Try gpioDelay(500000) for a half second on half second off blink.

  • Thanks a lot for the help. I'm doing a framework in c++ so I can use the same code in both arduino and raspberry pi 3 robots, and in my mind I was thinking that your gpioDelay() accepted arguments in milliseconds because of the function in the Arduino xD. Nov 28, 2017 at 21:02
  • hi, may I ask you where can I change the name of the functions ? I mean in which files should I look. Thanks in advance. Nov 28, 2017 at 21:58
  • pigpio.c contains the bulk of the code and the prototypes will be in pigpio.h. Rather than renaming the functions it may be more practical to use your own wrappers around the existing functions, e.g. myreadfunc()->gpioRead().
    – joan
    Nov 28, 2017 at 22:05
  • ok, didn't know that I could do that. Thanks for the help. Nov 28, 2017 at 22:13
  • sorry to bother you, but could you give me an example on how to wrapp any function you have or atleast point my in the right direction? I tried your example but it doesn't work, maybe I didn't understand it at all. Nov 28, 2017 at 23:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.