Beispiel #1
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            // Get the deferral instance
            deferral = taskInstance.GetDeferral();

            // Instantiate the sensors and actuators
            buzzer  = DeviceFactory.Build.Buzzer(Pin.DigitalPin2);
            button  = DeviceFactory.Build.ButtonSensor(Pin.DigitalPin4);
            blueLed = DeviceFactory.Build.Led(Pin.DigitalPin5);
            redLed  = DeviceFactory.Build.Led(Pin.DigitalPin6);

            soundSensor = DeviceFactory.Build.SoundSensor(Pin.AnalogPin0);
            lightSensor = DeviceFactory.Build.LightSensor(Pin.AnalogPin2);

            display = DeviceFactory.Build.RgbLcdDisplay();

            // The IO to the GrovePi sensors and actuators can generate a lot
            // of exceptions - wrap all GrovePi API calls in try/cath statements.
            try {
                // Set the RGB backlight to red and display a message
                display.SetBacklightRgb(255, 0, 0);
                display.SetText("The Thingy is getting started");
            }
            catch (Exception ex)
            {
                // On Error, Resume Next :)
            }

            // Start a timer to check the sensors and activate the actuators five times per second
            timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromMilliseconds(200));
        }
Beispiel #2
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            // Connect the RGB display to one of the I2C ports.
            IRgbLcdDisplay display = DeviceFactory.Build.RgbLcdDisplay();

            // Send out some diagnostics into the debug Output.
            System.Diagnostics.Debug.WriteLine("Hello from Dexter Industries!");
            System.Diagnostics.Debug.WriteLine("Connect the LCD Screen to any I2C port on the GrovePi.");

            // Loop endlessly
            while (true)
            {
                Task.Delay(100).Wait();     // Delay 0.1 second
                                            // We need to make sure we delay here.  If we don't, we won't be able to read
                                            // the LCD Screen.
                try
                {
                    // First, output to the LCD Display.
                    display.SetText("Hello from Dexter Industries!").SetBacklightRgb(255, 50, 255);
                    // Then output to the debug window.
                    System.Diagnostics.Debug.WriteLine("Hello from Dexter Industries!");
                }
                catch (Exception ex)
                {
                    // NOTE: There are frequent exceptions of the following:
                    // WinRT information: Unexpected number of bytes was transferred. Expected: '. Actual: '.
                    // This appears to be caused by the rapid frequency of writes to the GPIO
                    // These are being swallowed here/

                    // If you want to see the exceptions uncomment the following:
                    // System.Diagnostics.Debug.WriteLine(ex.ToString());
                }
            }
        }
        private void InitGrovePi()
        {
            System.Diagnostics.Debug.WriteLine(DeviceFactory.Build.GrovePi().GetFirmwareVersion());

            GroveRotary = DeviceFactory.Build.RotaryAngleSensor(Pin.AnalogPin0);
            GroveSound  = DeviceFactory.Build.SoundSensor(Pin.AnalogPin1);
            GroveLight  = DeviceFactory.Build.LightSensor(Pin.AnalogPin2);

            GroveRelay    = DeviceFactory.Build.Relay(Pin.DigitalPin2);
            GroveTempHumi = DeviceFactory.Build.DHTTemperatureAndHumiditySensor(Pin.DigitalPin3, DHTModel.Dht11);
            GroveRanger   = DeviceFactory.Build.UltraSonicSensor(Pin.DigitalPin4);
            GroveLedBar   = DeviceFactory.Build.BuildLedBar(Pin.DigitalPin5);
            GroveBuzzer   = DeviceFactory.Build.Buzzer(Pin.DigitalPin6);
            GroveButton   = DeviceFactory.Build.ButtonSensor(Pin.DigitalPin7);
            GroveLCD      = DeviceFactory.Build.RgbLcdDisplay();

            GroveLedBar.Initialize(GrovePi.Sensors.Orientation.GreenToRed);
            GroveLCD.SetBacklightRgb(255, 50, 255);

            DeviceFactory.Build.GrovePi().PinMode(Pin.DigitalPin2, PinMode.Output);
            Delay.Milliseconds(10);
            DeviceFactory.Build.GrovePi().Flush();

            DeviceFactory.Build.GrovePi().PinMode(Pin.DigitalPin6, PinMode.Output);
            Delay.Milliseconds(10);
            DeviceFactory.Build.GrovePi().Flush();
        }
Beispiel #4
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            deferral = taskInstance.GetDeferral();

            // Connect the RGB display to one of the I2C ports
            display = DeviceFactory.Build.RgbLcdDisplay();

            // Create a timer that will 'tick' every half-second (500ms)
            timer = ThreadPoolTimer.CreatePeriodicTimer(this.Timer_Tick, TimeSpan.FromSeconds(1));
        }
