Raspberry pi Blynk value display in Python (API)

Hello friends. I am doing a simple Blynk project and I seem to have approached a problem which I cannot solve. I am using a raspberry pi, and so far I have managed to create a code which can take input from buttons and sliders. But now I want to be able to do the exact same thing, but this time, get data from the Pi to Blynk. I want to display text on “value display”. But i dont seem to find a solution with regards to python.

For button, I would just do:

led = Blynk(auth_token, pin = “V3”)

Please help me with regards to how can I do the same way and get text from Pi to the Value display. For example, I want to display “0.1” on value display. How to do this? Any help would be appreciated, because all the things I have searched about this cater more towards Arduino users, not raspberry pi users.

Arduino and ESP are the most commonly used devices with Blynk in this forum.

But I am also slowly teaching myself to use the RPI (as Blynk client) with the NodeJS (Javascript) and Python languages.

I find it best to look through the examples on the GitHub page for each applicable language… for example the Python page…

Check out the 02_virtual_read.py and 03_virtual_write.py examples… well check them all out :stuck_out_tongue:

There is a lot of looking at how things were done and then Googling Python commands and experimenting…

Note: The syntax and letter case for Blynk commands is different then Arduino code… for example NO capitalization of blynk or use of the V in a vPin numbering…

For example, I think this should do what you are asking … at least in the most basic of ways…

blynk.virtual_write(3,'0.1') # Send the value 0.1 to a display widget on V3

Well, I tried the one you suggested, but sadly it didnt work. Basically let me explain how I did it.

I did:
led = Blynk(token,pin = “V3”)
ledStatus = led.get_val()

now basically, V3 is a button on Blynk. If I push it, ledStatus becomes 1 and obviously if not, it becomes 0.

When I tried to check the functions associated with this object, I found something called

set_val(self, value,request)

which I figure is the equivalent of the get_val() function. I understand that value would be the text I want to put (ie. “0.1”). But do you know what does the request mean? Like what do you think I should type there?

Where are you getting these commands from?? Where is the rest of your code?

import spidev
from blynkapi import Blynk
import time
import RPi.GPIO as GPIO

GPIO.setup(8, GPIO.OUT)
auth_token = "fc11c09f1xxxxxxxxxxbe52ee70548"
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 976000
mcp = Blynk(auth_token, pin = "V1")
display = Blynk(auth_token, pin = "V2")
led = Blynk(auth_token, pin = "V3")

def write_pot(input):
    msb = input >> 8
    lsb = input & 0xFF
    spi.xfer([msb, lsb])

while True:
    blink = led.get_val()
    if blink[0] == u'1':
	print("inside if statement")
        mcpval =  mcp.get_val()
        mcpval[0] =int(mcpval[0])

so basically this is the code of my project. These are python commands from the Blynk library. Basically I have a button which i push, and a slider to control its brightness. But now I want to be able to display text on my blynk app. Like when I push the button, it displays a particular text on the value display area. Please help me if you can.

I had to properly format your posted code as required in the Welcome Topic


I also blanked out part of your AUTH code so that others will not try to control your stuff :stuck_out_tongue:

I don’t quite understand what you are doing here… but it doesn’t look correct :face_with_monocle:

Start off with a simple sketch like this (Blynk Button, LED & Display Widgets) and confirm it works, then start adding all your other stuff one piece at a time…

import BlynkLib

BLYNK_AUTH ='xxxxxxxxxx'

# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)

@blynk.VIRTUAL_WRITE(0) # Virtual Button/Switch on V0
def my_write_handler(value):
    if int(value) == 1:
        blynk.virtual_write(1,255) # Turn ON Virtual LED on V1
        blynk.virtual_write(2,'LED is ON') # Send Text to Display on V2
        blynk.virtual_write(1,0) # Surn OFF Virtual LED on V1
        blynk.virtual_write(2,'LED is OFF') # Send Text to Display on V2

# Start Blynk (this call should never return)

Hmmm… I think you are using Blynk differently then the “official” Blynk Python Library method… I am installing and using the Blynk Python Library as shown on the developers GitHub page… You seem to be using some API method??

Yes I am using a blynk api for this. It is different from the code which you suggested. And so far, I have got the button and slider working perfectly with the code I showed. Its only when I want to display on the value display area I am having trouble.

Sorry, but I am totally unfamiliar of that API method for Python.

I can use normal Blynk API commands to control, or get feedback from, the normal Python Library so didn’t even know there was a way like however you are doing it.