New to BP. Could I get some sample code to get me started please?

Hi again. I am using a WS2812B light strip. I have installed and tested the PiWS281X drivers (I’m using LED_COUNT 240, LED_PIN 13, LED_CHANNEL 1) and I have installed BiblioPixel on an RPi3. I am at a loss now for how to utilize BP. Could someone please help me out with some sample code to get me started? Any help is appreciated. Thank you.

Just to clarify, did you run the rpi_ws281x examples or you ran the BiblioPixel PiWS281X driver? If the latter, can you send the code you used to test? I just want to see where you are at.
What is LED_CHANNEL 1?
Also… I recommend using 18 instead of 13. More stable in my experience.

After ensuring you have BiblioPixel 3.1.3 installed (pip3 freeze), trying this:

bibliopixel run [https://gist.githubusercontent.com/adammhaile/d00ff2a4ad5add5c948e2df8e4d3f97c/raw/694a9725b5777819b7d4b04d238a2bbe1739bb71/piws2812x.json](https://gist.githubusercontent.com/adammhaile/d00ff2a4ad5add5c948e2df8e4d3f97c/raw/694a9725b5777819b7d4b04d238a2bbe1739bb71/piws2812x.json) --verbose

So, here’s the thing. Yes… you can technically still just write nothing but python code to script out what you want to do but we’ve improved BiblioPixel greatly and you would be missing out on a bunch of cool features if you did go the raw script route. First, we highly recommend writing any actually animations as an Animation class, which you can find more info on here: https://github.com/ManiacalLabs/BiblioPixel/wiki/Writing-an-Animation

This is just a convenient way to package up a discrete animation and use it. Once you have that animation you’re actually done. Go to the file linked above in the bibliopixel run command. As you’ll see it’s a pretty simple JSON file that sets up your layout, driver, and calls an animation class. There are many more options here which we recommend checking out: https://github.com/ManiacalLabs/BiblioPixel/wiki/Projects
And I realize that the docs are not super great right now… we are trying to get things updated as quick as possible. Please do not hesitate to ask any more questions here… it really helps us focus in on what needs more attention in the docs.

Also, by using BiblioPixel projects instead of just writing scripts you’ll get the best of the best in new features as that’s where the core of our development work is going.
For example…

  • In 3.1.3 (current version) you can run a Web UI remote that’s built in. To see it in action, call bibliopixel run [https://github.com/ManiacalLabs/BiblioPixelAnimations/blob/master/Projects/matrix.json](https://github.com/ManiacalLabs/BiblioPixelAnimations/blob/master/Projects/matrix.json) then load http://localhost:5000 and http://simpixel.io You can choose any animation you want on the fly and, in this case, SimPixel will show the animation immediately. SimPixel is great for testing animation code when you don’t have the hardware at hand.
  • Coming in the next release the Web remote will also have a handy brightness control to tweak your brightness live, as the animations are running.
  • Also in the next release will be animation “Triggers” such as starting/stopping at a specific time, or even when your Pi senses that your phone is nearby via bluetooth. Note, this is only available using BiblioPixel projects and the Web remote. You can’t get any of that when scripting manually.
    Point being, write your animation first… plenty of strip examples here: https://github.com/ManiacalLabs/BiblioPixelAnimations/tree/master/BiblioPixelAnimations/strip
    (Note: all of those are already installed when you installed BiblioPixel).
    Then just load the animation from a JSON project file. That way you don’t have to worry about anything else.

···

On Mon, Aug 7, 2017 at 9:40 PM, Chet Stevens cws.ccsd@gmail.com wrote:

Hi again. I am using a WS2812B light strip. I have installed and tested the PiWS281X drivers (I’m using LED_COUNT 240, LED_PIN 13, LED_CHANNEL 1) and I have installed BiblioPixel on an RPi3. I am at a loss now for how to utilize BP. Could someone please help me out with some sample code to get me started? Any help is appreciated. Thank you.

You received this message because you are subscribed to the Google Groups “Maniacal Labs Users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to maniacal-labs-users+unsubscribe@googlegroups.com.

To post to this group, send email to maniacal-labs-users@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/maniacal-labs-users/1b1ea6a9-7b9c-4fd6-85e0-f7bbe84e73cc%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Thank you for the reply, Adam! Yes, I have only run the examples in rpi_ws281x. I’ve had to use pin 13 because 18 is in use by a sound card HAT. Do you think I would save myself some trouble by using a PWM HAT or AllPixel instead of pin 13? Thank you for the sample JSON file. I will try using that. I wasn’t sure before how to define what pin I needed to operate on, etc. If I have a working animation from using ''bibliopixel run .json" can this animation then be called/controlled natively from within a python script or is it only ever run by calling the shell command? Thank you again for your help.

···

On Monday, August 7, 2017 at 6:40:24 PM UTC-7, Chet Stevens wrote:

Hi again. I am using a WS2812B light strip. I have installed and tested the PiWS281X drivers (I’m using LED_COUNT 240, LED_PIN 13, LED_CHANNEL 1) and I have installed BiblioPixel on an RPi3. I am at a loss now for how to utilize BP. Could someone please help me out with some sample code to get me started? Any help is appreciated. Thank you.

Just try it with GPIO 13… should work, just wanted to note that 13 is considered the backup in this case. I know for a fact it doesn’t work on the Pi Zero, but the Pi 3 should be fine.

Right now there’s no great way to call a project (JSON) based setup from a python script without just shelling out and calling bibliopixel run file.json as a sub-process.

You could of course use BP direct for code if you wanted:


from bibliopixel import Strip

from bibliopixel.drivers.PiWS281X import PiWS281X

from BiblioPixelAnimations.strip.Rainbows import RainbowCycle

driver = PiWS281X(num=240, c_order="RGB", gpio=13)

layout = Strip(driver, brightness=255)

anim = RainbowCycle(layout)

anim.run(fps=30)

But as it’s my duty to push BiblioPixel projects on all new users…

https://gist.github.com/adammhaile/441859339184871bef2169e4f0ca7c10

What you’ll see there is like the other project file I gave you but implements the new remote UI functionality. It’s currently undocumented because it’s in “soft launch” as it’s very new. But here’s where I’m going with this… if you run that project file you can then go to http://localhost:5000 (or the IP of your Pi 3) and you will get a simple Web UI with buttons for Stop, ColorWipe, ColorPattern, and ColorFade. You can press the buttons of course to launch those animations. But you can also call out to the remote directly to start them. For example:


import urllib.request

urllib.request.urlopen('[http://localhost:5000/run_animation/ColorPattern](http://localhost:5000/run_animation/ColorPattern)')

Will launch ColorPattern as configured in the JSON file.

If you want to stop an animation, call [http://localhost:5000/stop](http://localhost:5000/stop`)

So if you want your script to start the server you would still have to call out to a sub-process to run bibliopixel run first.

Note to Tom: There is nothing I see outside of bibliopixel.main that would allow you to run a project file from code. I see this as a huge missed opportunity for script integration. We should add something directly off bibliopixel like run_project where you just pass it the filepath and it spawns a new process and does all the same stuff. For all I care it could just sub-process out to bibliopixel run but it should be easily called from the bibliopixel module and automatically be in a new process.

Hmm… as I was typing the above you came back with a solution, but I don’t think it’s elegant enough. Should be shorter:


from bibliopixel import run_project

bp_project = run_project('/path/to/project.json') # always threaded

# do your stuff

bp_project.stop()

Sorry Chet… back to you :slight_smile:

Anyways, between my solutions above and Tom’s there are a few ways you can run all this. Hopefully that makes sense.

···

On Tue, Aug 8, 2017 at 9:47 AM, Chet Stevens cws.ccsd@gmail.com wrote:

Thank you for the reply, Adam! Yes, I have only run the examples in rpi_ws281x. I’ve had to use pin 13 because 18 is in use by a sound card HAT. Do you think I would save myself some trouble by using a PWM HAT or AllPixel instead of pin 13? Thank you for the sample JSON file. I will try using that. I wasn’t sure before how to define what pin I needed to operate on, etc. If I have a working animation from using ''bibliopixel run .json" can this animation then be called/controlled natively from within a python script or is it only ever run by calling the shell command? Thank you again for your help.

On Monday, August 7, 2017 at 6:40:24 PM UTC-7, Chet Stevens wrote:

Hi again. I am using a WS2812B light strip. I have installed and tested the PiWS281X drivers (I’m using LED_COUNT 240, LED_PIN 13, LED_CHANNEL 1) and I have installed BiblioPixel on an RPi3. I am at a loss now for how to utilize BP. Could someone please help me out with some sample code to get me started? Any help is appreciated. Thank you.

You received this message because you are subscribed to the Google Groups “Maniacal Labs Users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to maniacal-labs-users+unsubscribe@googlegroups.com.

To post to this group, send email to maniacal-labs-users@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/maniacal-labs-users/bbdcd002-654c-45d7-a327-a4f2e1931de7%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

With a small modification it works!

Could I make one small request/recommendation? Per the comments in the rpi_ws281x drivers; "LED_CHANNEL = 1 # set to ‘1’ for GPIOs 13, 19, 41, 45 or 53.

Currently this is hard coded as ‘0’ in bibliopixel/drivers/PiWS281X.py:

self._strip = Adafruit_NeoPixel(num, gpio, ledFreqHz,

                                    ledDma, ledInvert, 255, **0**, 0x081000)

``

Could a new driver be added for “channel”? For example:

“driver”: {

“num”: 240,

“typename”: “pi_ws281x”,

“c_order”: “RGB”,

“gpio”: 13,
“channel”: 1,

},

``

Thank you for all your help!

···

On Monday, August 7, 2017 at 6:40:24 PM UTC-7, Chet Stevens wrote:

Hi again. I am using a WS2812B light strip. I have installed and tested the PiWS281X drivers (I’m using LED_COUNT 240, LED_PIN 13, LED_CHANNEL 1) and I have installed BiblioPixel on an RPi3. I am at a loss now for how to utilize BP. Could someone please help me out with some sample code to get me started? Any help is appreciated. Thank you.

Chet,
Funny timing… I was just playing around with that for a new product, updated to the latest rpi_ws281x and realized that was now broken. When I first wrote it I’m pretty sure that was unnecessary. I’ll have a fix in dev shortly, though it might be a little bit until it’s in a release… not quite ready for that with the current dev branch.

But what I think I’ll actually do is just pull the channel and pin list from the rpi_ws281x code and just auto-set the channel for you. No reason not to as they are fixed values.

···

On Tue, Aug 8, 2017 at 7:56 PM, Chet Stevens cws.ccsd@gmail.com wrote:

With a small modification it works!

Could I make one small request/recommendation? Per the comments in the rpi_ws281x drivers; "LED_CHANNEL = 1 # set to ‘1’ for GPIOs 13, 19, 41, 45 or 53.

Currently this is hard coded as ‘0’ in bibliopixel/drivers/PiWS281X.py:

self._strip = Adafruit_NeoPixel(num, gpio, ledFreqHz,

                                    ledDma, ledInvert, 255, **0**, 0x081000)

``

Could a new driver be added for “channel”? For example:

“driver”: {

“num”: 240,

“typename”: “pi_ws281x”,

“c_order”: “RGB”,

“gpio”: 13,
“channel”: 1,

},

``

Thank you for all your help!

On Monday, August 7, 2017 at 6:40:24 PM UTC-7, Chet Stevens wrote:

Hi again. I am using a WS2812B light strip. I have installed and tested the PiWS281X drivers (I’m using LED_COUNT 240, LED_PIN 13, LED_CHANNEL 1) and I have installed BiblioPixel on an RPi3. I am at a loss now for how to utilize BP. Could someone please help me out with some sample code to get me started? Any help is appreciated. Thank you.

You received this message because you are subscribed to the Google Groups “Maniacal Labs Users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to maniacal-labs-users+unsubscribe@googlegroups.com.

To post to this group, send email to maniacal-labs-users@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/maniacal-labs-users/fa02cb4d-c365-40cd-8dd9-eaf1352d280f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Chet,

Grab BP 3.2 and it will now automatically select the correct channel depending on which GPIO pin you choose.

pip3 install --upgrade bibliopixel

···