Beispiel #5
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            deferral = taskInstance.GetDeferral();

            // Connect the RGB display to one of the I2C ports
            display = DeviceFactory.Build.RgbLcdDisplay();

            // Create a timer that will 'tick' every half-second (500ms)
            timer = ThreadPoolTimer.CreatePeriodicTimer(this.Timer_Tick, TimeSpan.FromSeconds(1));
        }
Beispiel #6
0
        public MainPage()
        {
            this.InitializeComponent();

            deviceClient   = DeviceClient.Create(iotHubUri, new DeviceAuthenticationWithRegistrySymmetricKey("GrovePiSoundSensor", deviceKey), TransportType.Http1);
            soundsensor    = DeviceFactory.Build.SoundSensor(Pin.AnalogPin0);
            lcd            = DeviceFactory.Build.RgbLcdDisplay().SetText("Hello").SetBacklightRgb(0, 0, 255);
            timer          = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(5000);
            timer.Tick    += Timer_Tick;
            timer.Start();
        }
Beispiel #7
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            System.Diagnostics.Debug.WriteLine("Starting program!");

            // The RGB display is an I2C device and can be connected to any one of the I2C ports.
            IRgbLcdDisplay rgbdisplay = DeviceFactory.Build.RgbLcdDisplay();

            // Connect the Light Sensor to analog port 1
            IRotaryAngleSensor lightsensor = DeviceFactory.Build.RotaryAngleSensor(Pin.AnalogPin1);
            double             brightness  = 0;

            // Loop endlessly
            while (true)
            {
                try
                {
                    // Check the value of the button.
                    brightness = lightsensor.SensorValue();

                    // Print out Brightness to Debug.
                    System.Diagnostics.Debug.WriteLine("Raw Brightness is: " + brightness.ToString());

                    // Typecase the double to byte for the automatic brightness function!
                    byte brightbyte = (byte)brightness; // The SetBacklightRgb function takes a byte type.
                    // Set the display based on the light levels.
                    rgbdisplay.SetBacklightRgb(brightbyte, brightbyte, brightbyte);

                    // Use a StringBuilder to assemble the display text
                    StringBuilder lightstring = new StringBuilder();

                    // Print the value of the light sensor to the LCD Screen.
                    lightstring.Append(brightness.ToString());
                    System.Diagnostics.Debug.WriteLine("Display: " + lightstring.ToString());
                    rgbdisplay.SetText(lightstring.ToString());
                }
                catch (Exception ex)
                {
                    // NOTE: There are frequent exceptions of the following:
                    // WinRT information: Unexpected number of bytes was transferred. Expected: '. Actual: '.
                    // This appears to be caused by the rapid frequency of writes to the GPIO
                    // These are being swallowed here/

                    // If you want to see the exceptions uncomment the following:
                    // System.Diagnostics.Debug.WriteLine(ex.ToString());
                }

                // Delay in here to allow you to read the light sensor value.
                // If you don't include a short delay, the LCD screen will appear to be blank!
                Task.Delay(500).Wait(); //Delay 1 second
            }
        }
Beispiel #8
0
        public MainPage()
        {
            this.InitializeComponent();

            // initialise database
            try
            {
                db = new MySqlConnection("server=us-cdbr-azure-central-a.cloudapp.net;uid=b0a941f833069a;pwd=41561c96;database=as_eb778c54b5aa1fa;SslMode=None;charset=utf8;");
                db.Open();
            }
            catch (Exception e)
            {
                Debug.WriteLine("Failed to connect to db : " + e.Message);
            }

            // colors
            Blue = new SolidColorBrush(Colors.Blue);
            Green = new SolidColorBrush(Colors.Green);
            Red = new SolidColorBrush(Colors.Red);
            Gray = new SolidColorBrush(Colors.Gray);

            // initialise hardware
            _deviceFactory = DeviceFactory.Build;
            Display = _deviceFactory.RgbLcdDisplay();
            Button = _deviceFactory.ButtonSensor(Pin.DigitalPin8);
            BlueLed = _deviceFactory.Led(Pin.DigitalPin2);
            GreenLed = _deviceFactory.Led(Pin.DigitalPin3);
            RedLed = _deviceFactory.Led(Pin.DigitalPin4);
            LightSensor = _deviceFactory.LightSensor(Pin.AnalogPin2);

            // line info
            CurrentWeight = LightSensor.SensorValue();
            CurrentLine = 2;
            dbSet(CurrentLine);

            // update UI
            WeightText.Text = CurrentWeight.ToString();

            // LED tests
            DispatcherTimer time = new DispatcherTimer();
            time.Interval = TimeSpan.FromMilliseconds(5);
            time.Tick += tick;
            time.Start();

            // light sensor to simulate weight
            DispatcherTimer weightUpdater = new DispatcherTimer();
            weightUpdater.Interval = TimeSpan.FromSeconds(30);
            weightUpdater.Tick += updateWeight;
            weightUpdater.Start();
        }
