1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

3-Wire PWM

Introduction

This will explain how various PWM led types are controlled and setup.

WS2812B chipset

The "ws2812b" driver only works for the Raspberry Pi 1 (A and B model).
The newly merged "ws281x" driver works for Raspberry Pi 1,2 and 3

Configuration

You can use the special driver for Ws2812b to run compatible leds, the device-config for the original led device should look like this:

Code:
  "device" :
   {
     "name"  : "MyPi",
     "type"  : "ws2812b",
     "colorOrder" : "rgb"
   },
The device-config for the NEW led device that support RPi 1,2,3 should look like this:
Code:
  "device" :
   {
     "name"  : "MyPi",
     "type"  : "ws281x",
     "colorOrder" : "grb",
     "leds"  : 107
   },
Additional device parameters

In addition to "colorOrder" and "leds", the "ws281x" device has the following parameters (listed here with their defaults):
Code:
     "gpio"  : 18,
     "dmanum"  : 5,
     "freq"  : 800000,
     "pwmchannel" : 0,
The RPi 2 and 3 both have three pins capable of PWM, BCM 18 (default, channel 0), BCM 12 (channel 0) and BCM 13 (channel 1). All three pins have been verified to work with WS2812B LEDs and with the ws281x driver. However, both PWM channels are used by the Pi's on-board analog audio, so you have the problem outlined below no matter which pin you choose.

Hardware setup



Connect the data line of the leds to the pin 12 (GPIO 18) of your raspberry pi, most people put a resistor (R* in the graphic) (100Ohm) between the leds and the pi for less ringing.
HINT:If you use higher resistor values, the reaction speed of your leds looks delayed!

This simple wiring isn't guaranteed to work for everyone. The ws2812b specifications state that the logic "high" signal needs to be > 0.7*VCC which is 3.5v. The Pi's GPIO pins will only output 3.3v so this will be close enough for some users, but is not guaranteed. To do it properly, you should use a level shifter on the data line or drop the LED strip's VCC to 4.7V.

Known problems

These drivers uses the same hardware (PWM channels) as the analog audio out of the RPi, they **can not** work at the same time since the share the same output data line! If you don't direct the audio to the HDMI port or otherwise disable the analog audio, you'll get random nonsense on your LEDs.

For a reason that hasn't been nailed down yet, if you use an OSMC or RetroPie image (straight Jessie and Jessie-Lite don't yet exhibit this behavior), then this driver will only work if the HDMI port is connected when the Pi boots.

If you want to use a ws2812 without tying up a USB port you may want to consider a SPI to ws2812 converter.bThere are a couple of these written by penfold42 published here:
https://github.com/penfold42/stuff?files=1

There seems to be a problem using this driver with Raspbian on Raspberry Pi 3 and Raspberry Pi Zero W (reported here: https://github.com/beyondscreen/node-rpi-ws281x-native/issues/61). To fix it, set the dmanum to 10 in the driver options.



More information

All RPi pin configurations, depending on your version:

http://www.raspberrypi-spy.co.uk/2012/06/simple-guide-to-the-rpi-gpio-header-and-pins/

Pin Configuration of the RPi / RPi2 40 pin header with nice printout (40 pin 'Hat'):

http://www.raspberrypi-spy.co.uk/2014/07/raspberry-pi-b-gpio-header-details-and-pinout

General information about WS2812B wiring

https://learn.adafruit.com/adafruit-neopixel-uberguide/best-practices

More info at: https://github.com/tvdzwan/hyperion/issues/6

This page has been seen 28,780 times.