digitalWrite not updating output pin

I’m trying to edit the main.cpp file on my Raspberry Pi to control one of the output pins.
I’m using following code to do that.

const int relay=4;

pinMode(relay, OUTPUT);
digitalWrite(relay, HIGH);

As can be seen below, this seems to set GPIO. 7 into output mode correctly, but it is not setting the pin high, which I also tested with a multimeter. I also tried setting it LOW.

Is this a bug? Something I’m doing wrong?

@JeroenG now try:

pinMode(relay, INPUT);
//digitalWrite(relay, HIGH); 

and post another screenshot.

Thanks for your help. Here’s the screenshot.

@JeroenG so it looks like your main.cpp is able to set the mode of output or input correctly.

This suggests you have wiringPi setup correctly and referenced in your main.cpp.

Can you post a copy of your main.cpp.

Have you tried any of the other pins?

I just gave it a try with another pin (BCM 17 which should be GPIO 0 or physical pin 11), but it was the same.

     * @file       main.cpp
     * @author     Volodymyr Shymanskyy
     * @license    This project is released under the MIT License (MIT)
     * @copyright  Copyright (c) 2015 Volodymyr Shymanskyy
     * @date       Mar 2015
     * @brief

    //#define BLYNK_DEBUG
    #define BLYNK_PRINT stdout
    #ifdef RASPBERRY
     #include <BlynkApiWiringPi.h>
     #include <BlynkApiLinux.h>
    #include <BlynkSocket.h>
    #include <BlynkOptionsParser.h>

    static BlynkTransportSocket _blynkTransport;
    BlynkSocket Blynk(_blynkTransport);

    #include <BlynkWidgets.h>

    WidgetLED upLed(V2);
    WidgetLED downLed(V3);
    const int relay=17;  //4

      printf("Got a value V1: %s\n", param[0].asStr());

      printf("Got a value V0: %s\n", param[0].asStr());


    void setup()
      pinMode(relay, OUTPUT);
      digitalWrite(relay, HIGH);

    int main(int argc, char* argv[])
        const char *auth, *serv;
        uint16_t port;
        parse_options(argc, argv, auth, serv, port);

        Blynk.begin(auth, serv, port);

        while(true) {

        return 0;

When I try setting the pins through Python it works fine.

    pi@raspberrypi:~ $ python
    Python 2.7.9 (default, Sep 17 2016, 20:26:04) 
    [GCC 4.9.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import RPi.GPIO as GPIO
    >>> GPIO.setmode(GPIO.BCM)
    >>> GPIO.setup(4, GPIO.OUT)
    >>> GPIO.output(4,1)
    >>> GPIO.output(4,0)

@JeroenG what command are you using to compile main.cpp?

I’m using following command that I found in a Blynk tutorial.
make clean all target=raspberry

@JeroenG just double checked my main.cpp and the pin status is changing. Haven’t put the meter on the pins but I trust wiringPi.

Study my first post in this thread and try the main.cpp included in it Using C++ on a Raspberry Pi with Blynk

Test is with a Zero, haven’t tried my Zero W’s yet but no reason to think it would be any different.

Indeed, the hardware should be very similar.
Thanks for referring to that code. I’ll have a look at it.