I'm having trouble getting the "displaying text message on dot matrix using blynk app and raspberry pi" code to work (
https://www.youtube.com/watch?v=nkOPYD-P_CE). I managed to get the LED matrix to display the clock when I run the Blynk Python script and the matrix is definitely working and connected properly. I also got the Raspberry Pi to successfully authenticate with the Blynk app (the app tells me when the Pi has been connected). However, the code for returning a message from the app's text input field is not working. It seems like maybe a syntax issue with @blynk.VIRTUAL_WRITE(0) as I get blynklib.py errors pointing back to the script's virtual write for line 167 and line 287, saying "AttributeError: 'NoneType' object has no attribute 'send' ". I have tried another script as well and both scripts return the same error for virtual write operations. The idea is to get text input from the app and display it on the LED matrix. Can anyone point to what my issue might be? Thanks! Code is below:
- CODE: SELECT_ALL_CODE
from gpiozero import LED, Button, Buzzer
import BlynkLib
from time import time, sleep, strftime
from datetime import datetime
import sys
from luma.core.interface.serial import spi, noop
from luma.core.render import canvas
from luma.core.virtual import viewport
from luma.led_matrix.device import max7219
from luma.core.legacy import text, show_message
from luma.core.legacy.font import proportional, CP437_FONT, LCD_FONT
led1 = LED(17)
led2 = LED(18)
led3 = LED(27)
led4 = LED(22)
led5 = LED(25)
led6 = LED(12)
led7 = LED(13)
led8 = LED(19)
sw1 = Button(21)
buzzer = Buzzer(26)
BLYNK_AUTH = 'YourAuthToken'
# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)
# Register Virtual Pins
@blynk.VIRTUAL_WRITE(0)
def my_write_handler(value):
global counter
global BlynkText
buzzer.beep(0.1, 0.1, 1)
BlynkText = format(value[0])
print('Blynk Text: {}'.format(BlynkText))
counter = 1
serial = spi(port=0, device=0, gpio=noop())
device = max7219(serial, width=32, height=8, block_orientation=-90)
device.contrast(5)
virtual = viewport(device, width=32, height=8)
def millis():
return time() * 1000
def my_user_task():
global counter
global BlynkText
print('Counter = {}'.format(counter))
if counter == 0:
buzzer.beep(0.1, 0.1, 2)
show_message(device, 'Blynk Ready', fill="white", font=proportional(LCD_FONT), scroll_delay=0.05)
counter = 3
elif counter < 4:
if len(BlynkText) > 0:
show_message(device, BlynkText, fill="white", font=proportional(LCD_FONT), scroll_delay=0.08)
else:
counter = 3
else:
if counter == 10:
counter = 0
with canvas(virtual) as draw:
text(draw, (0, 1), datetime.now().strftime('%I:%M'), fill="white", font=proportional(CP437_FONT))
counter = counter + 1
counter = 0
BlynkText = ''
currentMillis = 0
previousMillis = 0
interval = 5000
try:
while True:
blynk.run()
currentMillis = millis()
if currentMillis - previousMillis > interval:
my_user_task()
previousMillis = currentMillis
except KeyboardInterrupt:
sys.exit(0)