Beispiel #9
0
        public Pi()
        {
            var builder = DeviceFactory.Build;

            _display = builder.RgbLcdDisplay();

            _light = builder.LightSensor(Pin.AnalogPin0);

            _led = builder.Led(Pin.DigitalPin7);
            //_temp = builder.TemperatureAndHumiditySensor(Pin.AnalogPin1, TemperatureAndHumiditySensorModel.DHT11);

            _ultrasonicRanger = builder.UltraSonicSensor(Pin.DigitalPin3);

            _button = builder.ButtonSensor(Pin.DigitalPin2);
            //_buzzer = builder.Buzzer(Pin.DigitalPin3);
        }
Beispiel #10
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

            display = DeviceFactory.Build.RgbLcdDisplay();
            client  = DeviceClient.CreateFromConnectionString(DEVICEC_CONNECTION_STRING, TransportType.Amqp);

            SetDisplayToOK();

            //Setup C2D message receiver
            Task.Run(async() =>
            {
                await SetupCloudToDeviceMessageReceiver();
            });

            //setup D2C message sender
            SetupDeviceToCloudSensorDataSender();

            deferral.Complete();
        }
Beispiel #11
0
        bool lcdIsGreen = true; // initial state

        private void InitializeGrove()
        {
            try
            {
                string groveVersion = DeviceFactory.Build.GrovePi().GetFirmwareVersion();
                Debug.WriteLine(groveVersion);
                sensor  = DeviceFactory.Build.DHTTemperatureAndHumiditySensor(Pin.DigitalPin4, DHTModel.Dht11);
                display = DeviceFactory.Build.RgbLcdDisplay();

                //Initialize LCD to Green
                SetLcdGreen(true);
                SetLcdText("You did it bro.");
                GroveStatus.Text = "Grove gone done and initted.";
            }
            catch (Exception e)
            {
                Debug.WriteLine("Grove not found :" + e.ToString());
                GroveStatus.Text = "Grove not found.";
                display          = null;
                sensor           = null;
            }
        }
 public void Run(IBackgroundTaskInstance taskInstance)
 {
     deferral    = taskInstance.GetDeferral();
     buzzer      = DeviceFactory.Build.Buzzer(Pin.DigitalPin2);
     button      = DeviceFactory.Build.ButtonSensor(Pin.DigitalPin4);
     blueLed     = DeviceFactory.Build.Led(Pin.DigitalPin5);
     redLed      = DeviceFactory.Build.Led(Pin.DigitalPin6);
     lightSensor = DeviceFactory.Build.LightSensor(Pin.AnalogPin2);
     display     = DeviceFactory.Build.RgbLcdDisplay();
     buttonState = SensorStatus.Off;
     try
     {
         display.SetBacklightRgb(255, 0, 0);
         display.SetText("Hey Web Summit");
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Write("Something happened: " + ex.ToString());
         throw;
     }
     timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromMilliseconds(200));
 }
Beispiel #13
0
        /// <summary>
        /// Main page constructor
        /// </summary>
        public MainPage()
        {
            this.InitializeComponent();

            // Hard coding guid for sensors. Not an issue for this particular application which is meant for testing and demos
            List <ConnectTheDotsSensor> sensors = new List <ConnectTheDotsSensor> {
                new ConnectTheDotsSensor("2298a348-e2f9-4438-ab23-82a3930662ab", "Sound", "Amp"),
            };

            ctdHelper = new ConnectTheDotsHelper(serviceBusNamespace: ConnectionStrings.ServicebusNamespaceDefault,
                                                 eventHubName: ConnectionStrings.EventHubNameDefault,
                                                 keyName: ConnectionStrings.KeyNameDefault,
                                                 key: ConnectionStrings.KeyDefault,
                                                 displayName: ConnectionStrings.DisplayNameDefault,
                                                 organization: ConnectionStrings.OrganizationDefault,
                                                 location: ConnectionStrings.LocationDefault,
                                                 sensorList: sensors);
            soundsensor    = DeviceFactory.Build.SoundSensor(Pin.AnalogPin0);
            lcd            = DeviceFactory.Build.RgbLcdDisplay().SetText("Hello").SetBacklightRgb(0, 0, 255);
            timer          = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(5000);
            timer.Tick    += Timer_Tick;
            timer.Start();
        }
