Raspberry Node.js Virtual Pin reboot state

var Blynk = require('blynk-library');
var AUTH = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxpm2 ';
var blynk = new Blynk.Blynk(AUTH, options = {
 connector : new Blynk.TcpClient()
});
var Gpio = require('onoff').Gpio,
  relay = new Gpio(23, 'out');  // Pi BCM # 23

var v2 = new blynk.VirtualPin(2);  // virtual pin to control GPIO 23

v2.on('write', function() {
        if(relay.readSync() == 0) {  // toggle gpio 23 from high to low
                relay.writeSync(1);
        }
        else {
                relay.writeSync(0);
        }
});

When i use above code everything is ok,but when i restart Rpi and after Blynk connect to cloud my relay state go HIGH…can this behavior change to LOW?

That is more due to the nature of the device, musch like as on ESP… but you can try adding in a sync command to reset it upon boot to whatever last server value was.

blynk.on('connect', function() {
  console.log("Blynk ready.");
  //blynk.syncAll();
  blynk.syncVirtual(2);
});

I try this…go HIGH for moment and then LOW…i need to avoid that moment :slight_smile:

I guess you can ask on the RPi forum if there is any way of changing the nature of the hardware…

Change to a different GPIO, add additional PULL DOWN resistors, wire your relay differently, perhaps add in a capacitor/resistor to the pin output that might smooth out the brief bump without triggering the relay, etc.

Basically I don’t see this as a Blynk related issue… hardware does what it is built to do, and some GPIOs boot or pulse HIGH.

How you then explain that when i use plain digital pin(gpio) (NO VIRTUAL) state is LOW?
And is LOW on ANY GPIO.

Possibly due to how you have coded it? It is not my code :wink: so I haven’t really tried to figure out what you are doing or why you are doing it that way ;)… I was just explaining that sometimes GPIO pins boot high… if that is not your case, then it is your code.

I would toggle the pin this way (untested)

v2.on('write', function(param) {
        if (param == 1) {  // If Button HIGH
                relay.write(1);
        }
        else if (param == 0) {  // If Button LOW
                relay.write(0);
        }
});

Thanks @Gunner but still the same…when i reboot pin goes HIGH :frowning:

Read the link to the RPi site… it just may be the way it is??

As per that link… According to page 102 of this document, GPIO23 is pulled LOW… does your relay trigger on a LOW or a HIGH signal?

Yes i read already…but if that is the case,i dont understand why is hapening only when i try VIRTUAL pin…
My relay is trigering on a HIGH signal (i have led indicator)

Well, first off the Virtual pin has NO direct effect on the device. So, perhaps your relay = new Gpio(23, 'out'); // Pi BCM # 23 is doing something??

Or how your GPIO library works?

There are also other variations of GPIO control libraries to experiment with… I am using pigpio