Code Monkey home page Code Monkey logo

rpi-ws281x-matrix-python's Introduction

WS281X NeoPixel-ish Matrix Rendering Library

This library is intended to make the neopixel ish LED matrix to work with raspberry pi and Python. It is based on this rpi-ws281x python implementation. This makes it setting up your LED panel faster and removes a lot of hiccups. The original library does not work with panel, it is meant to control the strip.

Features offered

  • Direct resizing and rendering of images (png/jpeg).
  • Direct resizing and rendering of animations (gif)
  • Frames are represented as RGB Tuples so building your own frame is very simple.
  • Excellent brightness control.
  • Support for multi panel configurations.
  • Non-blocking threads, the operations are async and will not block you.

Setup

You'll need to install pillow and rpi-ws281x packages (and their dependencies from pip)

# pip install pillow rpi-ws281x

Demo

# python demo.py

The order is red -> green -> blue -> image -> animation. If this is not the order you see, your strip config is different than the mine.

Adding to your project

Add it as a submodule.

$ git submodule add https://github.com/whizzzkid/rpi-ws281x-matrix-python matrix

In your project

from matrix.ws281xMatrix import WS281xMatrix

screen = WS281xMatrix()

API

Once you have:

screen = WS281xMatrix()

You can simply ask it to render an image like so:

screen.render_image('path_to_image')

Why is this needed?

When I wrote this, I was frustrated to make this 16x16 panel work with RPi. The Adafruit Neopixel library claims that their panels cannot work with RPi because of their strict timing requirements. However that is not the case. The rpi-281x library is a proof that it works, however it does not allow you to dump images/animations directly on the screen. This library aims to solve just that.

License

MIT

rpi-ws281x-matrix-python's People

Contributors

whizzzkid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rpi-ws281x-matrix-python's Issues

Consider to use numpy for faster matrix operations

First of all I want to thank You for such a wonderful library. Even 0.0.2 version is pretty cool! ๐Ÿ˜„

I'm using it to reactively display some low latency animation based on sound. I process audio and put a result of it into a numpy array, which allows to make all the operations really fast compared to standard Python functions.

However the bottleneck is that I have to convert numpy array to Python list which is really time consuming for a hundreds of pixels.

        frame  = np.zeros((32, 16, 3), dtype=np.uint8)
        self.next_frame(frame.tolist())

I'm wondering if it's possible to speedup things and add support for a numpy?

Use Python3

Since Python2 reached EOL it makes sense to move to Python3.

It is as easy as:
xrange โ†’ range
from Queue import Queue โ†’ from queue import Queue

render() doesn't reverse some columns as render image method does

def render(self, frame):
"""Renders the supplied frame on the matrix.
Args:
frame: RGB representation of the frame.
"""
p = 0
for i in frame:
for j in i:
self.strip.setPixelColor(p, ws.Color(*j))
p += 1
self.strip.show()

self.render() should probably use self.next_frame()

def next_frame(self, frame, override = False):
"""Queues the next frame in the buffer. We can also override the current
buffer and display this frame instead.
Args:
frame: RGB representation of the frame.
override: optional
"""
if override:
self.buffer = Queue()
for i in xrange(len(frame)):
if i%2 == 1:
frame[i] = list(reversed(frame[i]))
self.buffer.put(frame)

Slow beginning animation

Hi

I'm using your code in a rpi3 to run 1200 LEDs in a strip.

My plan is run a 1200x1px GIF on the script. it will be 990 frames, at 30fps

Right now, I'm trying with a 660 frames sample I did and it's working almost great

The thing is, when the GIF starts it takes a few seconds to start running at aimed fps, it's like if everytime the loop starts it takes some time to process it or something.

Sorry if I'm asking a silly question, I'm quite noob at python.

My setup is a Rpi3 with raspbian strech, I thought to switch to lite version of the OS and see if it helps.

I have plenty of power for LEDS (70 AMP) and I'm using a logic level converter between Pi and 2812's.

Maybe is a way to optimize this? Code wise I'm just using your demo, deleting everything before the animation.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.