private void InitFirmata()
    {
      //USB\VID_2A03&PID_0043&REV_0001
      //create a serial connection
      //var devices = await UsbSerial.listAvailableDevicesAsync();
      //var devList = devices.ToList();

      serial = new UsbSerial("VID_2A03", "PID_0043");

      //construct the firmata client
      firmata = new UwpFirmata();
      firmata.FirmataConnectionReady += Firmata_FirmataConnectionReady;
      firmata.StringMessageReceived += Firmata_StringMessageReceived;

      //last, construct the RemoteWiring layer by passing in our Firmata layer.
      arduino = new RemoteDevice(firmata);
      arduino.DeviceReady += Arduino_DeviceReady;

      //if you create the firmata client yourself, don't forget to begin it!
      firmata.begin(serial);

      //you must always call 'begin' on your IStream object to connect.
      //these parameters do not matter for bluetooth, as they depend on the device. However, these are the best params to use for USB, so they are illustrated here
      serial.begin(57600, SerialConfig.SERIAL_8N1);

    }
Example #2
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            System.Diagnostics.Debug.WriteLine("hola");
            playing = false;
            DeviceInformation device = null;

            var result = UsbSerial.listAvailableDevicesAsync().AsTask <DeviceInformationCollection>().Result;

            if (result == null || result.Count == 0)
            {
                throw new InvalidOperationException("No USB FOUND");
            }
            else
            {
                // Assume first
                device = result.FirstOrDefault();
            }

            Connection = new UsbSerial(device);

            Firmata = new UwpFirmata();
            Firmata.begin(Connection);
            Arduino = new RemoteDevice(Firmata);
            Connection.ConnectionEstablished += OnConnectionEstablished;

            Connection.begin(BAUD_RATE, SerialConfig.SERIAL_8N1);
        }
Example #3
0
        private async void grid1_Loaded(object sender, RoutedEventArgs e)
        {
            var devices = await UsbSerial.listAvailableDevicesAsync();

            int idx = -1;

            for (int i = 0; i < devices.Count; i++)
            {
                if (devices[i].Name.StartsWith("Arduino"))
                {
                    idx = i;
                }
            }

            if (idx != -1)
            {
                usbSerial = new UsbSerial(devices[idx]);
                firmata   = new UwpFirmata();
                arduino   = new RemoteDevice(firmata);
                firmata.begin(usbSerial);
                //arduino.DeviceReady += OnDeviceReady;
                //usbSerial.ConnectionEstablished += OnDeviceReady;
                firmata.FirmataConnectionReady += OnDeviceReady;
                //arduino.SysexMessageReceived += DataRecieved;
                firmata.SysexMessageReceived          += Firmata_SysexMessageReceived;
                firmata.PinCapabilityResponseReceived += Firmata_PinCapabilityResponseReceived;
                firmata.DigitalPortValueUpdated       += Firmata_DigitalPortValueUpdated;
                usbSerial.begin(57600, SerialConfig.SERIAL_8N1);
            }
        }
Example #4
0
        /// <summary>
        /// This page uses advanced features of the Windows Remote Arduino library to carry out custom commands which are
        /// defined in the NeoPixel_StandardFirmata.ino sketch. This is a customization of the StandardFirmata sketch which
        /// implements the Firmata protocol. The customization defines the behaviors of the custom commands invoked by this page.
        ///
        /// To learn more about Windows Remote Arduino, refer to the GitHub page at: https://github.com/ms-iot/remote-wiring/
        /// To learn more about advanced behaviors of WRA and how to define your own custom commands, refer to the
        /// advanced documentation here: https://github.com/ms-iot/remote-wiring/blob/develop/advanced.md
        /// </summary>
        public MainPage()
        {
            this.InitializeComponent();
            timer          = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(80);
            timer.Tick    += SetAllPixelsRandomly;

            timer2          = new DispatcherTimer();
            timer2.Interval = TimeSpan.FromMilliseconds(100);
            timer2.Tick    += CyclePixels;

            timer3          = new DispatcherTimer();
            timer3.Interval = TimeSpan.FromMilliseconds(100);
            timer3.Tick    += BlendPixels;

            timer4          = new DispatcherTimer();
            timer4.Interval = TimeSpan.FromMilliseconds(50);
            timer4.Tick    += SetPixelsByVolume;

            //blendedRainbow =  initBlend(100);
            //initGraph();
            initMedia();
            InitGPIO();
            firmata = App.Firmata;
        }
