Skip to content

Use pixelbuf #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 22, 2022
Merged

Use pixelbuf #106

merged 4 commits into from
Jul 22, 2022

Conversation

Neradoc
Copy link
Contributor

@Neradoc Neradoc commented Jul 12, 2022

Use PixelBuf to back the pixels buffer in the neopixel submodule.
This adds compatibility with the adafruit_led_animation library, in particular it adds: __getitem__ and slices support. It sends pixel data all at once, but in chunks to avoid IO errors. It no longer sends pixel data as they are changed. Also switches the pixel order constants to strings, to match the neopixel API.

The size of the chunks is an estimate, I'm not sure if there are devices with seesaw builds that require a smaller size. Sending the whole strip of pixels at once can be quite slow with long pixel strips. This is the only way to do it with PixelBuf however, since the only access to the buffer is in _transmit.

Comparatively the original code would send pixels as they are modified, and only send a "show" command on show to the seesaw, basically putting the double buffer on the seesaw. This can actually be beneficial for some specific types of animations, but it's a tradeoff.

An alternative to this PR would be to add the PixelBuf API in python to the current implementation to keep the double buffering (and also optimize slices with chunks), for which the python version of PixelBuf might help.

I did some tests on Feather RP2040 with a Neokey 1x4 and a SAMD09 and ATTiny8x7 seesaw breakouts with a 30 pixels strip, no RGBW device. Additional tests on other seesaw boards would be nice.

Here is the test code:

import time
import board
import busio

i2c_bus = board.I2C()

# Test with seesaw breakout
from adafruit_seesaw import neopixel
from adafruit_seesaw.seesaw import Seesaw
seesaw = Seesaw(i2c_bus)
pixels = neopixel.NeoPixel(seesaw, 3, 30)

# test with Neokey 1x4:
"""
from adafruit_neokey.neokey1x4 import NeoKey1x4
neokey = NeoKey1x4(i2c_bus)
neokey.pixels.fill(0)
pixels = neokey.pixels
"""

from adafruit_led_animation.animation.rainbow import Rainbow
from adafruit_led_animation.animation.chase import Chase
from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.sequence import AnimationSequence
from adafruit_led_animation.color import AMBER, JADE

# works in the original version
comet = Comet(pixels, speed=0.02, color=JADE, tail_length=10, bounce=True)
# needs __getitem__, causes a MemoryError in the original version
chase = Chase(pixels, speed=0.04, size=3, spacing=6, color=AMBER)
# needs slices, causes TypeError in the original version
rainbow = Rainbow(pixels, speed=0.04)

while True:
    for x in range(100):
        comet.animate()
        time.sleep(0.01)
    for x in range(100):
        chase.animate()
        time.sleep(0.01)
    for x in range(100):
        rainbow.animate()
        time.sleep(0.01)

This should fix #105

Neradoc added 4 commits July 11, 2022 18:07
- use PixelBuf to back the pixels buffer in the neopixel submodule
- this adds compatibility with the adafruit_led_animation library
- in particular it adds getitem and slices support
- sends pixel data on show() un chunks to avoid IO errors
- no longer sends pixel data as they are changed
@tekktrik tekktrik requested a review from a team July 12, 2022 14:55
Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very good -- thanks! I was a little worried about the small Crickit-specific builds, but I see from the support matrix that both the CPX Crickit build and the Feather M0 Crickit build have adafruit_pixelbuf built in.

@dhalbert dhalbert merged commit 198f2aa into adafruit:main Jul 22, 2022
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jul 26, 2022
Updating https://github.com/adafruit/Adafruit_CircuitPython_MONSTERM4SK to 0.3.9 from 0.3.8:
  > Updated setup.py, reverted release.yml

Updating https://github.com/adafruit/Adafruit_CircuitPython_Seesaw to 1.11.2 from 1.10.12:
  > Merge pull request adafruit/Adafruit_CircuitPython_seesaw#108 from carlfj/patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_seesaw#109 from Neradoc/nera-fix-pixelbuf-size
  > Merge pull request adafruit/Adafruit_CircuitPython_seesaw#106 from Neradoc/use-pixelbuf
  > Changed .env to .venv in README.rst
  > Removed duplicate-code from library pylint disable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

seesaw.neopixel is incompatible with regular neopixel protocol
2 participants