dotnet / dotnet/iot

RPI4 PWM can't be used with Windows11

Open
#1,640 12 comments 0 reactions 0 assignees View on GitHub
area-System.Device.Gpio blocked Priority:3 tracking-external-issue
Dominant language
C#
Stars
2.4k
Forks
630
Avg merge
11d 3h
Merged PRs (30d)
2

Description

**Describe the bug**
When I execute the Sample code, I get an error message like the following.

Unhandled exception. System.ArgumentException: No PWM device exists for PWM chip at index 0. (Parameter 'chip')
at System.Device.Pwm.Channels.Windows10PwmChannel..ctor(Int32 chip, Int32 channel, Int32 frequency, Double dutyCycle)
at System.Device.Pwm.PwmChannel.CreateWindows10PwmChannel(Int32 chip, Int32 channel, Int32 frequency, Double dutyCyclePercentage)
at System.Device.Pwm.PwmChannel.Create(Int32 chip, Int32 channel, Int32 frequency, Double dutyCyclePercentage)
at GPIOTry.Program.Main(String[] args) in D:\Chester\Project\RPI4\Windows\GPIOTry\GPIOTry\Program.cs:line 16

I changed the boot/config.txt according to "https://github.com/dotnet/iot/blob/main/Documentation/raspi-pwm.md",
But the same problem still occurs.
```csharp
// put sample code here
using System;
using System.Device.Gpio;
using System.Device.I2c;
using System.Device.Spi;
using System.Device.Pwm;
using System.Threading;
namespace GPIOTry
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
var gpiocontroller = new GpioController();

PwmChannel pwmcontroller = PwmChannel.Create(0,0,400,0);
pwmcontroller.Start();
gpiocontroller.OpenPin(2, PinMode.Output);
byte bringth = 0;
try
{
while (true)
{
bringth++;
if (bringth == 11)
bringth = 0;
pwmcontroller.DutyCycle=bringth*0.1;
gpiocontroller.Write(2, PinValue.High);
Console.WriteLine("Duty is " + bringth.ToString());
Console.WriteLine("Set GPIO2 High");
Thread.Sleep(1000);
gpiocontroller.Write(2, PinValue.Low);
Console.WriteLine("Set GPIO2 Low");
Thread.Sleep(1000);
}
}
finally
{
pwmcontroller.Stop();
gpiocontroller.ClosePin(2);
}
}
}
}

Platform: RPI4B
OS: Windows11
System.Device.Gpio: 1.5.0

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.