GithubHelp home page GithubHelp logo

piers7 / rpi_ws281x Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jgarff/rpi_ws281x

0.0 1.0 0.0 268 KB

Userspace Raspberry Pi PWM library for WS281X LEDs

License: BSD 2-Clause "Simplified" License

Python 25.88% C 52.66% Shell 0.23% C# 21.23%

rpi_ws281x's Introduction

rpi_ws281x

Userspace Raspberry Pi PWM library for WS281X LEDs

This fork exists to create a .net/mono wrapper around the ws281x library - see the .\mono\README.md.

This fork will generally track upstream where possible.

Background:

The BCM2835 in the Raspberry Pi has a PWM module that is well suited to driving individually controllable WS281X LEDs. Using the DMA, PWM FIFO, and serial mode in the PWM, it's possible to control almost any number of WS281X LEDs in a chain connected to the PWM output pin.

This library and test program set the clock rate of the PWM controller to 3X the desired output frequency and creates a bit pattern in RAM from an array of colors where each bit is represented by 3 bits for the PWM controller as follows.

Bit 1 - 1 1 0
Bit 0 - 1 0 0

Hardware:

WS281X LEDs are generally driven at 5V, which requires that the data signal be at the same level. Converting the output from a Raspberry Pi GPIO/PWM to a higher voltage through a level shifter is required.

It is possible to run the LEDs from a 3.3V - 3.6V power source, and connect the GPIO directly at a cost of brightness, but this isn't recommended.

The test program is designed to drive a 8x8 grid of LEDs from Adafruit (http://www.adafruit.com/products/1487). Please see the Adafruit website for more information.

Know what you're doing with the hardware and electricity. I take no reponsibility for damage, harm, or mistakes.

Build:

  • Install Scons (on raspbian, apt-get install scons).
  • Make sure to adjust the parameters in main.c to suit your hardare.
    • Signal rate (400kHz to 800kHz). Default 800kHz.
    • ledstring.invert=1 if using a inverting level shifter.
    • Width and height of LED matrix (height=1 for LED string).
  • Type 'scons' from inside the source directory.

Running:

Enter the following at the console:

sudo scons
sudo ./test

That's it. You should see a moving rainbow scroll across the display.

Usage:

The API is very simple. Make sure to create and initialize the ws2811_t structure as seen in main.c. From there it can be initialized by calling ws2811_init(). LEDs are changed by modifying the color in the .led[index] array and calling ws2811_render(). The rest is handled by the library, which creates the DMA memory and starts the DMA/PWM.

Make sure to hook a signal handler for SIGKILL to do cleanup. From the handler make sure to call ws2811_fini(). It'll make sure that the DMA is finished before program execution stops.

That's it. Have fun. This was a fun little weekend project. I hope you find it useful. I plan to add some diagrams, waveform scope shots, and a .deb package soon.

Wrappers

This repository also contains:

  • A python wrapper, originally by Tony Dicola @tdicola
  • A .net/mono wrapper (reason for this fork)

rpi_ws281x's People

Contributors

jgarff avatar piers7 avatar tdicola avatar twp avatar

Watchers

 avatar

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.