Example #5
0
 private async void Firmata_StringMessageReceived(UwpFirmata caller, StringCallbackEventArgs argv)
 {
     var content = argv.getString();
     await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         this.ReadingTextBlock.Text = content;
     });
 }
Example #6
0
        public NeoPixel(UwpFirmata firmata, byte pin, byte led_count)
        {
            this.firmata = firmata;
            this.pin     = pin;
            this.leds    = led_count;

            NeoPixelRegister(this.pin, this.leds);
        }
Example #7
0
        /// <summary>
        /// Sends a blob of pixel data to the client, broken up into arbitraily sized chunks
        /// </summary>
        /// <param name="firmata">Firmata client to send the command to</param>
        /// <param name="bytes">Pixel data to send</param>
        /// <param name="inSetsOf">How many bytes to send in a single firmata command</param>
        public static void SendPixelBlob(this UwpFirmata firmata, IEnumerable <byte> bytes, int inSetsOf)
        {
            if (inSetsOf == 0)
            {
                firmata.SendPixelBlob(bytes);
                return;
            }

            bytes.InSetsOf(inSetsOf).ForEach(firmata.SendPixelBlob);
            firmata.flush();
        }
Example #8
0
        public const byte SYSEX_BLOB_COMMAND = 0x7C; // send a series of 7-bit resolution characters

        /// <summary>
        /// Sends a blob of pixel data to the client
        /// </summary>
        /// <param name="firmata">Firmata client to send the command to</param>
        /// <param name="bytes">Pixel data to send</param>
        public static void SendPixelBlob(this UwpFirmata firmata, IEnumerable <byte> bytes)
        {
            firmata.write((byte)Command.START_SYSEX);
            firmata.write(SYSEX_BLOB_COMMAND);

            foreach (byte b in bytes)
            {
                firmata.write(b);
            }

            firmata.write((byte)Command.END_SYSEX);
        }
Example #9
0
 public async Task CaptureReadings()
 {
     await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         this.bluetooth = new BluetoothSerial("RNBT-9E86");
         this.firmata = new UwpFirmata();
         this.firmata.FirmataConnectionReady += Firmata_FirmataConnectionReady;
         this.firmata.StringMessageReceived += Firmata_StringMessageReceived;
         this.device = new RemoteDevice(firmata);
         this.firmata.begin(bluetooth);
         bluetooth.begin(9600, SerialConfig.SERIAL_8N1);
     });
 }
Example #10
0
        /// <summary>
        /// This page uses advanced features of the Windows Remote Arduino library to carry out custom commands which are
        /// defined in the NeoPixel_StandardFirmata.ino sketch. This is a customization of the StandardFirmata sketch which
        /// implements the Firmata protocol. The customization defines the behaviors of the custom commands invoked by this page.
        ///
        /// To learn more about Windows Remote Arduino, refer to the GitHub page at: https://github.com/ms-iot/remote-wiring/
        /// To learn more about advanced behaviors of WRA and how to define your own custom commands, refer to the
        /// advanced documentation here: https://github.com/ms-iot/remote-wiring/blob/develop/advanced.md
        /// </summary>
        public MainPage()
        {
            this.InitializeComponent();
            firmata = App.Firmata;


            Unloaded += MainPage_Unloaded;

            //accelerometer
            InitAccel();

            //audio
            CreateAudioGraph();

            //buttons
            InitGPIO();
        }
Example #11
0
        public static async void Init()
        {
            var deviceList = await UsbSerial.listAvailableDevicesAsync();
            var device = deviceList.First();
            connection = new UsbSerial(device);
            firmata = new UwpFirmata();
            firmata.begin(connection);
            App.Arduino = new RemoteDevice(firmata);

            connection.ConnectionEstablished += OnConnectionEstablished;
            connection.ConnectionFailed += OnConnectionFailed;
            connection.begin(115200, SerialConfig.SERIAL_8N1);

            //start a timer for connection timeout
            timeout = new DispatcherTimer();
            timeout.Interval = new TimeSpan(0, 0, 30);
            timeout.Tick += Connection_TimeOut;
            timeout.Start();
        }
