MSDN Community

Configuring GPIO on Raspberry Pi 4 (Windows IoT)
Hi everyone,

I'm trying to control a PWM LED on the GPIO pins of my Raspberry Pi 4 running Windows IoT Core. I followed the docs but the LED just stays off. Has anyone managed to get PWM working on this board?

Thanks!
Make sure you enable the GPIO controller in the Device Manager. Also, use the PwmController class from the Windows.Devices.Pwm namespace. Here's a quick snippet:
using Windows.Devices.Pwm;
var pwm = PwmController.GetDefault();
pwm.SetDesiredFrequency(1000);
var pin = pwm.OpenPin(18);
pin.SetActiveDutyCyclePercentage(0.5);
pin.Start();
That should give you a 50% duty cycle at 1 kHz.
I ran into an issue where the PWM pin defaults to input mode. You need to call pin.SetActiveDutyCyclePercentage after pin.Start() and ensure the pin number matches the board layout (GPIO18 is pin 12 on the header).

Also, don't forget to add the capability in the app manifest:
<DeviceCapability Name="gpio">
    <Device Id="any">
        <Function Type="gpio"></Function>
    </Device>
</DeviceCapability>

Post a Reply