sudo sed -i -e "s/^dtparam=audio=on/# dtparam=audio=on/g" /boot/config.txt
ここでは、Adafruitの下記のチュートリアルを参考に WS2812を動かします。
(Adafruitの解説では +5V電源を使用して、制御線に 74AHCT125のレベルコンバータを入れる方法と、+5Vに直列に 1N4001ダイオードを入れる結線方法が示されています。) NeoPixels on Raspberry Pi
How to control NeoPixel LEDs with Python on a Raspberry Pi!
# LED strip configuration:
LED_COUNT = 8 # Number of LED pixels.
LED_PIN = 12 # GPIO pin connected to the pixels (must support PWM!).
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
LED_DMA = 5 # DMA channel to use for generating signal (try 5)
LED_BRIGHTNESS = 12 # Set to 0 for darkest and 255 for brightest
LED_INVERT = False # True to invert the signal (when using NPN transistor$
cd ~/rpi_ws281x/python/examples
sudo sed -i -e "s/^LED_COUNT = 16/LED_COUNT = 8 /g" strandtest.py
sudo sed -i -e "s/^LED_PIN = 18/LED_PIN = 12/g" strandtest.py
sudo sed -i -e "s/^LED_BRIGHTNESS = 255/LED_BRIGHTNESS = 8 /g" strandtest.py
# NeoPixel library strandtest example
# Author: Tony DiCola (tony@tonydicola.com)
#
# Direct port of the Arduino NeoPixel library strandtest example. Showcases
# various animations on a strip of NeoPixels.
import time
from neopixel import *
# LED strip configuration:
LED_COUNT = 8 # Number of LED pixels.
LED_PIN = 12 # GPIO pin connected to the pixels (must support PWM!).
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
LED_DMA = 5 # DMA channel to use for generating signal (try 5)
LED_BRIGHTNESS = 8 # Set to 0 for darkest and 255 for brightest
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
# Define functions which animate LEDs in various ways.
def colorWipe(strip, color, wait_ms=0):
"""Wipe color across display a pixel at a time."""
for i in range(strip.numPixels()):
strip.setPixelColor(i, color)
strip.show()
time.sleep(wait_ms/1000.0)
# Main program logic follows:
if __name__ == '__main__':
# Create NeoPixel object with appropriate configuration.
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS)
# Intialize the library (must be called once before other functions).
strip.begin()
colorWipe(strip, Color(0, 0, 0)) # clear wipe
cd
git clone https://github.com/wejn/ws2812
cd ws2812
# Assuming raspbian here; otherwise make sure you have 'mkmf'
# and can compile exts (failing that "rake compile" will bomb on you)
sudo apt-get -y update
sudo apt-get install -y ruby-full