Example #12
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            usb = new UsbSerial("VID_2341", "PID_0042");//Arduino MEGA

            //construct the firmata client
            firmata = new UwpFirmata();
            arduino = new RemoteDevice(firmata);
            firmata.begin(usb);

            //we do not care about inputs in this example
            //firmata.startListening();

            usb.begin(115200, SerialConfig.SERIAL_8N1);
            arduino.DeviceReady            += Stepper_Usb_ConnectionEstablished; //usb.ConnectionEstablished
            arduino.DeviceReady            += Drive_Usb_ConnectionEstablished;   //usb.ConnectionEstablished
            arduino.DeviceConnectionFailed += Arduino_DeviceConnectionFailed;

            deferral = taskInstance.GetDeferral();
            //pwmController = (await PwmController.GetControllersAsync(PwmPCA9685.PwmProviderPCA9685.GetPwmProvider()))[0];
            //pwmController.SetDesiredFrequency(300); // Check if this is the correct frequency for Talon
            //motorPin = pwmController.OpenPin(13);
            //drive.RampUp(motorPin, .34);
            drive = new FirmataDriveController(firmata);
            step  = new StepperController(firmata);

            var carImpl = new CarImplementation(step, drive);

            carRC.implementation = carImpl;


            await Task.Run(async() =>
            {
                while (!stepperUsbSetup && !driveUsbSetup)
                {
                    //wait
                    await Task.Delay(1);
                }

                carRC.Start();
            });
        }
Example #13
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            // Create Firmata
            this.mkr1000_firmata = new UwpFirmata();

            //Create MKR1000 Device
            mkr1000 = new Microsoft.Maker.RemoteWiring.RemoteDevice(mkr1000_firmata);

            //Establish a network serial connection. change it to the right IP address and port
            wificonnection = new Microsoft.Maker.Serial.NetworkSerial(new Windows.Networking.HostName("192.168.1.42"), 3030);

            //Attach event handlers
            wificonnection.ConnectionEstablished += NetWorkSerial_ConnectionEstablished;
            wificonnection.ConnectionFailed      += NetWorkSerial_ConnectionFailed;

            //Begin Firmata
            mkr1000_firmata.begin(wificonnection);

            //Begin connection
            wificonnection.begin(115200, Microsoft.Maker.Serial.SerialConfig.SERIAL_8N1);
        }
        private void button_Click(object sender, RoutedEventArgs e)
        {
            // Create Firmata
            this.mkr1000_firmata = new UwpFirmata();

            //Create MKR1000 Device
            mkr1000 = new Microsoft.Maker.RemoteWiring.RemoteDevice(mkr1000_firmata);

            //Establish a network serial connection. change it to the right IP address and port
            wificonnection = new Microsoft.Maker.Serial.NetworkSerial(new Windows.Networking.HostName("192.168.1.42"), 3030);

            //Attach event handlers
            wificonnection.ConnectionEstablished += NetWorkSerial_ConnectionEstablished;
            wificonnection.ConnectionFailed += NetWorkSerial_ConnectionFailed;

            //Begin Firmata
            mkr1000_firmata.begin(wificonnection);

            //Begin connection
            wificonnection.begin(115200, Microsoft.Maker.Serial.SerialConfig.SERIAL_8N1);
        }
Example #15
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            System.Diagnostics.Debug.WriteLine("hi");
            //
            // TODO: Insert code to start one or more asynchronous methods
            //

            playing = false;
            DeviceInformation device = null;

            var result = UsbSerial.listAvailableDevicesAsync().AsTask <DeviceInformationCollection>().Result;

            if (result == null || result.Count == 0)
            {
                throw new InvalidOperationException("No USB FOUND");
            }
            else
            {
                // Assume first
                // TODO: Might not be first.
                device = result.FirstOrDefault();
            }
            WriteLine("device name: " + device.Name);
            Connection = new UsbSerial(device);

            Firmata = new UwpFirmata();
            Firmata.begin(Connection);
            Arduino = new RemoteDevice(Firmata);
            Connection.ConnectionEstablished += OnConnectionEstablished;



            Connection.begin(BAUD_RATE, SerialConfig.SERIAL_8N1);


            // Begin Recording from mic.
            this.StartRecording();
        }
