1

I'm trying to drive a RGB LED strip with RPI's GPIO18 in python with rpi_ws281x library while listening to USB Microphone connected to the RPI to finally send colors depending on audio frequencies captured.

Problem: the LED strip works fine UNTIL i instanciate the pyAudio Object. As soon as I execute the following instructions:

>>> import pyaudio
>>> p = pyaudio.PyAudio() # <-- after this instruction the LED strip is KO

After that instruction the LED strip blocks or displays random colors. PyAudio outputs some messages see at the end of this post.

Is there an incompatiblity between GPIO18 in PWM mode and PyAudio ?

Any help would be appreciated, and Merry Christmas All!

Notes:

  • I use the strandtest.py script to test the led strip (see reference below). This script works great.
  • Recording microphone manually with arecord command while LED strip is being driven by strandtest.py works great too
  • PyAudio input mode works. I managed to get audio frequencies with fft.

References:

(NeoPixel sample wiring)[https://learn.adafruit.com/neopixels-on-raspberry-pi/wiring]

(rpi_ws281x strandtest)[https://github.com/jgarff/rpi_ws281x/blob/master/python/examples/strandtest.py]

PyAudio's messages:

ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm28                                   35.pcm.front.0:CARD=0'
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned err                                   or: No such file or directory
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directo                                   ry
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM front
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm28                                   35.pcm.surround51.0:CARD=0'
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned err                                   or: No such file or directory
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directo                                   ry
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM surround21
ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm28                                   35.pcm.surround51.0:CARD=0'
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned err                                   or: No such file or directory
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directo                                   ry
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM surround21
ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm28                                   35.pcm.surround40.0:CARD=0'
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned err                                   or: No such file or directory
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directo                                   ry
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM surround40
ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm28                                   35.pcm.surround51.0:CARD=0'
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned err                                   or: No such file or directory
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directo                                   ry
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM surround41
ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm28                                   35.pcm.surround51.0:CARD=0'
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned err                                   or: No such file or directory
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directo                                   ry
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM surround50
ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm28                                   35.pcm.surround51.0:CARD=0'
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned err                                   or: No such file or directory
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directo                                   ry
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM surround51
ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm28                                   35.pcm.surround71.0:CARD=0'
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned err                                   or: No such file or directory
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directo                                   ry
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM surround71
ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm28                                   35.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned err                                   or: No such file or directory
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directo                                   ry
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM iec958
ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm28                                   35.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned err                                   or: No such file or directory
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directo                                   ry
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM spdif
ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm28                                   35.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned err                                   or: No such file or directory
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directo                                   ry
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM spdif
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started

1 Answer 1

1

Both PyAudio and rpi_ws281x are using a single hardware PWM peripheral in an inconsistent fashion. Of course it does not work.

You need to change one of them to not use the hardware PWM peripheral.

I'd have thought the LED strips could be driven by the hardware PCM peripheral rather than the hardware PWM peripheral.

2
  • Thanks for the reply! I'm a total noob with this so I want to apologize in advance if i ask dumb questions :-) I don't understand why Pyaudio will mess up the GPIO18 (whereas arecord do not while doing the same thing) ? Dec 19, 2016 at 11:59
  • I have no idea. I'm not into audio or LED strips. You may find someone who knows at github.com/jgarff/rpi_ws281x/issues
    – joan
    Dec 19, 2016 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.