Beispiel #14
0
        //------------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Constructor
        //------------------------------------------------------------------------------------------------------------------------
        public LCD()
        {
            display = DeviceFactory.Build.RgbLcdDisplay();
        }
Beispiel #15
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            // LCD - This screen is I2C
            IRgbLcdDisplay LCD = DeviceFactory.Build.RgbLcdDisplay();

            LCD.SetBacklightRgb(255, 255, 255);
            LCD.SetText("Hello world!"); // Not sure what colour this will show up in

            // LEDs
            ILed red  = DeviceFactory.Build.Led(Pin.DigitalPin2);
            ILed blue = DeviceFactory.Build.Led(Pin.DigitalPin3);

            // Ultrasonic
            IUltrasonicRangerSensor Ultrasonic = DeviceFactory.Build.UltraSonicSensor(Pin.DigitalPin4);

            // Temperature and Humidity
            // TODO: Double check Sensor model number. Assumed DHT11 from the GrovePi+ Starter Kit
            IDHTTemperatureAndHumiditySensor tempHumidity = DeviceFactory.Build.DHTTemperatureAndHumiditySensor(Pin.DigitalPin5, DHTModel.Dht11);

            // Sound sensor
            ISoundSensor Sound = DeviceFactory.Build.SoundSensor(Pin.AnalogPin0);

            // LDR
            IRotaryAngleSensor LDR = DeviceFactory.Build.RotaryAngleSensor(Pin.AnalogPin1);

            while (true)
            {
                Task.Delay(100).Wait();

                try
                {
                    // Ultrasonic sensor
                    int distance = Ultrasonic.MeasureInCentimeters();
                    Debug.WriteLine("Distance: " + distance.ToString());
                    // TODO - tune to distance of door
                    //if(distance < 50)

                    // LDR
                    int lightLevel = LDR.SensorValue();
                    Debug.WriteLine("Light Level: " + lightLevel.ToString());

                    // LEDs
                    red.ChangeState(SensorStatus.On);
                    blue.ChangeState(SensorStatus.On);

                    // Temperature Humidity
                    tempHumidity.Measure();
                    double temp_degC = tempHumidity.TemperatureInCelsius;
                    double humidity  = tempHumidity.Humidity;
                    Debug.WriteLine("Temperature: " + temp_degC + "\tHumidity: " + humidity);

                    // Sound sensor
                    int soundLevel = Sound.SensorValue();
                    Debug.WriteLine("Sound Level: " + soundLevel);

                    // TODO: Send data to Azure
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            }
        }
        private void InitGrovePi()
        {
            System.Diagnostics.Debug.WriteLine(DeviceFactory.Build.GrovePi().GetFirmwareVersion());

            GroveRotary = DeviceFactory.Build.RotaryAngleSensor(Pin.AnalogPin0);
            GroveSound = DeviceFactory.Build.SoundSensor(Pin.AnalogPin1);
            GroveLight = DeviceFactory.Build.LightSensor(Pin.AnalogPin2);

            GroveRelay = DeviceFactory.Build.Relay(Pin.DigitalPin2);
            GroveTempHumi = DeviceFactory.Build.DHTTemperatureAndHumiditySensor(Pin.DigitalPin3, DHTModel.Dht11);
            GroveRanger = DeviceFactory.Build.UltraSonicSensor(Pin.DigitalPin4);
            GroveLedBar = DeviceFactory.Build.BuildLedBar(Pin.DigitalPin5);
            GroveBuzzer = DeviceFactory.Build.Buzzer(Pin.DigitalPin6);
            GroveButton = DeviceFactory.Build.ButtonSensor(Pin.DigitalPin7);
            GroveLCD = DeviceFactory.Build.RgbLcdDisplay();

            GroveLedBar.Initialize(GrovePi.Sensors.Orientation.GreenToRed);
            GroveLCD.SetBacklightRgb(255, 50, 255);

            DeviceFactory.Build.GrovePi().PinMode(Pin.DigitalPin2, PinMode.Output);
            Delay.Milliseconds(10);
            DeviceFactory.Build.GrovePi().Flush();

            DeviceFactory.Build.GrovePi().PinMode(Pin.DigitalPin6, PinMode.Output);
            Delay.Milliseconds(10);
            DeviceFactory.Build.GrovePi().Flush();
        }