public void InitHardware() { Console.WriteLine("Init Mcp9808..."); sensor = new Mcp9808(Device.CreateI2cBus()); Console.WriteLine("Mcp9808 created"); sensor.Updated += Sensor_Updated; Console.WriteLine("Start reading temperature data"); sensor.StartUpdating(); }
private static Mcp9808 InitializeMcp9808TemperatureSensor() { Console.WriteLine("Initializing MCP9808 temperature sensor..."); Mcp9808 mcp9808 = Mcp9808.FromF7Micro(Device); Console.WriteLine($"Device ID: {mcp9808.GetDeviceId()}"); Console.WriteLine($"Device Revision: {mcp9808.GetDeviceRevision()}"); Console.WriteLine($"Manufacturer ID: {mcp9808.GetManufacturerId()}"); Console.WriteLine($"Resolution: {mcp9808.GetResolution()}"); Console.WriteLine($"Temperature: {mcp9808.GetTemperature().Temperature} deg C"); return(mcp9808); }
public static void Main(string[] args) { I2cConnectionSettings settings = new I2cConnectionSettings(1, Mcp9808.DefaultI2cAddress); I2cDevice device = I2cDevice.Create(settings); using (Mcp9808 sensor = new Mcp9808(device)) { while (true) { // read temperature Console.WriteLine($"Temperature: {sensor.Temperature.DegreesCelsius} ℃"); Console.WriteLine(); Thread.Sleep(1000); } } }
public MeadowApp() { this.spdtSwitch = new SpdtSwitch(Device.CreateDigitalInputPort(Device.Pins.D04, InterruptMode.EdgeBoth)); this.displayInCelcius = this.spdtSwitch.IsOn; this.spdtSwitch.Changed += this.SpdtSwitch_Changed; this.st7789 = InitializeLcdScreen(out this.displayWidth, out this.displayHeight, out this.graphics); this.analogTemperature = InitializeAnalogTemperatureSensor(this.AnalogTemperatureUpdated); this.mcp9808 = InitializeMcp9808TemperatureSensor(); this.Display9808Temperature(this.mcp9808.GetTemperature()); this.mcp9808.Subscribe(new FilterableChangeObserver <AtmosphericConditionChangeResult, AtmosphericConditions>( this.Mcp9808TemperatureUpdated, e => Math.Abs(e.Delta.Temperature.Value) > 0.1 )); this.mcp9808.StartUpdating(); OnboardLed led = new OnboardLed(Device); led.SetColor(RgbColor.Green); }
/// <summary> /// Opens the data logger. /// </summary> /// <returns> /// <see langword="false"/> if any of the sensors failed to open, otherwise <see langword="true"/>. /// </returns> /// <exception cref="InvalidOperationException"> /// Thrown if the data logger is already open. /// </exception> public bool Open() { if (IsOpen) { throw new InvalidOperationException("The data logger is already open"); } IsOpen = true; bool success = true; if (config.IsSensorEnabled(AwsSensor.AirTemperature)) { try { airTempSensor = new Mcp9808(); airTempSensor.Open(); } catch { gpio.Write(config.errorLedPin, PinValue.High); LogMessage("Failed to open airTemp sensor"); success = false; } } if (config.IsSensorEnabled(AwsSensor.RelativeHumidity)) { try { relHumSensor = new Htu21d(); relHumSensor.Open(); } catch { gpio.Write(config.errorLedPin, PinValue.High); LogMessage("Failed to open relHum sensor"); success = false; } } if (config.IsSensorEnabled(AwsSensor.Satellite)) { SatelliteConfiguration satConfig = new SatelliteConfiguration(); if (config.IsSensorEnabled(AwsSensor.WindSpeed)) { satConfig.WindSpeedEnabled = true; satConfig.WindSpeedPin = (int)config.sensors.satellite.windSpeed.pin; } if (config.IsSensorEnabled(AwsSensor.WindDirection)) { satConfig.WindDirectionEnabled = true; satConfig.WindDirectionPin = (int)config.sensors.satellite.windDir.pin; } if (config.IsSensorEnabled(AwsSensor.SunshineDuration)) { satConfig.SunshineDurationEnabled = true; satConfig.SunshineDurationPin = (int)config.sensors.satellite.sunDur.pin; } try { satellite = new Satellite((int)config.sensors.satellite.port, satConfig); satellite.Open(); } catch { gpio.Write(config.errorLedPin, PinValue.High); LogMessage("Failed to open satellite sensor"); success = false; } } if (config.IsSensorEnabled(AwsSensor.Rainfall)) { try { rainfallSensor = new RainwiseRainew111( (int)config.sensors.rainfall.pin, gpio); rainfallSensor.Open(); } catch { gpio.Write(config.errorLedPin, PinValue.High); LogMessage("Failed to open rainfall sensor"); success = false; } } if (config.IsSensorEnabled(AwsSensor.StationPressure)) { try { staPresSensor = new Bmp280(); staPresSensor.Open(); } catch { gpio.Write(config.errorLedPin, PinValue.High); LogMessage("Failed to open BMP280 sensor"); success = false; } } return(success); }