I would like to use hardware PWM on a GPIO port to generate RC-5 IR codes with an IR LED.

I read that .NET Core now has PWM support and that the Pi has at least one PWM-enabled GPIO pin, but I can find precious little documentation on how to access it. The PwmChannel.Create() method requires a chip number, and passing 0 doesn't work.

I'm hoping that the hardware can provide the 36 kHz carrier signal, and the Stopwatch.GetTimestamp() method should give me sufficient resolution to generate the RC-5 output over it... but I just can't get PwmChannel working.

I would be very glad of any pointers on how to do this... or am I on the wrong track altogether?

  • I read that: ".NET Core 3.1 is supported on the following operating systems: Debian: 9+, ...". Does it mean Raspbian 10 buster is also OK?
    – tlfong01
    Feb 24, 2020 at 3:51
  • 1
    I found Daren May's .NET 3.0 tutorial good. Do you have any other tutorials as good for newbies? - ".NET Core and GPIO on Rpi - Daren May 2019oct16" darenmay.com/blog/….
    – tlfong01
    Feb 24, 2020 at 4:03
  • 1
    I would check that you can generate on off signals accurately at the sub-millisecond rate before you bother adding the carrier. If you check the resulting timings you may find that it can't be done with .NET on the Pi.
    – joan
    Feb 24, 2020 at 8:30
  • 1
    @tlfong01 Apparently so! I installed the latest Raspbian distro and the latest .NET Core runtime successfully. (I have RS232 communication working nicely. It's just the PWM that's proving tricky.)
    – Olly
    Feb 25, 2020 at 13:32
  • @Olly How did you get RS232 working on a Pi? Special hardware?
    – Andreas
    Feb 25 at 12:03

2 Answers 2


After having the same issue, I found the solution. You have to enable PWM in the boot config file.

Add this line to your /boot/config.txt file:


Answer found here.


For me it works without any edits to /boot/config.txt, using .net5, the NuGet package System.Device.Gpio from Microsoft and the standard Raspberry OS. A hardware-PWM-GPIO or a software-PWM-GPIO can both be called with SoftwarePwmChannel:

System.Device.Pwm.Drivers.SoftwarePwmChannel buzzerPwm = new System.Device.Pwm.Drivers.SoftwarePwmChannel(16, 400, 0.5, false, controller, false);

-or (hardware PWM)-

System.Device.Pwm.PwmChannel buzzerPwm = new System.Device.Pwm.Drivers.SoftwarePwmChannel(12, 400, 0.5, false, controller, false);

and then use it with for instance:

buzzer = new Iot.Device.Buzzer.Buzzer(buzzerPwm);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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