blinkstick-python icon indicating copy to clipboard operation
blinkstick-python copied to clipboard

Can't get BlinkStickProMatrix to work

Open dz46 opened this issue 9 years ago • 5 comments

When I'm trying to execute the following code, I got from the documentation:

matrix = blinkstick.BlinkStickProMatrix(4,4)
matrix.set_color(x=1, y=1, r=255, g=0, b=0)
matrix.send_data_all()

I only get this:Exception: 'NoneType' object has no attribute 'set_led_data'

Could you please give me a hint on this?

Thanks in advance

dz46 avatar Oct 08 '16 18:10 dz46

It seems to be a bug in the blinkstick.py. Tested with python 2.7.10 and 2.7.11 under Xubuntu and Win10. Always the same issue.

p0ke234 avatar Oct 09 '16 20:10 p0ke234

Could you please test this example: It does not seem to be a bug in the lib but an error in the description:

import time
import math
import colorsys
from random import randint

from blinkstick import blinkstick

class Main(blinkstick.BlinkStickProMatrix):
    def run(self):
        self.send_data_all()

        red = randint(0, 255)
        green = randint(0, 255)
        blue = randint(0, 255)

        x = 0
        sign = 1
        try:
            while True:
                self.bstick.set_color(0, x, red, green, blue)
                time.sleep(0.02)
                self.bstick.set_color(0, x, 0, 0, 0)
                time.sleep(0.004)

                x += sign
                if x == self.r_led_count - 1:
                    sign = -1
                    red = randint(0, 255)
                    green = randint(0, 255)
                    blue = randint(0, 255)

                elif x == 0:
                    sign = 1


        except KeyboardInterrupt:
            self.off()
            return

# Change the number of LEDs for r_led_count
main = Main(r_columns=4, r_rows=4, delay=0.002, max_rgb_value=255)
if main.connect():
    main.run()
else:
    print "No BlinkSticks found"

Please let me know if this will work for you.

p0ke234 avatar Oct 12 '16 19:10 p0ke234

HI,

this is working technically working. But I was looking for a solution to

  1. set all the pixels in the framebuffer and then
  2. send them out at one ( as described in the documenation:
    Then you can set the internal framebuffer by using {set_color} command:
        >>> matrix.set_color(x=10, y=5, r=255, g=0, b=0)
    And send data to both matrices in one go:
        >>> matrix.send_data_all()

Because how each set_color will instantly set the color of the pixel, but as there are 16 in my case you can clearly see, that they are being changed one after another.

Maybe to be more clear what I'm trying to archive: Call the script from comandline, with a png as param (or more) and it'll display it..

import png
import time
import sys 
import array 
from blinkstick import blinkstick

class Main(blinkstick.BlinkStickPro):

    def run(self):
        param = sys.argv
        param.pop(0)
        if(len(param) == 0):
            print "Please supply one or more filenames"
            return "false"

        filenames = param

        #Map Pixel in PNG to the Pixel on the Display (for Multiline)
        #Weird sequence because of the zig-zag wirering on the board
        mapping = array.array("B", [0,1,2,3,7,6,5,4,8,9,10,11,15,14,13,12])
        self.send_data_all()
        try:
            # For all given Filenames
            for (i, filename) in enumerate(filenames):
                reader = png.Reader(filename=filename)
                pixelid = 0

                w, h, pixels, metadata = reader.read()

                for elem in pixels:
                    #print "New row"
                    #print elem
                    #How grep each rgb tripple
                    for x in range(0, w):
                        r = elem[x*3+0]
                        g = elem[x*3+1]
                        b = elem[x*3+2]

                        #Set the Pixel
                        # Devide rgb-value by 10 to make it not that bright
                        self.bstick.set_color(0, mapping[pixelid], r/10, g/10, b/10)
                        pixelid = pixelid + 1;

                #Sleep untill moving to the next file.
                time.sleep(0.75)

        except KeyboardInterrupt:
            self.off()
            return

main = Main()
if main.connect():
    main.run()
else:
    print "No BlinkSticks found"

Demo PNGs (since 4x4 pretty small) s t v w

Thanks for your help in advance. dz46

dz46 avatar Oct 13 '16 05:10 dz46

Hey, your project looks very nice. I hope I have time to take a deeper look into it later. But if I´m really with you, the set_led_data() command could be right for you: https://forums.blinkstick.com/t/blinkstick-flex-ambilight/292/36

Btw, the BlinkStick forum is a good place for getting some help and publishing own projects (If you don´t know yet). Edit: A better link directly to the set_led_data() post: https://forums.blinkstick.com/t/blinkstick-flex-ambilight/292/37?u=p0ke

p0ke234 avatar Oct 13 '16 06:10 p0ke234

Been a while since I looked into this part of code. Sorting this out in a bit!

arvydas avatar Oct 13 '16 08:10 arvydas