前言

树莓派在控制某些硬件外设上坑还真不少,今天就又踩了一个(其实有两天了)。其实越复杂的问题往往是有越简单的解决办法。
树莓派驱动ws2812 网上一搜几乎都是 用的 rpi-ws281x 这个库

安装

安装还是比较简单

sudo pip3 install rpi-ws281x

官方示例

看看官方的示例程序 ,这是一个名为 strandtest.py 的示例程序
当然还有其他的示例程序 Github链接

#!/usr/bin/env python3
# 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 rpi_ws281x import PixelStrip, Color
import argparse# LED strip configuration:
LED_COUNT = 16        # Number of LED pixels.
LED_PIN = 18          # GPIO pin connected to the pixels (18 uses PWM!).
# LED_PIN = 10        # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
LED_FREQ_HZ = 800000  # LED signal frequency in hertz (usually 800khz)
LED_DMA = 10          # DMA channel to use for generating signal (try 10)
LED_BRIGHTNESS = 255  # Set to 0 for darkest and 255 for brightest
LED_INVERT = False    # True to invert the signal (when using NPN transistor level shift)
LED_CHANNEL = 0       # set to '1' for GPIOs 13, 19, 41, 45 or 53# Define functions which animate LEDs in various ways.
def colorWipe(strip, color, wait_ms=50):"""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)def theaterChase(strip, color, wait_ms=50, iterations=10):"""Movie theater light style chaser animation."""for j in range(iterations):for q in range(3):for i in range(0, strip.numPixels(), 3):strip.setPixelColor(i + q, color)strip.show()time.sleep(wait_ms / 1000.0)for i in range(0, strip.numPixels(), 3):strip.setPixelColor(i + q, 0)def wheel(pos):"""Generate rainbow colors across 0-255 positions."""if pos < 85:return Color(pos * 3, 255 - pos * 3, 0)elif pos < 170:pos -= 85return Color(255 - pos * 3, 0, pos * 3)else:pos -= 170return Color(0, pos * 3, 255 - pos * 3)def rainbow(strip, wait_ms=20, iterations=1):"""Draw rainbow that fades across all pixels at once."""for j in range(256 * iterations):for i in range(strip.numPixels()):strip.setPixelColor(i, wheel((i + j) & 255))strip.show()time.sleep(wait_ms / 1000.0)def rainbowCycle(strip, wait_ms=20, iterations=5):"""Draw rainbow that uniformly distributes itself across all pixels."""for j in range(256 * iterations):for i in range(strip.numPixels()):strip.setPixelColor(i, wheel((int(i * 256 / strip.numPixels()) + j) & 255))strip.show()time.sleep(wait_ms / 1000.0)def theaterChaseRainbow(strip, wait_ms=50):"""Rainbow movie theater light style chaser animation."""for j in range(256):for q in range(3):for i in range(0, strip.numPixels(), 3):strip.setPixelColor(i + q, wheel((i + j) % 255))strip.show()time.sleep(wait_ms / 1000.0)for i in range(0, strip.numPixels(), 3):strip.setPixelColor(i + q, 0)# Main program logic follows:
if __name__ == '__main__':# Process argumentsparser = argparse.ArgumentParser()parser.add_argument('-c', '--clear', action='store_true', help='clear the display on exit')args = parser.parse_args()# Create NeoPixel object with appropriate configuration.strip = PixelStrip(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)# Intialize the library (must be called once before other functions).strip.begin()print('Press Ctrl-C to quit.')if not args.clear:print('Use "-c" argument to clear LEDs on exit')try:while True:print('Color wipe animations.')colorWipe(strip, Color(255, 0, 0))  # Red wipecolorWipe(strip, Color(0, 255, 0))  # Green wipecolorWipe(strip, Color(0, 0, 255))  # Blue wipeprint('Theater chase animations.')theaterChase(strip, Color(127, 127, 127))  # White theater chasetheaterChase(strip, Color(127, 0, 0))  # Red theater chasetheaterChase(strip, Color(0, 0, 127))  # Blue theater chaseprint('Rainbow animations.')rainbow(strip)rainbowCycle(strip)theaterChaseRainbow(strip)except KeyboardInterrupt:if args.clear:colorWipe(strip, Color(0, 0, 0), 10)

测试

新建一个py文件,copy上面那个示例程序,使用命令行运行 (直接在IDE运行会报错,目前不知道解决办法)
比如 我建的名字为 test.py, 放在了桌面

cd Desktop
sudo python3 test.py

虽然没报错,但是灯是没有任何反应的,经过一番查找,在这里找到了原因,原来需要关闭音频输出。。。。。。

解决办法

打开终端运行

sudo nano /etc/modprobe.d/snd-blacklist.conf

添加下列语句

blacklist snd_bcm2835

ctrl+o保存 ctrl+x退出

修改conf.txt文件

sudo nano /boot/config.txt

找到下列语句(一般是在最下面)

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

注释掉第二行

# Enable audio (loads snd_bcm2835)
#dtparam=audio=on

ctrl+o保存 ctrl+x退出

重启

sudo reboot

再次运行程序,可以成功点亮

树莓派驱动 WS2812 灯珠 不亮的问题相关推荐

  1. STM32使用PWM+DMA方式驱动WS2812灯珠

    一. 关于WS2812 WS2812 内部集成了处理芯片和3颗不同颜色的led灯(红,绿,蓝),通过单总线协议分别控制三个灯的亮度强弱,达到全彩的效果. WS2812B Datasheet 二. WS ...

  2. WS2812灯珠(三)-- STM32 PWM+DMA方式驱动

    WS2812灯珠(三)-- STM32 PWM+DMA方式驱动 文章目录 WS2812灯珠(三)-- STM32 PWM+DMA方式驱动 一.理论 二.代码实践 一.理论 PWM输出就是对外输出脉宽( ...

  3. Arduino控制1302颗ws2812灯珠显示圣诞树和圣诞老人(附程序源码)

    Arduino控制1302颗ws2812灯珠显示圣诞树和圣诞老人 设计者:STCode(公众号同名) 效果直接看视频~ Arduino控制ws2812灯带显示圣诞树和圣诞老人 1)项目介绍 该设计一共 ...

  4. WS2812灯珠(四)---实现全彩呼吸灯效果

    WS2812灯珠实现呼吸灯效果主要涉及到呼吸函数及颜色模型两部分的内容.清楚了这两点结合之前的灯珠驱动程序,便可以实现任意颜色的呼吸变换效果了. 呼吸函数 具体的呼吸函数细节这里就不介绍了,感兴趣的可 ...

  5. 学习用树莓派驱动LED灯闪烁

    学习用树莓派驱动LED灯闪烁 [前沿] ·认识GPIO编码 ·准备实验材料 ·实验电路连接 ·编写驱动程序 ·讲解其它的驱动方式(扩展篇) [实际操作] 一.认识GPIO编码 学习如何用树莓派驱动LE ...

  6. STC15点亮WS2812灯珠(C结合汇编)

    WS2812自带5050灯珠,只需要一个IO口就能够驱动LED灯带,十分方便.但是,由于需要800K的PWM信号,对大部分单片机来说,压力非常大,通常单片机的硬件PWM只支持到100K左右. 好不容易 ...

  7. WS2812灯珠(五)---移植Adafruit_NeoPixel库

    将Adafruit_NeoPixel库移植为C版本 Adafruit_NeoPixel库为实现WS2812类似系列的灯珠实现非常酷炫的效果提供了各种接口函数,应用层可以很方便的利用这些接口函数实现各种 ...

  8. STM32F405驱动WS2812E灯珠灯带代码

    头文件: #ifndef __LAMP_BEADS_H__ #define __LAMP_BEADS_H__#include "tim.h" #include "main ...

  9. GD32驱动SK6812灯珠

    GD32F130G6U6 SPI驱动SK6812 GPIO配置 SPI配置 SPI发送 DMA配置 GPIO配置 使用IO口PB5,GPIO初始化: rcu_periph_clock_enable(R ...

最新文章

  1. WiFi行业9大趋势解析
  2. “完美论文”过于真实,道出了科研狗的痛
  3. Java SE、Java EE、Java ME三者的区别
  4. springmvc接收参数
  5. Spark 2.1.0集成CarbonData 1.1.0
  6. 用过http api 发送邮件
  7. Asp.Net中OnClientClick与OnClick之我见
  8. [Linux]搭建Jdk7与Tomcat7
  9. 小情调的伤感空间日志分享:亲爱的、你还不懂么?
  10. ddd软件设计两个人的工作
  11. 英文单词缩写规则(转自天涯)
  12. 了解Wi-fi频段概念
  13. creo绘图属性模板_creo制作工程图模板教程
  14. 与计算机应用相关的公告,2015全国大学生数学建模与计算机应用竞赛报名通知...
  15. DateUtil时间处理插件
  16. 新生宝宝奶粉喂养正确方法
  17. 设计模式之七大原则——里氏替换原则(LSP)(三)
  18. CSS实现背景图轮播
  19. Mybatis association标签用途
  20. 沃尔玛logo的历史

热门文章

  1. python编程用台式还是笔记本好_编程选什么笔记本电脑?
  2. 笔记本电脑推荐2020大学生计算机,2020年大学生笔记本电脑推荐
  3. 图解!《养老机构服务安全基本规范》—养老第一项强制性国家标准
  4. win10系统无法连接网络解决办法
  5. 4.5-那些漂亮软件是怎么做出来的?为啥自己做的好丑
  6. html5游戏存档,别出机杼,这些游戏把存档玩出了花
  7. 【美股】美股中的几种分析形态
  8. 【转载】Sqlserver使用Right函数从最右边向前截取固定长度字符串
  9. 王佩丰excel学习笔记(二):第三——六讲
  10. 中国广告联合总公司局域网流量控制案例【上海百络信息技术有限公司-典型案例】