Hello all i am trying control servo motor usiun dotnet and Unosquare.RaspberryIO
librery. This is my code and whatever I pass to the PayTone
method the motor rotates only in one direction and one speed. I am using Pi 4b
and FeeTech FS90R
motor.
If anyone can help
using Unosquare.RaspberryIO;
using Unosquare.RaspberryIO.Abstractions;
using Unosquare.WiringPi;
namespace projectV2
{
public class ServoController : BaseClass
{
public void Start()
{
Pi.Init<BootstrapWiringPi>();
var pin = Pi.Gpio[12];
pin = Pi.Gpio[BcmPin.Gpio12];
pin.PinMode = GpioPinDriveMode.Output;
System.Device.Pwm.Drivers.SoftwarePwmChannel buzzerPwm =
new System.Device.Pwm.Drivers
.SoftwarePwmChannel(12, 1600, 0.5, false, new System.Device.Gpio.GpioController(), false);
var buzzer = new Iot.Device.Buzzer.Buzzer(buzzerPwm);
buzzer.PlayTone(1000, 1000);
Thread.Sleep(2000);
buzzer.PlayTone(1500, 1000);
Thread.Sleep(2000);
buzzer.PlayTone(2000, 1000);
buzzer.Dispose();
}
}
}
Now I try use System.Device.Gpio
now my code looks like below. The code is executed to the end , but there no result to the gpio 12 (servo does not react )
using System;
using System.Device.Pwm;
using System.Threading.Tasks;
using System.Device.Gpio;
namespace projectV2
{
public class ServoController : BaseClass
{
public async Task Test()
{
ServoMotor servoMotor = new ServoMotor(PwmChannel.Create(0, 0, 50, 0.5));
servoMotor.Start();
servoMotor.WritePulseWidth(1000);
await Task.Delay(2000);
servoMotor.WritePulseWidth(1500);
await Task.Delay(2000);
servoMotor.WritePulseWidth(2000);
servoMotor.Stop();
}
}
}
sudo pigpiod
thenpigs s 12 1000
thenpigs s 12 1400
thenpigs s 12 2000
. What happens?