I have been working on a project for a Blynk project using a Raspberry Pi Zero W and Python 3. I noticed that there is no support for the LCD Widget. I decided to take a look at the Blynk Library and created a class that can control the LCD Widget.
WidgetLCD.py
# Controls the LCD Widget in the Blynk App
class WidgetLCD():
# Constructor
# Constructor for the Blynk LCD Widget
# Parameters:
# blynk - Blynk object
# vPin - The Virtual pin the LCD is connected to
def __init__(self, blynk, vPin):
self.__blynk = blynk
self.__vPin = vPin
# clear()
# Clears the LCD widget
# Parameters: None
def clear(self):
self.__blynk.virtual_write(self.__vPin, 'clr')
# printlcd(x, y, s)
# Prints a message to the LCD
# Parameters:
# x - x-position of the lcd cursor | range [0, 15]
# y - y-position of the lcd cursor | range [0, 1]
# s - messages to print to the LCD
def printlcd(self, x, y, s):
self.__blynk.virtual_write(self.__vPin, '\0'.join(map(str, ('p', x, y, s))))
Is there any way this could still be contributed to blynk-library-python? To install it I used pip3 install blynk-library-python instead of pip install blynk-library-python in order to make it work with python 3.
Supposedly there is mainly syntax differences between versions?? I think? But what they are I don’t know off hand…
Using Python 2.7 I just added your file into the same folder that my BlynkLib.py is in, and it seems to import without error, but I get this when I run it…
Traceback (most recent call last):
File "/home/gunner/Blynk-Test-Py/PythonTest.py", line 10, in <module>
lcd = WidgetLCD.WidgetLCD(blynk, 5)
NameError: name 'blynk' is not defined
Judging by the traceback message, it looks like you didn’t create a BlynkLib.Blynk object named blynk that the WidgetLCD class needs to function. To do that, all you have to do is declare
Of course you could always name you BlynkLib.Blynk object whatever you want (within python variable name rules). All you would have to do is change the name of the object you pass to WidgetLCD.WidgetLCD().
Here is some example code that I have got to work for both Python 2 and Python 3. This assumes a button attached to Virtual Pin V1 and an LCD in Advanced mode attached to Virtual Pin V0.
@vshymanskyy@Gunner
I have sent a pull request to vshymanskyy/blynk-library-python that contains the code and the example. Unfortunately, I do not know how to use setuptools and could not modify setup.py to accommodate the new file.