Page 1 of 1

Trouble with Blynk / Raspberry Pi / Python LED Matrix

PostPosted: Thu Jul 25, 2019 12:48 pm
by mw2323
I'm having trouble getting the "displaying text message on dot matrix using blynk app and raspberry pi" code to work ( 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 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:

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
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)
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)
            counter = 3
        if counter == 10:
            counter = 0
        with canvas(virtual) as draw:
            text(draw, (0, 1),'%I:%M'), fill="white", font=proportional(CP437_FONT))
    counter = counter + 1

counter = 0
BlynkText = ''
currentMillis = 0
previousMillis = 0
interval = 5000

    while True:
        currentMillis = millis()
        if currentMillis - previousMillis > interval:
            previousMillis = currentMillis

except KeyboardInterrupt:

Re: Trouble with Blynk / Raspberry Pi / Python LED Matrix

PostPosted: Fri Jul 26, 2019 9:54 am
by Idris
Hi mw2323,

I suspect Blynk already update their library. Can I know what version of Raspbian did you used? I will check again this code and update it on tutorial. This will take some time and I hope you understand. :)


Re: Trouble with Blynk / Raspberry Pi / Python LED Matrix

PostPosted: Fri Aug 02, 2019 11:38 am
by Idris
Hi mw2323,

I just want to update. I already test the code and everything works same as shown in the video. Could you share more details on your setup?


Or maybe you can try to run using python 3. Before that install dot matrix and blynk library for python 3.

sudo -H pip3 install --upgrade luma.led_matrix

sudo pip3 install blynk-library-python