nrzled

package
v3.6.4+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package nrzled is a driver for LEDs ws2811/ws2812/ws2812b and compatible devices like sk6812 and ucs1903 that uses a single wire NRZ encoded communication protocol.

Note that some ICs are 7 bits with the least significant bit ignored, others are using a real 8 bits PWM. The PWM frequency varies across ICs. User can select a driver implementation using a memory-mapped GPIO line or leverage a SPI connection's MISO pin.

The SPI implementation is sensitive to variations in SPI clock speed. On the Raspberry Pi, you will need to add `core_freq=250` to /boot/config.txt to prevent glitching.

You may also need to increase your SPI buffer size to 12*num_pixels+3, or just max it out with `spidev.bufsize=65536`. That should allopw you to buffer over 5400 Neopixels.

Datasheet

This directory contains datasheets for ws2812, ws2812b, ucs190x and various sk6812.

https://github.com/cpldcpu/light_ws2812/tree/master/Datasheets

UCS1903 datasheet

http://www.bestlightingbuy.com/pdf/UCS1903%20datasheet.pdf

ws2812b A.K.A. Neopixel datasheet

https://cdn-shop.adafruit.com/datasheets/WS2812B.pdf

Index

Constants

This section is empty.

Variables

View Source
var DefaultOpts = Opts{
	NumPixels: 150,
	Channels:  3,
	Freq:      800 * physic.KiloHertz,
}

DefaultOpts is the recommended default options.

Functions

This section is empty.

Types

type Dev

type Dev struct {
	// contains filtered or unexported fields
}

Dev is a handle to the LED strip.

func NewSPI

func NewSPI(p spi.Port, opts *Opts) (*Dev, error)

NewSPI returns a strip that communicates over SPI to NRZ encoded LEDs.

Due to the tight timing demands of these LEDs, the SPI port speed must be a reliable 2.4~2.5MHz; this is 3x 800kHz.

The driver's SPI buffer must be at least 12*num_pixels+3 bytes long.

func NewStream

func NewStream(p gpiostream.PinOut, opts *Opts) (*Dev, error)

NewStream opens a handle to a compatible LED strip.

func (*Dev) Bounds

func (d *Dev) Bounds() image.Rectangle

Bounds implements display.Drawer. Min is guaranteed to be {0, 0}.

func (*Dev) ColorModel

func (d *Dev) ColorModel() color.Model

ColorModel implements display.Drawer.

It is color.NRGBAModel.

func (*Dev) Draw

func (d *Dev) Draw(r image.Rectangle, src image.Image, sp image.Point) error

Draw implements display.Drawer.

Using something else than image.NRGBA is 10x slower and is not recommended. When using image.NRGBA, the alpha channel is ignored in RGB mode and used as White channel in RGBW mode.

A back buffer is kept so that partial updates are supported, albeit the full LED strip is updated synchronously.

func (*Dev) Halt

func (d *Dev) Halt() error

Halt turns the lights off.

It doesn't affect the back buffer.

func (*Dev) String

func (d *Dev) String() string

func (*Dev) Write

func (d *Dev) Write(pixels []byte) (int, error)

Write accepts a stream of raw RGB/RGBW pixels and sends it as NRZ encoded stream.

This bypasses the back buffer.

type Opts

type Opts struct {
	// NumPixels is the number of pixels to control. If too short, the following
	// pixels will be corrupted. If too long, the pixels will be drawn
	// unnecessarily but not visible issue will occur.
	NumPixels int
	// Channels is 1 for single color LEDs, 3 for RGB LEDs and 4 for RGBW (white)
	// LEDs.
	Channels int
	// Freq is the frequency to use to drive the LEDs. It should be either 800kHz
	// for fast ICs and 400kHz for the slow ones.
	Freq physic.Frequency
}

Opts defines the options for the device.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL