How to control a servo motor with Windows Remote Arduino?

425 Views Asked by At

I've been playing with the new Remote Wiring libraries on Windows Remote Arduino and I have been unable to control a servo - there is a "PinMode.Servo" option in the library - but the motor does not move reliably, sometimes not at all.

The code is below

namespace UniversalBlink

{ public sealed partial class MainPage : Page { private bool useBluetooth = true;

    BluetoothSerial bluetooth;
    UsbSerial usb;

    RemoteDevice arduino;

    public MainPage()
    {
        this.InitializeComponent();

        if (useBluetooth)
        {
            bluetooth = new BluetoothSerial("HC-06");
            arduino = new RemoteDevice(bluetooth);
            bluetooth.ConnectionEstablished += OnConnectionEstablished;
            //these parameters don't matter for bluetooth
            bluetooth.begin(0, 0);
        }
        else
        {
            usb = new UsbSerial("VID_2341", "PID_0043");   //I've written in my device D directly
            var test = UsbSerial.listAvailableDevicesAsync();                

            arduino = new RemoteDevice(usb);
            usb.ConnectionEstablished += OnConnectionEstablished;
            usb.begin(57600, SerialConfig.SERIAL_8N1);
        }
    }

    private void OnConnectionEstablished()
    {
        //enable the buttons on the UI thread!
        var action = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => {
            OnButton.IsEnabled = true;
            OffButton.IsEnabled = true;
            arduino.pinMode(9, PinMode.SERVO);
        }));
    }       

    private async void OnButton_Click(object sender, RoutedEventArgs e)
    {
        arduino.analogWrite(9, 0);
    }

    private async void OffButton_Click(object sender, RoutedEventArgs e)
    {
        arduino.analogWrite(9, 140);
    }


}

}

I'm at a loss as to where to go from here.

1

There are 1 best solutions below

0
On

The Code use Bluetooth or Serial (via USB) to control an Arduino.