2

I'm working on a pi zero alarm clock project which uses the internal pwm hardware pin for audio generation. There are some tutorials (like this adafruit tutorial) online explaining how to do this, by using the alternative gpio functions.

Now I want to add some WS2812 LEDs for an additional "light wake up function". Those LEDs are very common and easy to control... if you have one spare pwm pin.

I know Raspberry Pi has two different pwm channels, which you can access by using the following alternative functions of the given GPIOs:

GPIO18 ALT5 = PWM0 GPIO19 ALT5 = PWM1 GPIO12 ALT0 = PWM0 GPIO13 ALT0 = PWM1

Using libraries like pigpio or wiringpi I'm able to set those alternative functions and control either the audio generation or the leds. Independent of the pwm channels the applications seem to conflict with each other and switching between applications is just possible after doing a reboot.

Doing some research about this I found some help in the raspberry pi forum, suggesting of adding the following line to the /boot/config.txt file:

force_pwm_open=0

This enables the pi to switch between pwm applications, but using one python script to run my alarm clock still blocks the pwm for controlling the leds after running the ALSA audio module.

Now I'm looking for possible other solutions of how to work around this. Are there some IC which I could use for the generation of an additional pwm channel?

5
  • pigpio can do PWM on all pins... should that not solve the problem?
    – Ghanima
    Feb 9, 2017 at 23:00
  • Here is a hardware alternative adafruit.com/product/815 Feb 9, 2017 at 23:03
  • @Ghanima for controlling the leds I need accurate timing. The pigpio just provides: pi.hardware_PWM(18, 800, 250000) # 800Hz 25% dutycycle, which doesn't allow any precise modulation of the pulse width like I would need it for the leds Therefore I need the true hardware pwm peripheral, which conflicts with the audio module, like described here.
    – Fabs
    Feb 9, 2017 at 23:20
  • That is not what pgipio's feature list describes hardware timed PWM on all of GPIO 0-31 but I'll leave the authorative answer to joan.
    – Ghanima
    Feb 9, 2017 at 23:24
  • joan pointed out in the raspberry pi forums that pigpio is not capable of driving the WS2812B leds
    – Fabs
    Feb 12, 2017 at 17:42

1 Answer 1

1

One possible option, as pointed out by @Steve Robillard, indeed would be the Adafruit 16 Channel PWM Servo Driver, which makes use of the PCA9685 I²C LED Controller.

Since this was too big for my project I decided to buy new LEDs.

The APA102 LEDs come with integrated pwm and are controllable via SPI, which is very easy by using tinues Python code. They come in the same size (5x5mm) such that I could easily replace the WS2812 LEDs.

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.