/// <summary> /// Initializes a new instance of the <see cref="Pressure4Click" /> class using the I2C interface. /// </summary> /// <param name="socket">The virtual socket on which the Pressure4Click module is connected to on the MikroBus.Net board</param> /// <param name="slaveAddress">The I2C Slave Address <see cref="I2CAddress"/> to use.</param> public Pressure4Click(Hardware.Socket socket, I2CAddress slaveAddress) { _interface = Interface.I2C; _sensorI2C = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings((Int32)slaveAddress, 400000)); Initialize(); }
/// <summary> /// Initializes a new instance of the <see cref="IlluminanceClick"/> class. /// </summary> /// <param name="socket">The socket on which the Illuminance Click module is plugged on MikroBus.Net board</param> /// <param name="slaveAddress">The user selectable I2C Address of the module based on Logic Level of Jumper J1. See <see cref="I2CAddress"/> for more information.</param> public IlluminanceClick(Hardware.Socket socket, I2CAddress slaveAddress) { _socket = socket; _illuminance = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings((Int32)slaveAddress, 4000000)); if (!Init()) { throw new DeviceInitialisationException($"Error initializing device at address 0x{slaveAddress:x2}"); } }
/// <summary> /// Initializes a new instance of the <see cref="Altitude2Click" /> class. /// </summary> /// <param name="socket">The socket on which the Altitude2Click module is plugged on MikroBus.Net board</param> /// <param name="address">The slave address of the module.</param> public Altitude2Click(Hardware.Socket socket, I2CAddress address) { _socket = socket; _sensor = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings((Int32)address, 100000)); Reset(); ReadCalibrationData(); PressureOverSamplingRate = OverSamplingRate.ADC256; TemperatureOverSamplingRate = OverSamplingRate.ADC256; TemperatureUnit = TemperatureUnits.Celsius; PressureCompensationMode = PressureCompensationModes.SeaLevelCompensated; }
/// <summary> /// Initializes a new instance of the <see cref="IlluminanceClick"/> class. /// </summary> /// <param name="socket">The socket on which the Illuminance Click module is plugged on MikroBus.Net board</param> /// <param name="address">The user selectable I2C Address of the module based on Logic Level of Jumper J1. See <see cref="I2CAddress"/> for more information.</param> /// <param name="clockRateKHz">The clock rate of the I²C device. <seealso cref="ClockRatesI2C"/> for more information.</param> /// <param name="timeout">Optional, the I2C transaction timeout in milliseconds. The default value is 1000 ms.</param> public IlluminanceClick(Hardware.Socket socket, I2CAddress address, ClockRatesI2C clockRateKHz, int timeout = 1000) { try { Hardware.CheckPinsI2C(socket, socket.Int); _config = new I2CDevice.Configuration((ushort)address, (Int32)clockRateKHz); _timeout = timeout; if (!Init()) { throw new DeviceInitialisationException("Illuminance Click not found"); } } // Catch only the PinInUse exception, so that program will halt on other exceptions and send it directly to the caller. catch (PinInUseException ex) { throw new PinInUseException(ex.Message); } }
/// <summary> /// Initializes a new instance of the <see cref="ThermostatClick"/> class. /// </summary> /// <param name="socket">The socket on which the ThermostatClick module is plugged on MikroBus.Net board</param> /// <param name="address">The <see cref="I2CAddress"/> of the module.</param> public ThermostatClick(Hardware.Socket socket, I2CAddress address) { _socket = socket; _sensor = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings((UInt16)address, 100000)); _resetPin = GpioController.GetDefault().OpenPin(socket.Rst); _resetPin.SetDriveMode(GpioPinDriveMode.Output); _resetPin.Write(GpioPinValue.Low); Thread.Sleep(1); _resetPin.Write(GpioPinValue.High); GpioPin enablePin = GpioController.GetDefault().OpenPin(socket.Cs); enablePin.SetDriveMode(GpioPinDriveMode.Output); enablePin.Write(GpioPinValue.High); }
/// <summary> /// Initializes a new instance of the <see cref="BarometerClick" /> class. /// </summary> /// <param name="socket">The socket on which the BarometerClick module is plugged on MikroBus.Net board</param> /// <param name="slaveAddress">The slave address of the module.</param> public BarometerClick(Hardware.Socket socket, I2CAddress slaveAddress) { _socket = socket; _sensor = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings((Int32)slaveAddress, 400000)); if (!Reset()) { throw new ApplicationException("Unable to reset Barometer to Factory defaults"); } if (WhoAmI() != LPS25HB_DEVICE) { throw new DeviceInitialisationException("Barometer Click not found on the I2C Bus."); } SetRecommendedMode(RecommendedModes.WeatherMonitoringLowPower); // Set to lowest level of operating functionality. }
/// <summary> /// Creates a new instance of the HDC1000 click class. /// </summary> /// <param name="socket">The socket that the HDC1000 is plugged in to.</param> /// <param name="ic2Address">The <see cref="I2CAddress"/> used for the I2C Bus.</param> public Hdc1000Click(Hardware.Socket socket, I2CAddress ic2Address = I2CAddress.I2CAddressOne) { _socket = socket; _sensor = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings((Int32)ic2Address, 100000)); _dataReady = GpioController.GetDefault().OpenPin(socket.Int); _dataReady.SetDriveMode(GpioPinDriveMode.InputPullUp); _dataReady.ValueChangedEdge = GpioPinEdge.FallingEdge; _dataReady.ValueChanged += DataReady_ValueChanged; if (GetManufacturerId() != 0x5449 && GetDeviceId() != 0x1000) { throw new DeviceInitialisationException("HDC1000 click not found on I2C Bus"); } // Set default configuration for 14-bit Temperature, 14 Bit Humidity and HeaterMode Off. Configure(AcquisitionMode.Sequential, TemperatureResolution.FourteenBit, HumidityResolution.FourteenBit, HeaterMode.Disabled); }
/// <summary> /// Initializes a new instance of the <see cref="TempHum4Click" /> class. /// </summary> /// <param name="socket">The socket on which the TempHum4Click module is plugged on MikroBus.Net board</param> /// <param name="slaveAddress"></param> public TempHum4Click(Hardware.Socket socket, I2CAddress slaveAddress) { _socket = socket; _addressPin0 = GpioController.GetDefault().OpenPin(socket.Rst); _addressPin0.SetDriveMode(GpioPinDriveMode.Output); _addressPin0.Write(GpioPinValue.Low); _addressPin1 = GpioController.GetDefault().OpenPin(socket.Cs); _addressPin1.SetDriveMode(GpioPinDriveMode.Output); _addressPin1.Write(GpioPinValue.Low); switch (slaveAddress) { case I2CAddress.AddessZero: { _addressPin0.Write(GpioPinValue.Low); _addressPin1.Write(GpioPinValue.Low); break; } case I2CAddress.AddressOne: { _addressPin0.Write(GpioPinValue.High); _addressPin1.Write(GpioPinValue.Low); break; } case I2CAddress.AddressTwo: { _addressPin0.Write(GpioPinValue.Low); _addressPin1.Write(GpioPinValue.High); break; } case I2CAddress.AddressThree: { _addressPin0.Write(GpioPinValue.High); _addressPin1.Write(GpioPinValue.High); break; } default: { throw new ArgumentOutOfRangeException(nameof(slaveAddress)); } } _dataReadyPin = GpioController.GetDefault().OpenPin(socket.Int); _dataReadyPin.SetDriveMode(GpioPinDriveMode.InputPullUp); _sensor = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings((Int32)slaveAddress, 100000)); Reset(); if (GetManufacturerId() != 0x5449 && GetDeviceId() != 0x1000) { throw new DeviceInitialisationException("TempHum4 click not found on I2C Bus"); } // Set default configuration for Sequential acquisition, 14-bit Temperature, 14 Bit Humidity and HeaterMode Off. ConfigureSensor(AcquisitionModes.Sequential, TemperatureResolutions.FourteenBit, HumidityResolutions.FourteenBit, HeaterModes.Disabled); }