BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Raspberry Pi GPIO pin direct control via virtual pins and Node js

#1

Hello all,

Is there a simpler way to directly control the GPIO pins on a raspberry pi 3 (turn off or on) via virtual pins with Node js?
The code below works but GPIO pins go high on boot up and the pins often go out of sync with my button widgets. direct digital pin control and button widgets work great via On/Off or PIGPIO but I need to use Virtual pins. Any help will be greatly appreciated.

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(14, 'out');  // Pi BCM # 14

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

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

#2

Problem solved ya’ll. Worked great with the following code and pigpio.:grinning:

const Gpio = require('pigpio').Gpio;

const relay = new Gpio(14, {mode: Gpio.OUTPUT});

var button = new blynk.VirtualPin(4);

button.on('write', function(relayValue) {
  relay.digitalWrite(relayValue);
});
0 Likes