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(); }
private async Task SyncToAzure() { var DeviceConnectionString = "NithinsPI.azure-devices.net"; var DeviceId = "NithinsPI"; var DeviceKey = "3/Di9ndJYFzf5JphzW8YzRM7HebOhKoUGoqmK6Xh/cY="; var device = DeviceClient.Create(DeviceConnectionString, AuthenticationMethodFactory.CreateAuthenticationWithRegistrySymmetricKey(DeviceId, DeviceKey), TransportType.Amqp); IDHTTemperatureAndHumiditySensor sensor = DeviceFactory.Build.DHTTemperatureAndHumiditySensor(Pin.DigitalPin4, DHTModel.Dht11); while (true) { sensor.Measure(); string sensortemp = sensor.TemperatureInCelsius.ToString(); string sensorhum = sensor.Humidity.ToString(); var telemetry = new Telemetry { Temperature = sensortemp, Humidity = sensorhum }; var payLoad = JsonConvert.SerializeObject(telemetry); var message = new Message(Encoding.ASCII.GetBytes(payLoad)); await device.SendEventAsync(message); await Task.Delay(TimeSpan.FromSeconds(15)); } }
public SensorController() { temphumiSensor = DeviceFactory.Build.DHTTemperatureAndHumiditySensor(Pin.DigitalPin2, DHTModel.Dht11); pirMotion = DeviceFactory.Build.PIRMotionSensor(Pin.DigitalPin3); button = DeviceFactory.Build.ButtonSensor(Pin.DigitalPin4); relay = DeviceFactory.Build.Relay(Pin.DigitalPin5); soundSensor = DeviceFactory.Build.SoundSensor(Pin.AnalogPin0); lightSensor = DeviceFactory.Build.LightSensor(Pin.AnalogPin1); gasSensor = DeviceFactory.Build.GasSensorMQ2(Pin.AnalogPin2); display = DeviceFactory.Build.OLEDDisplay128X64(); motor = DeviceFactory.Build.MiniMotorDriver(); lockState = false; }
public void Run(IBackgroundTaskInstance taskInstance) { // Connect the Sound Sensor to Digital port 4 // Models of Temp and Humidity sensors are - Dht11, Dht12, Dht21 // In this example, we use the DHT11 sensor that comes with the GrovePi Starter Kit. /// Specifies the model of sensor. /// DHT11 - blue one - comes with the GrovePi+ Starter Kit. /// DHT22 - white one, aka DHT Pro or AM2302. /// DHT21 - black one, aka AM2301. IDHTTemperatureAndHumiditySensor sensor = DeviceFactory.Build.DHTTemperatureAndHumiditySensor(Pin.DigitalPin3, DHTModel.Dht11); var display = DeviceFactory.Build.RgbLcdDisplay(); // Loop endlessly while (true) { Task.Delay(1000).Wait(); //Delay 1 second try { // Check the value of the Sensor. // Temperature in Celsius is returned as a double type. Convert it to string so we can print it. sensor.Measure(); var sensortemp = sensor.TemperatureInFahrenheit; // Same for Humidity. string sensorhum = sensor.Humidity.ToString(); if (sensortemp > 75.0d) { display.SetBacklightRgb(255, 0, 0); } else { display.SetBacklightRgb(0, 255, 0); } // Print all of the values to the debug window. System.Diagnostics.Debug.WriteLine("Temp is " + sensortemp + " F. And the Humidity is " + sensorhum + "%. "); } 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 async Task <string> GetSensorData(IRotaryAngleSensor vibroSensor, IDHTTemperatureAndHumiditySensor temperatureHumiditySensor) { temperatureHumiditySensor.Measure(); var eventDataJson = JsonConvert.SerializeObject(new { deviceId = DEVICEID, temperature = temperatureHumiditySensor.TemperatureInCelsius, humidity = temperatureHumiditySensor.Humidity, vibrationLevel = vibroSensor.SensorValue(), latitude = LATITUDE, longitude = LONGITUDE }); Debug.WriteLine($"EventData {eventDataJson}"); return(eventDataJson); }
private async Task SetupHat() { grove = DeviceFactory.Build.GrovePi(); grove.PinMode(led, PinMode.Output); grove.PinMode(buzzer, PinMode.Output); grove.PinMode(butt, PinMode.Input); dht = DeviceFactory.Build.DHTTemperatureAndHumiditySensor(Pin.DigitalPin7, GrovePi.Sensors.DHTModel.Dht11); lbl.Text = "Ready! 1.0.1"; //hat = await SenseHatFactory.GetSenseHat() // .Configure // .ConfigureAwait(false); //hat.Display.Fill(Colors.Azure); //hat.Display.Update(); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => timer.Start()); }
public async void Run(IBackgroundTaskInstance taskInstance) { Debug.WriteLine("Application is running!"); var DeviceConnectionString = "NithinsPI.azure-devices.net"; var DeviceId = "NithinsPI"; var DeviceKey = "3/Di9ndJYFzf5JphzW8YzRM7HebOhKoUGoqmK6Xh/cY="; var device = DeviceClient.Create(DeviceConnectionString, AuthenticationMethodFactory.CreateAuthenticationWithRegistrySymmetricKey(DeviceId, DeviceKey), TransportType.Http1); IDHTTemperatureAndHumiditySensor sensor = DeviceFactory.Build.DHTTemperatureAndHumiditySensor(Pin.DigitalPin4, DHTModel.Dht11); ILed greenLed = DeviceFactory.Build.Led(Pin.DigitalPin5); while (true) { BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); greenLed.AnalogWrite(Convert.ToByte(255)); sensor.Measure(); string sensortemp = sensor.TemperatureInCelsius.ToString(); string sensorhum = sensor.Humidity.ToString(); var telemetry = new Telemetry { Temperature = sensortemp, Humidity = sensorhum }; var payLoad = JsonConvert.SerializeObject(telemetry); var message = new Message(Encoding.ASCII.GetBytes(payLoad)); await device.SendEventAsync(message).ConfigureAwait(false); greenLed.AnalogWrite(Convert.ToByte(0)); await Task.Delay(TimeSpan.FromHours(1)); } }
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) { // 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); } } }
public TemperatureSensor() { _sensor = DeviceFactory.Build.DHTTemperatureAndHumiditySensor(Pin.DigitalPin8, DHTModel.Dht11); }