Example #16
0
        public ConnectionPage()
        {
            playing = false;
            this.InitializeComponent();
            ConnectionMethodComboBox.SelectionChanged += ConnectionComboBox_SelectionChanged;

            Task <DeviceInformationCollection> task = null;
            DeviceInformation device = null;

            task = UsbSerial.listAvailableDevicesAsync().AsTask <DeviceInformationCollection>();
            //task.Wait();

            var result = task.Result;



            if (result == null || result.Count == 0)
            {
                throw new InvalidOperationException("No USB FOUND");
            }
            else
            {
                // Assume first
                device = result.FirstOrDefault();
            }

            Connection = new UsbSerial(device);

            Firmata = new UwpFirmata();
            Firmata.begin(Connection);
            Arduino = new RemoteDevice(Firmata);
            Connection.ConnectionEstablished += OnConnectionEstablished;
            Connection.begin(115200, SerialConfig.SERIAL_8N1);

            //for (int i = 0; i < 500; i++)
            //    System.Diagnostics.Debug.WriteLine(i);
        }
Example #17
0
        /// <summary>
        /// This page uses advanced features of the Windows Remote Arduino library to carry out custom commands which are
        /// defined in the NeoPixel_StandardFirmata.ino sketch. This is a customization of the StandardFirmata sketch which
        /// implements the Firmata protocol. The customization defines the behaviors of the custom commands invoked by this page.
        /// 
        /// To learn more about Windows Remote Arduino, refer to the GitHub page at: https://github.com/ms-iot/remote-wiring/
        /// To learn more about advanced behaviors of WRA and how to define your own custom commands, refer to the
        /// advanced documentation here: https://github.com/ms-iot/remote-wiring/blob/develop/advanced.md
        /// </summary>
        public MainPage()
        {
            
            this.InitializeComponent();
            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(80);
            timer.Tick += SetAllPixelsRandomly;

            timer2 = new DispatcherTimer();
            timer2.Interval = TimeSpan.FromMilliseconds(100);
            timer2.Tick += CyclePixels;

            timer3 = new DispatcherTimer();
            timer3.Interval = TimeSpan.FromMilliseconds(100);
            timer3.Tick += BlendPixels;

            timer4 = new DispatcherTimer();
            timer4.Interval = TimeSpan.FromMilliseconds(50);
            timer4.Tick += SetPixelsByVolume;

            //blendedRainbow =  initBlend(100);
            //initGraph();
            initMedia();
            InitGPIO();
            firmata = App.Firmata;
        }
Example #18
0
 private void Firmata_PinCapabilityResponseReceived(UwpFirmata caller, SysexCallbackEventArgs argv)
 {
     byte cmd = argv.getCommand();
 }
Example #19
0
 /// <summary>
 /// This page uses advanced features of the Windows Remote Arduino library to carry out custom commands which are
 /// defined in the NeoPixel_StandardFirmata.ino sketch. This is a customization of the StandardFirmata sketch which
 /// implements the Firmata protocol. The customization defines the behaviors of the custom commands invoked by this page.
 ///
 /// To learn more about Windows Remote Arduino, refer to the GitHub page at: https://github.com/ms-iot/remote-wiring/
 /// To learn more about advanced behaviors of WRA and how to define your own custom commands, refer to the
 /// advanced documentation here: https://github.com/ms-iot/remote-wiring/blob/develop/advanced.md
 /// </summary>
 public MainPage()
 {
     this.InitializeComponent();
     firmata = App.Firmata;
 }
Example #20
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            System.Diagnostics.Debug.WriteLine("hola");
            playing = false;
            DeviceInformation device = null;

            var result = UsbSerial.listAvailableDevicesAsync().AsTask<DeviceInformationCollection>().Result;

            if (result == null || result.Count == 0)
            {
                throw new InvalidOperationException("No USB FOUND");
            }
            else
            {
                // Assume first
                device = result.FirstOrDefault();
            }

            Connection = new UsbSerial(device);

            Firmata = new UwpFirmata();
            Firmata.begin(Connection);
            Arduino = new RemoteDevice(Firmata);
            Connection.ConnectionEstablished += OnConnectionEstablished;

            Connection.begin(BAUD_RATE, SerialConfig.SERIAL_8N1);
        }
