sebar
Posts: 12
Joined: Thu Jan 04, 2018 9:49 am

Project: Pi 3 PWM - Control LEDs AND play audio?

Thu Jan 04, 2018 10:11 am

Hi guys!

I want to set up my Pi 3 as an MP3 audio center with external amplification and music library over USB. And since the Pi is capable of much more than just playing and organizing MP3s I also want to attach a DIY LED panel that functions as a spectrum analyzer/VU meter/message display.

Before I get started and run into serious trouble I want to ask you some questions that I couldn't find clear answers to myself. AFAIK the Pi's PWM can either control LED panels (I'm thinking about WS2811 strips) OR play analog audio. Or does that limitation only apply to older models?

However, to avoid interference, I figured I should either attach a HifiBerry DAC or route the audio over the HDMI - so the Pi's PWM pin can be dedicated to the LED panel. The HDMI solution would of course require another D/A conversion so I can hear the audio.

So, what do you think? Am I way off or is my project possible?

Cheers!

SurferTim
Posts: 1800
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Project: Pi 3 PWM - Control LEDs AND play audio?

Thu Jan 04, 2018 11:29 am

I moved the PWM off the RPi.
https://www.adafruit.com/product/815
Just a thought.

Edit: ...or if you don't mind waiting a couple weeks for delivery:
https://www.banggood.com/PCA9685-16-Cha ... rehouse=CN

User avatar
joan
Posts: 15090
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Project: Pi 3 PWM - Control LEDs AND play audio?

Thu Jan 04, 2018 11:58 am

You don't need to use the specialized PWM pins for PWM. There are several libraries which will generate hardware timed PWM on any spare GPIO.

Rather than the WS2811 perhaps consider strips based on APA102 which are much easier to drive.

sebar
Posts: 12
Joined: Thu Jan 04, 2018 9:49 am

Re: Project: Pi 3 PWM - Control LEDs AND play audio?

Thu Jan 04, 2018 12:13 pm

From another project I still have a bunch WS2811 - so if possible, I want to use them.
@ joan, I guess the problem lies not in the pin, but in the PWM processor, right? I mean, the PWM module can only drive either the LEDs or the audio without disturbance. Please correct me if I'm wrong.

@ SurferTim, thanks for the links - what price difference! So do I get it right - that extra board comes with an own PWM module so that in total there would be two then? One for the sound and one for the LEDs?

Thank you so much so far!

SurferTim
Posts: 1800
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Project: Pi 3 PWM - Control LEDs AND play audio?

Thu Jan 04, 2018 12:28 pm

If I understand you correctly, yes. I use the PWM board only for LED/servo control, and use the onboard PWM for sound. The board is really handy if you start running out of GPIO pins. You can daisy-chain a bunch of those boards. As I recall, the address selectors allow 64 boards.

Edit: If I wasn't clear, these boards use the I2C bus to set the pulse width. Only requires two data pins and a ground. Once you set the pulse width, the board does not require any further action to maintain the pulse width until you need to change it. "Set it and forget it".

mattmiller
Posts: 2247
Joined: Thu Feb 05, 2015 11:25 pm

Re: Project: Pi 3 PWM - Control LEDs AND play audio?

Thu Jan 04, 2018 4:49 pm

Might be easier to offload sound output to a USB sound device?

Not tried that approach myself but maybe worth considering

sebar
Posts: 12
Joined: Thu Jan 04, 2018 9:49 am

Re: Project: Pi 3 PWM - Control LEDs AND play audio?

Thu Jan 04, 2018 5:38 pm

@ mattmiller: Yes, thank you for pointing me in that direction. I guess that's also a possibilty. I just want to keep the hardware as simple as possible. Maybe I would use that option as a last resort. First I'd like to explore the Pi's own capabilities (GPIO, HDMI).

@ SurferTim: Same goes for your suggestion. Of course it's not a big deal to attach that board. But is it really necessarry?

So how about this: The Pi's PWM to control the LED panel and its HDMI for sound. That should work, right?

User avatar
joan
Posts: 15090
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Project: Pi 3 PWM - Control LEDs AND play audio?

Thu Jan 04, 2018 5:49 pm

If you are using WS281X based LED strips you need to use either the PWM peripheral or the SPI peripheral. The linked add-on PWM board will not be of any use for any type of LED strip.

If you use the PWM peripheral for your LED strips that still leaves the PCM peripheral available for sound.

User avatar
rpdom
Posts: 17715
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Project: Pi 3 PWM - Control LEDs AND play audio?

Thu Jan 04, 2018 6:00 pm

SurferTim wrote:
Thu Jan 04, 2018 12:28 pm
If I understand you correctly, yes. I use the PWM board only for LED/servo control, and use the onboard PWM for sound. The board is really handy if you start running out of GPIO pins. You can daisy-chain a bunch of those boards. As I recall, the address selectors allow 64 boards.

Edit: If I wasn't clear, these boards use the I2C bus to set the pulse width. Only requires two data pins and a ground. Once you set the pulse width, the board does not require any further action to maintain the pulse width until you need to change it. "Set it and forget it".
The thing is the WS281x strips don't use a PWM input. They need strictly timed serial data. One driver (at least) uses the special mode of the PWM where you can program it with a series of bits to send and it constantly updates that bit pattern. I think an alternative driver uses SPI instead, which might be an option.

EDIT: joan beat me to it :-)

sebar
Posts: 12
Joined: Thu Jan 04, 2018 9:49 am

Re: Project: Pi 3 PWM - Control LEDs AND play audio?

Thu Jan 04, 2018 8:43 pm

Thank you so much for pointing this out to me! That saved me a lot of trouble!
I had to look up the SPI and PCM devices, which brought me here:
https://github.com/jgarff/rpi_ws281x
At the bottom of that page it says pretty much what you two said.
To control the LEDs you can use either PWM or PCM or SPI.
When I started this thread I didn't know these options, because all the tutorials I read only mentioned PWM to control LED panels.
So - once again - the Pi is a swiss army knife!
I consider my questions answered and will have to try it out now :).

mattmiller
Posts: 2247
Joined: Thu Feb 05, 2015 11:25 pm

Re: Project: Pi 3 PWM - Control LEDs AND play audio?

Thu Jan 04, 2018 10:37 pm

Never knew about using SPI to control them - you learn something new everyday :)

Return to “Advanced users”