Demo for a working pipixel code?

I admit it, I seem to be a bit thick in my head, I think I have followed the install docs to get everything installed that is needed to get PiPixel working on a Pi Zero W.

I guess what I am still having problems with is all the definitions that might be clear to someone working day in day out in Python, unfortunately, that’s not me.

The following is a code that I tested to work with AllPixel, but now I want that to work with PiPixel. The changes I made are obviously incorrect, how should it look like?

from bibliopixel.drivers.neopixel import *

driver = neopixel(num = 8*8, ledtype = LEDTYPE.WS2812B, c_order='GRB')

#import the bibliopixel base classes
from bibliopixel import *
from bibliopixel.animation import *

import sys

class BasicAnimTest(BaseStripAnim):
    def __init__(self, led):
        super(BasicAnimTest, self).__init__(led)
        #do any initialization here
        self.index = 0
        self.oldindex = -1
        self.NUM_LEDS = 8*8
        self.gHue = 0

    def step(self, amt=1):
        self._led.set(self.index, colors.hue2rgb((self.gHue)%256))
        if self.oldindex > -1:
            self._led.set(self.oldindex, colors.Black)
        self.oldindex = self.index
        self.index += 1
        if self.index >= self.NUM_LEDS:
            self.index = 0
        self.gHue += 1
        if self.gHue > 255:
            self.gHue = 0


#Now try with Strip
led = Matrix(driver, width=8, height=8)
led.set_brightness(10)

try:
    anim = BasicAnimTest(led)
    anim.run(fps=60)

except:
    e = sys.exc_info()[0]
    print('Error:', e)

It should be:

from bibliopixel.drivers.PiWS281X import PiWS281X
driver  = PiWS281X(num=8*8, c_order='GRB')

I’ll add a demo script - honestly not sure how there isn’t one. I swear there used to be. But none of those docs have really had to change in quite a long time so I don’t really remember.

AND it works! Thank you Adam.

May I suggest another jumper for a future version of the PiPixel? It would be terrific if I could immediately power the Pi Zero from the barrel connecter or the block terminators. I can solder that wire myself, but it would be terrific to have that option directly on a jumper header.

Or is there something that speaks against that, something I have not yet considered?

Add on: While the solution works there still seems to be something wrong and the output is not very helpful. Here is the output of the code above once it is running:

it works for a while and then out of the blue the error below appears. Something that I have not had with the AllPixel version.


pi@pipixel:~/bp $ sudo python3 t1.py

WARNING - deprecated - BaseAnimation.run

WARNING - adaptor - Animation BasicAnimTest expects a layout of type Strip but layout is of type Matrix:

you might get unpredictable results.

WARNING - animation_threading - Frame-time of 16ms set, but took 28ms

Error: <class ‘ValueError’>

pi@pipixel:~/bp $

Definitely a fan of the ‘jumper to power the Pi directly’ idea :wink:

Hmmm… I’m honestly not sure what’s up with the “ValueError” thing. Though that warning is correct. For that animation type you should be using Strip instead of Matrix. Trying switching that. Something may be having a weird interaction. Just led = Strip(driver, num=64) - everything else is the same.

Also - what @djternes is being subtle about… once we run out of the current run of PiPixels, there’s a new version coming with an option to power the Pi :slight_smile:

1 Like

Thanks for the answer Adam, I will continue to buy the PiPixel hats, for my own projects I have decided to switch back to good old plain C. Python has just too much overhead for me and does not deliver enough advantages.

The BiblioPixel library as a C library, That would be the kicker. Otherwise I will just port a bastardized version of FastLED to the PI.

Ha, yea…I’ve thought about doing other languages but no real time to do it. But kinda the beauty of the PiPixel and AllPixel. Neither are complicated to interface with.