rpi PWM control

edited October 2016 in Raspberry PI

I am hoping to use a rpi and this circuit to dim a 240v lightbulb up and down.

does anyone know if this is possible or not?

Cheers Rich

Tagged:

Answers

  • Unfortunately, the Raspberry Pi only has a single PWM channel, which is also used for analog audio at the same time. The code for it is there, but it's really awkward to use, so we're not advertising this functionality anymore. This is how to use it:

    The Pi has only one PWM channel exposed on the pin header, which is furthermore disabled by default, as it is shared with the on-board audio output functionality. To enable it, add the line dtoverlay=pwm to the bottom of the /boot/config.txt file and restart.

    It is currently necessary to use the audio output, however brief, before the PWM channel can be used, since this sets up the required internal clocks. Run e.g. omxplayer example.mp3 from the terminal. (But make sure no sound is being played back while you actually use the PWM channel. Again, those functions share the same underlying hardware.)

    After this, PWM.list() should return pwmchip0/pwm0 and pwmchip0/pwm1. pwmchip0/pwm0 is located on the Pi's header on pin 12, as well as on the right channel of the audio jack. (see pinout) pwmchip0/pwm1 seems to be only accessible on the left channel of the audio jack.

    Unfortunately, the Linux kernel doesn't send out notifications to user-space after a new channel has been requested, which would allow the udev program to change its permissions. Because of this, it is currently necessary to run Processing as the root user to use PWM output.

Sign In or Register to comment.