Mr.Tr33
Posts: 2
Joined: Thu Oct 08, 2015 4:32 pm

blink(1) mk2 library

Fri Oct 09, 2015 3:59 pm

Hello,

I have a blink(1) mk2 (https://blink1.thingm.com/) and I'm using the pypi library (https://github.com/todbot/blink1/tree/m ... ython/pypi).

I don't know if anyone has a blink(1) mk2 but anyway. Also I'm pretty new to python, but not new to programming languages.

In the documentation there is an example:

Code: Select all

from blink1.blink1 import Blink1
import time

b1 = Blink1()
b1.fade_to_rgb(1000, 64, 64, 64)
time.sleep(3)
b1.fade_to_rgb(1000, 255, 255, 255)
This one works fine.

Code: Select all

from blink1.blink1 import Blink1
import time

b1 = Blink1()
b1.fade_to_color(1000, '#ffffff') # Hexdecimal RGB as a string
b1.fade_to_color(1000, 'green') # Named color - any color name understood by css3
b1.fade_to_color(1000, (22,33,44)) # RGB as a tuple. Luminance values are 0 <= lum <= 255
This one works just for the "green" part.
Here is the error message:

Code: Select all

pi@raspberrypi ~/projects $ sudo python3 test.py
Traceback (most recent call last):
  File "test.py", line 5, in <module>
    b1.fade_to_color(1000, '#ffffff') # Hexdecimal RGB as a string
  File "/usr/local/lib/python3.4/dist-packages/blink1/blink1.py", line 161, in fade_to_color
    red, green, blue = webcolors.name_to_rgb(color)
  File "/usr/local/lib/python3.4/dist-packages/webcolors.py", line 384, in name_to_rgb
    return hex_to_rgb(name_to_hex(name, spec=spec))
  File "/usr/local/lib/python3.4/dist-packages/webcolors.py", line 373, in name_to_hex
    u"'%s' is not defined as a named color in %s." % (name, spec)
ValueError: '#ffffff' is not defined as a named color in css3.
I think that I found the error but I'm not allowed to modify the files through WinSCP.
Is there any way to modify the webcolors.py?

Another "problem" is that the blink(1) mk2 (second version) has two LEDs. Also there is a way to change the color on both LEDs seperetly, but it's not working.

Has anyone a blink(1) mk2 too and can help me?

Sincerely
Mr.Tr33

-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: blink(1) mk2 library

Mon Nov 16, 2015 1:42 pm

Why would you want to modify the webcolors.py - it appears to be a 'system package' and you would normally not modify these...

Also it looks to me the problem is in the blink1.py - it should not be calling webcolors.name_to_rgb() with the string starting with a '#'. This one seems correct to me https://github.com/todbot/blink1/blob/m ... /blink1.py - are you sure you have the latest version of the blink1 package?

In fact this is probably what you have https://github.com/todbot/blink1/blob/6 ... /blink1.py - it appears to only accept the color names. So best to upgrade your blink1 package ('pip3 install blink1 --upgrade').

For the mk2 two led you would need to find a compatible library ...does this not look like it might be there already https://github.com/todbot/blink1/blob/m ... k1.py#L184 ??
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

ghp
Posts: 1518
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: blink(1) mk2 library

Mon Nov 16, 2015 2:53 pm

Hello,
I recently used a blink library based on pyusb. See http://heppg.de/ikg/wordpress/?p=706
There is a description on the commands in their github repository. https://github.com/todbot/blink1/blob/m ... ommands.md
Good luck,
Gerhard

Return to “Python”