Trouble with Blynk / Raspberry Pi / Python LED Matrix

Please feedback the issue encountered while using Cytron official website (http://www.cytron.com.my), Cytron Technical Forum and Cytron Tutorial site (http://tutorial.cytron.com.my) here. We greatly appreciate any comments and suggestions too.

Trouble with Blynk / Raspberry Pi / Python LED Matrix

Postby mw2323 » Thu Jul 25, 2019 12:48 pm

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)
mw2323
Fledgling
 
Posts: 1
Joined: Thu Jul 25, 2019 12:40 pm

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

Postby Idris » Fri Jul 26, 2019 9:54 am

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. :)

Thanks.
Cytron Technologies invest time and resources providing tutorial, training and support for STEM education and maker movement. We need your support by purchasing products from Cytron Technologies. Thanks.
http://www.cytron.com.my
User avatar
Idris
Moderator
 
Posts: 409
Joined: Thu Mar 22, 2012 5:28 pm
Location: Pulau Pinang

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

Postby Idris » Fri Aug 02, 2019 11:38 am

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?

IMG_4134.jpg

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

CODE: SELECT_ALL_CODE
sudo -H pip3 install --upgrade luma.led_matrix

CODE: SELECT_ALL_CODE
sudo pip3 install blynk-library-python

Thanks.
Cytron Technologies invest time and resources providing tutorial, training and support for STEM education and maker movement. We need your support by purchasing products from Cytron Technologies. Thanks.
http://www.cytron.com.my
User avatar
Idris
Moderator
 
Posts: 409
Joined: Thu Mar 22, 2012 5:28 pm
Location: Pulau Pinang


Return to Cytron Website, Forum & Tutorial Site Feedback

Who is online

Users browsing this forum: No registered users and 2 guests

cron