Example #21
0
 private void Firmata_DigitalPortValueUpdated(UwpFirmata caller, CallbackEventArgs argv)
 {
     byte port = argv.getPort();
 }
Example #22
0
 public FirmataDriveController(UwpFirmata firmataIn)
 {
     firmata = firmataIn;
 }
Example #23
0
 private void Firmata_SysexMessageReceived(UwpFirmata caller, SysexCallbackEventArgs argv)
 {
     rcvCmd  = Convert.ToInt32(argv.getCommand());
     rcvData = argv.getDataBuffer().ToArray();
 }
 /// <summary>
 /// This page uses advanced features of the Windows Remote Arduino library to carry out custom commands which are
 /// defined in the NeoPixel_StandardFirmata.ino sketch. This is a customization of the StandardFirmata sketch which
 /// implements the Firmata protocol. The customization defines the behaviors of the custom commands invoked by this page.
 /// 
 /// To learn more about Windows Remote Arduino, refer to the GitHub page at: https://github.com/ms-iot/remote-wiring/
 /// To learn more about advanced behaviors of WRA and how to define your own custom commands, refer to the
 /// advanced documentation here: https://github.com/ms-iot/remote-wiring/blob/develop/advanced.md
 /// </summary>
 public MainPage()
 {
     this.InitializeComponent();
     firmata = App.Firmata;
 }
Example #25
0
        public ConnectionPage()
        {
            playing = false;
            this.InitializeComponent();
            ConnectionMethodComboBox.SelectionChanged += ConnectionComboBox_SelectionChanged;

            Task<DeviceInformationCollection> task = null;
            DeviceInformation device = null;

            task = UsbSerial.listAvailableDevicesAsync().AsTask<DeviceInformationCollection>();
            //task.Wait();

            var result = task.Result;



            if (result == null || result.Count == 0)
            {
                throw new InvalidOperationException("No USB FOUND");
            }
            else
            {
                // Assume first
                device = result.FirstOrDefault();
            }

            Connection = new UsbSerial(device);

            Firmata = new UwpFirmata();
            Firmata.begin(Connection);
            Arduino = new RemoteDevice(Firmata);
            Connection.ConnectionEstablished += OnConnectionEstablished;
            Connection.begin(115200, SerialConfig.SERIAL_8N1);

            //for (int i = 0; i < 500; i++)
            //    System.Diagnostics.Debug.WriteLine(i);

        }
Example #26
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            System.Diagnostics.Debug.WriteLine("hi");
            // 
            // TODO: Insert code to start one or more asynchronous methods 
            //
            
            playing = false;
            DeviceInformation device = null;

            var result = UsbSerial.listAvailableDevicesAsync().AsTask<DeviceInformationCollection>().Result;

            if (result == null || result.Count == 0)
            {
                throw new InvalidOperationException("No USB FOUND");
            }
            else
            {
                // Assume first
                // TODO: Might not be first.
                device = result.FirstOrDefault();
            }
            WriteLine("device name: " + device.Name);
            Connection = new UsbSerial(device);

            Firmata = new UwpFirmata();
            Firmata.begin(Connection);
            Arduino = new RemoteDevice(Firmata);
            Connection.ConnectionEstablished += OnConnectionEstablished;


            
            Connection.begin(BAUD_RATE, SerialConfig.SERIAL_8N1);


            // Begin Recording from mic.
            this.StartRecording();

            
        }
Example #27
0
 public StepperController(UwpFirmata firmataIn)
 {
     firmata = firmataIn;
 }
 /// <summary>
 /// This is just used for some brute force debugging.  I have added various 
 ///
 ///  Firmata.sendMessage("...."); 
 /// 
 /// statements to the sketch deployed to the arduino to get feedback when
 ///  things are happening on the arduino.
 /// </summary>
 /// <param name="caller"></param>
 /// <param name="argv"></param>
 private async void Firmata_StringMessageReceived(UwpFirmata caller, StringCallbackEventArgs argv)
 {
   string message = argv.getString();
   FirmataMessage firmataMessage = new FirmataMessage(message);
   Debug.WriteLine(firmataMessage);
   await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => {
     //Add the message to the top of the list so that most recent messages appear at the top
     Messages.Insert(0, firmataMessage);
   }));            
 }