[SOLVED] Raspberry Pi 3 & Python (and NodeJS)

Anybody have the simple steps required to load Blynk on a Raspberry Pi 3? Im following older instructions and finding problems with loading npn etc.

Also being a complete novice in using the command line, like Pixel when possible.

Also anybody used it with Python 2.7? Would like simple examples to build on, perhaps just setting variable in Python to start with.



Hello. Did you check video - https://www.youtube.com/watch?v=LJ3ic8C8CcA? It also has all required links.

doesn’t this article work for you?

The article worked followed it and now have V1 toggling, big step forward for me (not an expert) Thanks.

Firstly I’m new to Pi’s and Blynk. The notes I followed helped me install node etc and I now have the blynk button switching V1: 0 /1.

I now need to understand more about the Virtual and Digital pins, how I program these to work with existing Python program on the Raspberry Pi.

I would prefer to get instructions into my Python code where I can program them into my project.

Any ideas


If you look for python implementation - there is one, but it’s early beta version (use forum search). It’s more reliable to use node.js and then call your python scripts from JS.

I think I asked the question incorrectly.

I have a large Python program that controls hot water generation and I wish to add a sleep command using Blynk.

Idea, using what I have written so far with js to toggle V1, now looking to pick up the virtual pin in the my Python Code.

Any examples?


I think it’s the connection between the virtual pin and the gpio that I am missing. The example js code I was sent and is working toggles v0 v1 on the screen but does not switch j
I assume that following switching gpio’s I can pick this up on my Python code, am I correct thinking that I can look at the gpio in Python and see the virtual pin change?

I know nothing about Python, and very little about JS, however this is my test script that has both virtual and physical buttons & LED control, and even starts a simple linux command (ifconfig) on the CLI with a virtual button press.

Perhaps you can get something out of its structure?

var Gpio = require('onoff').Gpio;  // links variable 'Gpio' to the all important onoff GPIO control library
var Blynk = require('blynk-library');  // Links variable 'Blynk' to the Blynk Library
var AUTH = 'cda957435ce44407bed2e9283c95018f';  // My top secret auth code... useless to anyone on the cloud ;P
var blynk = new Blynk.Blynk(AUTH, options = { connector : new Blynk.TcpClient( options = { addr: "", port: 8442 } ) });
var process = require('child_process'); // Allows this script to run CLI commands? Used in the "run the command ifconfig" function
var LEDintensity = 255;

var v1 = new blynk.VirtualPin(1);  // Setup Button Widget on V1 with variable 'v1'
var v4 = new blynk.VirtualPin(4);  // Setup Slider Widget on V4 with variable 'v4'
var v5 = new blynk.VirtualPin(5);  // Setup Button Widget on V5 with variable 'v5'
var v6 = new blynk.VirtualPin(6);  // Setup Display Widget on V6 with variable 'v6'
var v9 = new blynk.VirtualPin(9);  // Setup Display Widget on V9 with variable 'v9'
var v10 = new blynk.VirtualPin(10);  // Setup LED Widget on V10 with variable 'v10'

v1.on('write', function(param) {  // Watches for V1 Button
  console.log('V1:', param[0]);  // prints value to CLI
  if (param == 0) {
    blynk.virtualWrite(10, 0);  // V10 Widget (ORANGE) LED OFF
  } else if (param == 1) {
    blynk.virtualWrite(10, LEDintensity);  // V10 Widget (ORANGE) LED ON

// Vary the intensity or orange LED
v4.on('write', function(param) {  // Watches for V4 Slider
LEDintensity = param;
console.log(LEDintensity);  // prints value to CLI
blynk.syncVirtual(1);  // Runs the button funtion to update the LED

v4.on('read', function() {  // I don't understand why this says read??
  v6.write(LEDintensity);  // but this sends the seconds 0-59 to the Display Widget

// Run the command "ifconfig"
v5.on('write', function(param) {  // Watches for V5 Button
  console.log('V5:', param[0]);  // prints value to CLI
  if (param == 1) {  // Runs the CLI command ifconfig if the button on V5 is pressed
    process.exec('ifconfig', function (err, stdout, stderr) {
      if (err) {
        console.log("\n" + stderr);
      } else {

v9.on('read', function() {  // I don't understand why this says read??
  v9.write(new Date().getSeconds());  // but this sends the seconds 0-59 to the Display Widget

led = new Gpio(18, 'out'),  // Sets up the BCM pin 18 as an output for the LED and assigns it to variable "led"
button = new Gpio(25, 'in', 'both');  // Sets up the BCM pin 25 as an input registering both rising and falling for the variable "button"

button.watch(function (err, value) {  // Watches for button press and assigns 0/1 to value
  if (err) {
    throw err;  // Some form of error handling
  led.writeSync(value);  // Sends value (0/1) to Physical LED
  if (value  == 0) {
    blynk.virtualWrite(2, 0);  // V2 Widget (BLUE) LED off
    blynk.virtualWrite(3, 255);  // V3 Widget (RED) LED on
  }   else if (value == 1) {
    blynk.virtualWrite(2, 255);  // V2 (BLUE) Widget LED on
    blynk.virtualWrite(3, 0);  // V3 (RED) Widget LED off

Thanks for the JS script, i will try to sort out what would fit my needs. My knowledge of JS is the same as yours. What would make my life far easier is a simple Blynk JS script that switches a GPIO on when I push the button. A bonus would be a feed back signal to acknowledge the on signal to the GPIO. Must run on Raspberry Pi 3. Thanks

Hmm, in hindsight… in my above example I was using direct GPIO pin referencing on the Button Widget, and that toggled the physical LED because of this simple “pinmode” setup:

led = new Gpio(18, 'out'),  // Sets up the BCM pin 18 as an output for the LED and assigns it to variable "led"

Here is the Project QR as it might just be easier for you to figure it out in operation.

Problem solved. It was lack of knowledge about the use of virtual and digital pins. I was confused as there seemed to be lack of information on the web re Blynk and Raspbery Pi or people assumed that you were not a complete novice. It didn’t help that I did not recognise the GP abbreviation for GPIO on the app.

A “U Tube” video explained that using Digital pins you assigned a GPIO pin.

Somehow all my looking to date always included JS. Now works a treat without a line of JS code.

So simply using the direct pin control from the Widget?.. what about Python, did you get Blynk to work with it?

Yes, I put a couple of lines in my Python code to check for the GPIO pin going high. I’ll have to make that into a function and call it when required. Means I can put my application into sleep mode using the Blynk button when I’m away from the house.

Well when you get something demonstrable, feel free to post the code here… adds to the collection of differing code type examples :wink:

Gunner, thanks for your sample script. it was able to get me past the hump i had been in.

much appreciated !

You are welcome… I have a bit more NodeJS stuff here… Slowly working on Python…