0

Hello all i am trying control servo motor usiun dotnet and Unosquare.RaspberryIO librery. This is my code and whatever I pass to the PayTonemethod 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();

        }
    }
}

enter image description here

enter image description here


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();
        }
    }
}
9
  • You need to give the servo 50 pulses per second (each between 1 and 2 milliseconds long). Are you?
    – joan
    Jan 9 at 18:56
  • All i do is the code above.I am very new in that
    – Darkk L
    Jan 9 at 21:03
  • Assuming GPIO 12 try the following. sudo pigpiod then pigs s 12 1000 then pigs s 12 1400 then pigs s 12 2000. What happens?
    – joan
    Jan 9 at 22:05
  • I try it , but the result is the same , only one direction
    – Darkk L
    Jan 10 at 18:50
  • Either a faulty servo or you have not connected it to the correct GPIO.
    – joan
    Jan 10 at 18:55

1 Answer 1

0

The .NET library you are using is based on WiringPi which has been deprecated for almost 2 years. The Pi4 version of WiringPi was never released in source so it is unlikely the unofficial port in the library you are using is fully operational.

I believe there is a version based on pigpio which would be a better option.

1
  • Now I approach it differently , but again I have no success, the code is a above
    – Darkk L
    Jan 11 at 7:12

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.